From patchwork Mon Oct 23 12:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergei Trofimovich X-Patchwork-Id: 1853726 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Du3QslIs; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SDZd52QNQz23jV for ; Mon, 23 Oct 2023 23:44:09 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 550573858D39 for ; Mon, 23 Oct 2023 12:44:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 31B1D3858D39; Mon, 23 Oct 2023 12:43:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31B1D3858D39 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 31B1D3858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698065037; cv=none; b=MrXdXzlTywNEI8yZXLSWomY5QXhcbRYcGa2setjehOUTb/f4bwMRVS45tDjcR5Co+ChCf8IiRsG9Cv0AYYU7GjHgg00k1OS8q37EqZ9Wq87+aEYqyp//XsFMi0Y+thtq6xiUArQronAn2Iku+qjEaZjnViA89w5yzlIGRj1NYPI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698065037; c=relaxed/simple; bh=95Dc8PjZl5TBXk6OkyOKCK4WLout/67pIzBPCoEAFKQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VNJXzRGFKHXWXh8XDmOjMujl1vGFs3EQGqUyzlKVahjuTOvogSFY2fqWFcVEdmgkkdBM5CqGU5RThvZtOsJAZC6V6Tk/fjwW2r4WVAz9oS90bQBm6/yFKAFdSc77RJJezTtagJMZPPXjJQjJKpJDtCe2FpvA/csWAvmGFLwmHAo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-32d9d8284abso2254314f8f.3; Mon, 23 Oct 2023 05:43:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698065035; x=1698669835; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2iZWGAFaNVAWBZvNxeIs8TnSByfPLwJJhV2Fmdv67y4=; b=Du3QslIsZQUjoY6iOpYDdLW2e90r+E3rnDfbh4HC1E2egD0Xux+qICc8ZK27C/dfIf LVYIFEa45d/g1TmNkBwPMgLsAy6rEDLuL5NrvleqoCIkV4m0Coc89wP7ld83qq+zrlsB OqyoAS33CUHilg/5bqRv4krU7XyEzHp0Zb0CeRbepFLTZdwCuAIbfLv5Vqy3592Xmm4P weaBYn5ASzBoDhwE5suAMP+SFmLNRNGTrs+eMsN2sMgA9Yb719Gn49gcmK07ZUiBQCcN VUGFTrmXhG0OYHlk3obdGb+cT4du23/GYxQNd1WeC2OolWAfl/CneVeWcZm2o++EV9Sh YMHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698065035; x=1698669835; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2iZWGAFaNVAWBZvNxeIs8TnSByfPLwJJhV2Fmdv67y4=; b=aLKLHtZDOhgnUzoVzkOQ0UR7iH7i5gn1aISsomfA9uXkEYVXk1Jqqt/Dxj/P2HrHwz qXGS9fWbnb/TZa3FPXFUCLeEOTr1+D3AeVCTsvlitLsPoJd+HcWXy5JnrN6H9UUbjF7a 3CUKnd69A5nDwbDzRqB8MPrzeqtkXU22KFfou3Al84RTFkjXNQx9Lg6Y0iFXQoM/GPZ/ ejcZmrFTnb+WuJ91AjqiSoHq6qg/f+rTFvEYbSojFqcXKUySej/Dw8nmPhofwpumbBq2 R1Jz4U+3cL87Vu2KagTWEWaKt2njrSr4f3qV+BpBEYCI38oDn0YlsVc+EEn+e2sf3ZBW zjcQ== X-Gm-Message-State: AOJu0YytxkM40Xll5h+l3bWq+IsuUZaotg9VJJXqZ3ZsNf0enQz86Pre ZnD3n6NcIB2vXE1c9PuOY9k= X-Google-Smtp-Source: AGHT+IF8UECbaI4JvPQ35L0Odn83f0a953O8tHBPA4z0KkMg1wUMQ6Gcrk84pxYAzLQswyEczmK/Uw== X-Received: by 2002:adf:f603:0:b0:31a:d450:c513 with SMTP id t3-20020adff603000000b0031ad450c513mr6537947wrp.26.1698065034626; Mon, 23 Oct 2023 05:43:54 -0700 (PDT) Received: from nz.home ([2a00:23c8:a613:101:b585:c7ae:bc87:6414]) by smtp.gmail.com with ESMTPSA id z7-20020a5d4c87000000b0031980294e9fsm7673357wrs.116.2023.10.23.05.43.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 05:43:54 -0700 (PDT) Received: by nz.home (Postfix, from userid 1000) id D33F111FB8BD49; Mon, 23 Oct 2023 13:43:53 +0100 (BST) From: Sergei Trofimovich To: gcc-patches@gcc.gnu.org Cc: Andrew Burgess , Maxim Blinov , Iain Sandoe , Francois-Xavier Coudert , Sergei Trofimovich , Sergei Trofimovich Subject: [PATCH] libgcc: make heap-based trampolines conditional on libc presence Date: Mon, 23 Oct 2023 13:43:50 +0100 Message-ID: <20231023124350.432036-1-slyich@gmail.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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. 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 */