From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by sourceware.org (Postfix) with ESMTPS id 60BA93858D37; Tue, 24 Oct 2023 07:18:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60BA93858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 60BA93858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::133 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698131929; cv=none; b=Q5k7kBgqEO4w3MtLMWKuUgcMXZXvMukEEVgpjPwhPolsiuGv2aRE4Rj2VDKkUs88P4pqsgM9yuedv3wgu8ED39/GnWapq10LVUTUZBFyUqD4omoome4quFgIgcO2YuaVJtbeMGJlxgMpS5aTVrcWomDu4WqiO2RhZIWee2TVkjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698131929; c=relaxed/simple; bh=+c3m+OsS1JCEvqJS8lzSp6OWuwR1rtwuFZ9QWo9GSmk=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=xJbV6L8QAZg0Q7+FUGaptcz9cBvjw0j9qR0OGTPTx+HGEL4+k6LODvex3VqkL0RjiilHdTOlTQzu2i7iNl4kNrmf4AiMir4/wBSA6IGQFLtxgBveUNM4U5X+14o4CCY4mKbr/uGyo7hdHBwOEcXsQemEVVtHFY2gsErZrNY9kg4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-5079f6efd64so5772085e87.2; Tue, 24 Oct 2023 00:18:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698131926; x=1698736726; darn=gcc.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=PhHx6Nif1ZMELCYwrzKh45F0+BDBnt09KTYULSL8jII=; b=bVgaWnqjfTUEWOgnlPwbGpgLGlsBaefp+fSr4NSaKI6xCzaZSfCc2/ENfzYUrTf+OK z9eDpKB3if6sqFJJDlbhmviWfh4aHN6giwB5hG4v2rftGtV3wMaWShGUnJqm7TMaaeYC Kab7pLz5tHXMUxRsOLhX4lzB7J3gj2/nDl2xceiFSrhXGQteTAHLa8misFKTkXRebATi GI+SvatOi2wrqdP4fFV5lezmZ3Uaw8jbF9PGZNN9KzuGOigBW6DC3maivqHc2p8Go5N6 24hESovsY+ZjlhVKP22Xr+/0wQoF0P5u3yo+W7HU+YpQbb+HTfed5AjypIWQT7GGro9f VkSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698131926; x=1698736726; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PhHx6Nif1ZMELCYwrzKh45F0+BDBnt09KTYULSL8jII=; b=j1tnn414xKOpy7ifrpEmZ9yEqvN9zGZCJQPypWjfswEkmcP6EeKUgSRaj3p6x88whZ 1TeWhDkxkompGLpZ0TYcCo8q9bd14kS+L2wlkYsPAS7w0FQZPHL5YutgXsw/Rl+rpIVI RqPLTBfATyeUea9qusH7WmGIMTvgyckusDN2EZ7QZwvUIazMWEeD4LAbfV6vSNMRXE/s 47RhlZW9V1zxA0pnLpbTYsYihtwPzCGwjEp43FshB1+mcmPa9dzDxve3wLanKHt3TG9I weM6JN+ZrgFkW39Sn/SjmfQKRv4VzXAroV9HGJrmDds9BTz++j5oHlhv18UYqok1tOrC fc1A== X-Gm-Message-State: AOJu0YwKjohgZQKlxnMoT8QR5/VFE4IHqM6eJYeyXSsmPFJGSLOfPzoO Cdg+8634LIPuvxQqh+DW0x+FAIqnkNYN9a0mSuP0AvJ1 X-Google-Smtp-Source: AGHT+IGt5ShcfEYsAcGmw9U68zQonuAKSzCXBr1D7MFSRmC0VPo+qiGk/3QM/znONKL89TRiOCYLh6/Iyh/DVODinGI= X-Received: by 2002:ac2:58e7:0:b0:500:b53f:fbc2 with SMTP id v7-20020ac258e7000000b00500b53ffbc2mr7805457lfo.26.1698131925712; Tue, 24 Oct 2023 00:18:45 -0700 (PDT) MIME-Version: 1.0 References: <20231023124350.432036-1-slyich@gmail.com> <128A8A56-A735-4A61-AEC5-BD23B5B8112E@sandoe.co.uk> <20231023173956.4365d8e3@nz> In-Reply-To: <20231023173956.4365d8e3@nz> From: Richard Biener Date: Tue, 24 Oct 2023 09:18:33 +0200 Message-ID: Subject: Re: [PATCH] libgcc: make heap-based trampolines conditional on libc presence To: Sergei Trofimovich Cc: Iain Sandoe , GCC Patches , Francois-Xavier Coudert , Sergei Trofimovich Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Oct 23, 2023 at 6:41=E2=80=AFPM Sergei Trofimovich wrote: > > On Mon, 23 Oct 2023 13:54:01 +0100 > Iain Sandoe wrote: > > > hi Sergei, > > > > > On 23 Oct 2023, at 13:43, Sergei Trofimovich wrote= : > > > > > > From: Sergei Trofimovich > > > > > > 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 bro= ke > > > 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=3Dc \ > > > --disable-bootstrap \ > > > --disable-gcov \ > > > --disable-threads \ > > > --disable-shared \ > > > --disable-libssp \ > > > --disable-libquadmath \ > > > --disable-libgomp \ > > > --disable-libatomic \ > > > --with-build-sysroot=3D/tmp/empty > > > $ make > > > ... > > > /tmp/gb/./gcc/xgcc -B/tmp/gb/./gcc/ -B/usr/local/x86_64-pc-linux-g= nu/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 --sy= sroot=3D/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_SYMV= ER -fcf-protection -mshstk -g -DIN_LIBGCC2 -fbuilding-libgcc -fno-stack-pro= tector -Dinhibit_libc -fpic -mlong-double-80 -DUSE_ELF_SYMVER -fcf-protecti= on -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/hom= e/slyfox/dev/git/gcc/libgcc/../include -DHAVE_CC_TLS -DUSE_TLS -o heap-t= rampoline.o -MT heap-trampoline.o -MD -MP -MF heap-trampoline.dep -c .../g= cc/libgcc/config/i386/heap-trampoline.c -fvisibility=3Dhidden -DHIDE_EXPORT= S > > > ../gcc/libgcc/config/i386/heap-trampoline.c:3:10: fatal error: uni= std.h: No such file or directory > > > 3 | #include > > > | ^~~~~~~~~~ > > > 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(), b= ut the inhibit_libc is neater). > > > > The fact that this first compiler is buit without heap-trampoline suppo= rt, would become relevant, I guess if libc wanted to use them, it would nee= d another iteration. > > > > so, it looks fine, but I cannot actually approve it. > > Sounds good. Let's wait for others to chime in. Maybe Richard? :) OK. > 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 > > > #include > > > #include > > > @@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void) > > > tramp_ctrl_curr =3D prev; > > > } > > > } > > > + > > > +#endif /* !inhibit_libc */ > > > diff --git a/libgcc/config/i386/heap-trampoline.c b/libgcc/config/i38= 6/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 > > > #include > > > #include > > > @@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void) > > > tramp_ctrl_curr =3D prev; > > > } > > > } > > > + > > > +#endif /* !inhibit_libc */ > > > -- > > > 2.42.0 > > > > > > > > -- > > Sergei