From: Sergei Trofimovich <slyich@gmail.com>
To: Iain Sandoe <iain@sandoe.co.uk>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>,
Sergei Trofimovich <siarheit@google.com>,
Richard Biener <richard.guenther@gmail.com>
Subject: Re: [PATCH] libgcc: make heap-based trampolines conditional on libc presence
Date: Mon, 23 Oct 2023 17:39:56 +0100 [thread overview]
Message-ID: <20231023173956.4365d8e3@nz> (raw)
In-Reply-To: <128A8A56-A735-4A61-AEC5-BD23B5B8112E@sandoe.co.uk>
On Mon, 23 Oct 2023 13:54:01 +0100
Iain Sandoe <iain@sandoe.co.uk> wrote:
> hi Sergei,
>
> > On 23 Oct 2023, at 13:43, Sergei Trofimovich <slyich@gmail.com> wrote:
> >
> > From: Sergei Trofimovich <siarheit@google.com>
> >
> > To build `libc` for a target one needs to build `gcc` without `libc`
> > support first. Commit r14-4823-g8abddb187b3348 "libgcc: support
> > heap-based trampolines" added unconditional `libc` dependency and broke
> > libc-less `gcc` builds.
> >
> > An example failure on `x86_64-unknown-linux-gnu`:
> >
> > $ mkdir -p /tmp/empty
> > $ ../gcc/configure \
> > --disable-multilib \
> > --without-headers \
> > --with-newlib \
> > --enable-languages=c \
> > --disable-bootstrap \
> > --disable-gcov \
> > --disable-threads \
> > --disable-shared \
> > --disable-libssp \
> > --disable-libquadmath \
> > --disable-libgomp \
> > --disable-libatomic \
> > --with-build-sysroot=/tmp/empty
> > $ make
> > ...
> > /tmp/gb/./gcc/xgcc -B/tmp/gb/./gcc/ -B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/ -isystem /usr/local/x86_64-pc-linux-gnu/include -isystem /usr/local/x86_64-pc-linux-gnu/sys-include --sysroot=/tmp/empty -g -O2 -O2 -g -O2 -DIN_GCC -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -isystem ./include -fpic -mlong-double-80 -DUSE_ELF_SYMVER -fcf-protection -mshstk -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-protector -Dinhibit_libc -fpic -mlong-double-80 -DUSE_ELF_SYMVER -fcf-protection -mshstk -I. -I. -I../.././gcc -I/home/slyfox/dev/git/gcc/libgcc -I/home/slyfox/dev/git/gcc/libgcc/. -I/home/slyfox/dev/git/gcc/libgcc/../gcc -I/home/slyfox/dev/git/gcc/libgcc/../include -DHAVE_CC_TLS -DUSE_TLS -o heap-trampoline.o -MT heap-trampoline.o -MD -MP -MF heap-trampoline.dep -c .../gcc/libgcc/config/i386/heap-trampoline.c -fvisibility=hidden -DHIDE_EXPORTS
> > ../gcc/libgcc/config/i386/heap-trampoline.c:3:10: fatal error: unistd.h: No such file or directory
> > 3 | #include <unistd.h>
> > | ^~~~~~~~~~
> > compilation terminated.
> > make[2]: *** [.../gcc/libgcc/static-object.mk:17: heap-trampoline.o] Error 1
> > make[2]: Leaving directory '/tmp/gb/x86_64-pc-linux-gnu/libgcc'
> > make[1]: *** [Makefile:13307: all-target-libgcc] Error 2
> >
> > The change inhibits any heap-based trampoline code.
>
> That looks reasonable to me (I was considering using __has_include(), but the inhibit_libc is neater).
>
> The fact that this first compiler is buit without heap-trampoline support, would become relevant, I guess if libc wanted to use them, it would need another iteration.
>
> so, it looks fine, but I cannot actually approve it.
Sounds good. Let's wait for others to chime in. Maybe Richard? :)
AFAIU libcs (like `glibc`) try hard not to use link tests and uses
mainly preprocessor and code generator to specifically accommodate this
case. Maybe there is a way to pass the support flag to libc without the
reliance on code presence in libgcc.
Otherwise we could use __builtin_trap() as an implementation for exposed
symbols.
>
> >
> > libgcc/
> >
> > * libgcc/config/aarch64/heap-trampoline.c: Disable when libc is
> > not present.
> > ---
> > libgcc/config/aarch64/heap-trampoline.c | 5 +++++
> > libgcc/config/i386/heap-trampoline.c | 5 +++++
> > 2 files changed, 10 insertions(+)
> >
> > diff --git a/libgcc/config/aarch64/heap-trampoline.c b/libgcc/config/aarch64/heap-trampoline.c
> > index c8b83681ed7..f22233987ca 100644
> > --- a/libgcc/config/aarch64/heap-trampoline.c
> > +++ b/libgcc/config/aarch64/heap-trampoline.c
> > @@ -1,5 +1,8 @@
> > /* Copyright The GNU Toolchain Authors. */
> >
> > +/* libc is required to allocate trampolines. */
> > +#ifndef inhibit_libc
> > +
> > #include <unistd.h>
> > #include <sys/mman.h>
> > #include <stdint.h>
> > @@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void)
> > tramp_ctrl_curr = prev;
> > }
> > }
> > +
> > +#endif /* !inhibit_libc */
> > diff --git a/libgcc/config/i386/heap-trampoline.c b/libgcc/config/i386/heap-trampoline.c
> > index 96e13bf828e..4b9f4365868 100644
> > --- a/libgcc/config/i386/heap-trampoline.c
> > +++ b/libgcc/config/i386/heap-trampoline.c
> > @@ -1,5 +1,8 @@
> > /* Copyright The GNU Toolchain Authors. */
> >
> > +/* libc is required to allocate trampolines. */
> > +#ifndef inhibit_libc
> > +
> > #include <unistd.h>
> > #include <sys/mman.h>
> > #include <stdint.h>
> > @@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void)
> > tramp_ctrl_curr = prev;
> > }
> > }
> > +
> > +#endif /* !inhibit_libc */
> > --
> > 2.42.0
> >
>
--
Sergei
next prev parent reply other threads:[~2023-10-23 16:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-23 12:43 Sergei Trofimovich
2023-10-23 12:54 ` Iain Sandoe
2023-10-23 16:39 ` Sergei Trofimovich [this message]
2023-10-24 7:18 ` Richard Biener
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231023173956.4365d8e3@nz \
--to=slyich@gmail.com \
--cc=fxcoudert@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=iain@sandoe.co.uk \
--cc=richard.guenther@gmail.com \
--cc=siarheit@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).