From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 4360B3858D39; Mon, 23 Oct 2023 16:41:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4360B3858D39 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 4360B3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698079268; cv=none; b=P5eUkeNXLJuVL/aC4elGT5s5YNl97GvP4SMkIfpmcoPo/asyqPnc7ZgyZLXkeDhqktLQQLWdheHC0TZYLCm+yIdtyydnAXAZanosSlMF1evi/uJ+duDrYw8dy4GR2z3D4mCFk2ISVvTnR7//4+Y7oPsEj0FXvKIsQ6lHkAQS9ms= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698079268; c=relaxed/simple; bh=qkqFy1GhfO/KomS//txyjelWOuBDDUuMbr3Kdkp6mI8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=jScqQIlnneoGhva2UOTOtV1NTQcmRP5ED2VfpfQba5ec1OR810Kq/qVVqiy5I7S+iRL4/COhk2+rGSphpeUSjohUgAPf7o88tqQelaUDLZr2c2C9+UUmhoWPmLJZLvlh1smKHGxjnT84baO+Fw4Wih/8+edSNxfxWPpVYYm0KXc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40836ea8cbaso25988405e9.0; Mon, 23 Oct 2023 09:41:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698079265; x=1698684065; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=NLKuwnt5YLK8IGgrSQlGII50H2FdNa6LHf5trNZuQ0I=; b=OrtdMVcfgxQFI60oD0EVOUq/4YUA7MbQIcGAR0SVh00kanO2J4Bj6BgcsOKyG4D1h9 Pbalf+GHoBQtHveeQEoQHz5GE52DQSz+YU5JnTqIuWYjp1ii0q6GDqD29rCcRRJ7xH8H jAkK4sAFbfao0q4ThwBt+lsMITAKG7+SpPl7FntFz305hMDr1mGJ5pCr0XUtiBlqOOWH VMLmnip5wFqvq/dvT7uAKLPHHPUH5MEgCZe1E9ZzRevWUzOaqujw5koWM310/fvV1rLz 4F62XnmHqNaI05MQOl+/X3D9L8phUX6hHRFdlNf7pZlxlSV97WdfVVMsJIKnRQd6ZQBD FA6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698079265; x=1698684065; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NLKuwnt5YLK8IGgrSQlGII50H2FdNa6LHf5trNZuQ0I=; b=ImF9QfaO1gDvMRHl6z9D90ZBUAMZiufiHsDP4NmNVXC5HPxQ0xRCLmFweV55Bh4DiA LLaGZjVXW1zhXIeQu4YOm0u3hvAPll/7XyuFEDMH20Ee81J8az2zvfKqbMtUWCm+SdBi QvS2nvduD55nbjs+1vHm0A7JXb98dJLepZjGVUCVjOWIou47FtECOjaGP/BfVb2tdWBb LET9HFKhI/8ShD0VovTSMt+A2qVDbyvKCoA8LR9JYEf5aCa82Gg0ybypTNCnOVZbmsbk t2lBjWoYR3oy3alOvhXr/6kwLPvidY4ItNTQMAw8Ie3aXXwq15EqEkO+azq0f/FG8oM9 hP+A== X-Gm-Message-State: AOJu0YwlYwk8D+3EmQgtnMy8i+aP4G7/RpfBU4ffi9sCSZP8unG992YZ x91LXNCKTogT7FzIthZCSyM= X-Google-Smtp-Source: AGHT+IG9C0qidhBWTjLS/a7uzo1C2/8a4FINNZnJowSCBV9zTOE2IQS7ANEfhpnXo+jo9QA7CLwixQ== X-Received: by 2002:a05:600c:a01:b0:405:7400:1e3d with SMTP id z1-20020a05600c0a0100b0040574001e3dmr7281311wmp.32.1698079264635; Mon, 23 Oct 2023 09:41:04 -0700 (PDT) Received: from nz ([2a00:23c8:a613:101:b585:c7ae:bc87:6414]) by smtp.gmail.com with ESMTPSA id bg34-20020a05600c3ca200b00402f713c56esm9980615wmb.2.2023.10.23.09.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 09:40:37 -0700 (PDT) Date: Mon, 23 Oct 2023 17:39:56 +0100 From: Sergei Trofimovich To: Iain Sandoe Cc: GCC Patches , Francois-Xavier Coudert , Sergei Trofimovich , Richard Biener Subject: Re: [PATCH] libgcc: make heap-based trampolines conditional on libc presence Message-ID: <20231023173956.4365d8e3@nz> In-Reply-To: <128A8A56-A735-4A61-AEC5-BD23B5B8112E@sandoe.co.uk> References: <20231023124350.432036-1-slyich@gmail.com> <128A8A56-A735-4A61-AEC5-BD23B5B8112E@sandoe.co.uk> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.5 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, 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 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 > > | ^~~~~~~~~~ > > 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 > > #include > > #include > > @@ -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 > > #include > > #include > > @@ -170,3 +173,5 @@ __builtin_nested_func_ptr_deleted (void) > > tramp_ctrl_curr = prev; > > } > > } > > + > > +#endif /* !inhibit_libc */ > > -- > > 2.42.0 > > > -- Sergei