From patchwork Wed Feb 11 18:55:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 129977 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id B04E64BA23C2 for ; Wed, 11 Feb 2026 19:20:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B04E64BA23C2 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=riitdcw1 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx1-xb12a.google.com (mail-yx1-xb12a.google.com [IPv6:2607:f8b0:4864:20::b12a]) by sourceware.org (Postfix) with ESMTPS id 97E9A4BA2E10 for ; Wed, 11 Feb 2026 19:19:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 97E9A4BA2E10 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 97E9A4BA2E10 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837577; cv=none; b=lINpVlWirecxPPs2z1roHT6wATzyylgqfCPZ/fZ29jm6ThSPSRYqzgGhKJs+vZLdiAEANQ67Md7j3tvw6F40+iyg2O+6U0tSAU1w8n8bqdLcuWfFpz1Z5xHshDd7cuo+kW5XSR9EV44uwyAHu1G5Dqjyovx4in63EBCmbbpVTN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837577; c=relaxed/simple; bh=+7OIwcA6MdVhEmTOaXInrfZw6X9Nz0jOXkIvc033j30=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xvVtVW7Y0UxRb0j2j3l7qxFzF6j5ZxMzfajtC9c0r+GMruYuBefmB77L/AIobPo4MbWB2FXDo+ZT9UI7JDTb8yZuZts73rGj5G1Q7Li22oU3uDoAJbHfOv9Sn3N4mKKvr2hMfm6w+MjLhaHASaNO/VNbhZKig5E++yTuw3RH8TY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 97E9A4BA2E10 Received: by mail-yx1-xb12a.google.com with SMTP id 956f58d0204a3-64ae2ce2fe1so2540203d50.1 for ; Wed, 11 Feb 2026 11:19:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770837576; x=1771442376; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EO2iCsxo3hRcvmXu+0qpJzodJjh6HRrEvIgHAnsl4wo=; b=riitdcw1UQpFIHGpYnav9tAv8ha4cLPo+NS8xEnruqVwLySOeWR26sEMoxNnrU1gI1 3fjC9Lcfx2iGb0nqEYUEn225o81if/44bqkCtThl9Covi33copepeTg+mrlUxeXaEdYj MKUwtswTzXWCfR8v3ZmIstMq7kWXpShO5HRV6GN7m9CeX2Kz7ByuuHySPipq9HvzVmmM DJE40QSYjZBwUaVnwfoYtXXcPIr7hHwyxOs4xm8dgCggrcscTolsgNsztLY7sOt+W61j /vJHkdLbjy3ArEsidops80dn1QKwA8OasioR0/Urmrch0yP2LXhZUTbt4katx1svgeqy X+6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770837576; x=1771442376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=EO2iCsxo3hRcvmXu+0qpJzodJjh6HRrEvIgHAnsl4wo=; b=Gx25P3jfbcNuGTcebVwsizYjlwwCX+FsQw1SoD4cAfzf5fJxXclYr2Bd8K9RO6iHnX ZFQRQbjjenjEr4phdoKcNxwLeGOV5K95syR1rjqfy4f/NA958xNYde7D+c4T9S/IjSiA ERtfuusAhJp4v2nBWLghBgG/CShTnPCI3n71cOEJPgU31vaKErCm2SY2jcnCDwrrxnoo 53+ywhl218iGRu0St+hoCjIgHPCW5B3VMobBWvPsX6iKZHsCPde0/JJ9jLBaglB9uvpp En1AWPobP50kbyeokVuFqj8YqZICBWlKt0MWe8hREk9K74vV0ch+lItameuf46MDcoYd Pj3Q== X-Gm-Message-State: AOJu0Yw8GPBSLzKmhy8wS8B9jLlfr33xDO9u7YW+oos2HzKGUTWL8uzV LAFrl0ZIjbS3wg/1UNr5QbSXUSy/9t3IzhsiXmNAAgfOWNMwqspxEA5AVPQ2FWDRwAzWlLfyr1Q uLQWR+dQ= X-Gm-Gg: AZuq6aKBczeaHt9pSNWzrg9uWfXGzvL2n0m20pK7Gg8sdShV4XrUQYGWJqvgRjwIDzq /v6fHBr8z0WX3zOe4hpZEDnlfZHYYEgf09i3kqUDR2cQA6GVrUGbQFEvu8PInevLAF7Rc20jz82 E8pDZStVs1cSecVIYEFFv3Vdiwd44/lYmXB4zfaQTNwxOlJMg1/Or6X1agWRgDg+zSSrECwB/4/ 9+lX9SGVYuRGREyBu0CiTmAZHOITxHZebLyFPeK3V3bg195r7NojJiPeRHzQ6YrD+e9hlh1+1Ye nbWwx05hQrRyEM5ho01rXREjfGxEJnAA3QkytFEhzk6FqDk9R473Iylo5tCk5RE0uquHK3uSVHo wSAzi70BvhAZ7Ei1mZ60+WYIkJQe4kW8b5uy810GqdbekbdLy4I5KpMHob58VtLYxh1akfCt3zM Bx5TZ4AIcbtActfFNPCMrD5i4C/P5E3AIoLU4= X-Received: by 2002:a05:690e:1409:b0:64a:db17:3ce6 with SMTP id 956f58d0204a3-64bbaa18eecmr383640d50.2.1770837576435; Wed, 11 Feb 2026 11:19:36 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:42d3:8bd2:a06b:9b74:4887]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64afc9b5932sm2786042d50.21.2026.02.11.11.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 11:19:35 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Sam James , Collin Funk , "H . J . Lu" Subject: [PATCH 1/5] x86_64: Conditionally define __sfp_handle_exceptions for compiler-rt Date: Wed, 11 Feb 2026 15:55:28 -0300 Message-ID: <20260211191928.988805-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260211191928.988805-1-adhemerval.zanella@linaro.org> References: <20260211191928.988805-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The LLVM compiler-rt builtins library does not currently provide an implementation for __sfp_handle_exceptions. On x86_64, this causes unresolved symbol errors when building glibc in environments that exclude libgcc. This patch implements __sfp_handle_exceptions specifically for x86_64, bridging the gap for non-GNU compiler runtimes. The implementation is used conditionally, only if the compiler does not already provide the symbol. NB: the implementation is based on libgcc and raises bosh SSE and i387 exceptions (different that the one from 460ee50de054396cc9791ff4) --- config.h.in | 3 ++ configure | 82 ++++++++++++++++++++++++++++++++ configure.ac | 13 +++++ sysdeps/x86/fpu/Makefile | 5 +- sysdeps/x86/fpu/sfp-exceptions.c | 74 ++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 sysdeps/x86/fpu/sfp-exceptions.c diff --git a/config.h.in b/config.h.in index 2cd8c90eb6..125532ec6b 100644 --- a/config.h.in +++ b/config.h.in @@ -228,6 +228,9 @@ /* Set to 1 if 64 bit atomics are supported. */ #undef HAVE_64B_ATOMICS +/* Define to 1 if compiler runtime provides __sfp_handle_exceptions */ +#undef HAVE_SFP_HANDLE_EXCEPTIONS + /* */ diff --git a/configure b/configure index 0cd2269859..2b9425232e 100755 --- a/configure +++ b/configure @@ -9368,6 +9368,88 @@ printf "%s\n" "$libc_cv_have_libgcc_s" >&6; } config_vars="$config_vars have-libgcc_s = $libc_cv_have_libgcc_s" +# Check if compiler runtime library provides __sfp_handle_exceptions + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __sfp_handle_exceptions support" >&5 +printf %s "checking for __sfp_handle_exceptions support... " >&6; } +if test ${libc_cv_sfp_handle_exceptions+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ +void __sfp_handle_exceptions (int); __sfp_handle_exceptions (0) + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + libc_cv_sfp_handle_exceptions=yes +else case e in #( + e) libc_cv_sfp_handle_exceptions=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_sfp_handle_exceptions" >&5 +printf "%s\n" "$libc_cv_sfp_handle_exceptions" >&6; } +if test "$TEST_CC" = "$CC"; then + libc_cv_test_sfp_handle_exceptions=$libc_cv_sfp_handle_exceptions +else + +saved_CC="$CC" +CC="$TEST_CC" +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __sfp_handle_exceptions support in testing" >&5 +printf %s "checking for __sfp_handle_exceptions support in testing... " >&6; } +if test ${libc_cv_test_sfp_handle_exceptions+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main (void) +{ +void __sfp_handle_exceptions (int); __sfp_handle_exceptions (0) + ; + return 0; +} +_ACEOF +if ac_fn_c_try_link "$LINENO" +then : + libc_cv_test_sfp_handle_exceptions=yes +else case e in #( + e) libc_cv_test_sfp_handle_exceptions=no ;; +esac +fi +rm -f core conftest.err conftest.$ac_objext conftest.beam \ + conftest$ac_exeext conftest.$ac_ext + ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_test_sfp_handle_exceptions" >&5 +printf "%s\n" "$libc_cv_test_sfp_handle_exceptions" >&6; } + +CC="$saved_CC" + +fi + +if test $libc_cv_sfp_handle_exceptions = yes; then + printf "%s\n" "#define HAVE_SFP_HANDLE_EXCEPTIONS 1" >>confdefs.h + +fi + # Support configure.ac under sysdeps. diff --git a/configure.ac b/configure.ac index 3e4a601c01..39d32ecf7f 100644 --- a/configure.ac +++ b/configure.ac @@ -2134,6 +2134,19 @@ AC_CACHE_CHECK([whether $CC can link against -lgcc_s], libc_cv_have_libgcc_s, [d LIBS="$old_LIBS"]) LIBC_CONFIG_VAR([have-libgcc_s], [$libc_cv_have_libgcc_s]) +# Check if compiler runtime library provides __sfp_handle_exceptions +LIBC_TRY_CC_AND_TEST_LINK([for __sfp_handle_exceptions support], + [void __sfp_handle_exceptions (int); __sfp_handle_exceptions (0)], + libc_cv_sfp_handle_exceptions, + [libc_cv_sfp_handle_exceptions=yes], + [libc_cv_sfp_handle_exceptions=no], + libc_cv_test_sfp_handle_exceptions, + [libc_cv_test_sfp_handle_exceptions=yes], + [libc_cv_test_sfp_handle_exceptions=no]) +if test $libc_cv_sfp_handle_exceptions = yes; then + AC_DEFINE([HAVE_SFP_HANDLE_EXCEPTIONS]) +fi + # Support configure.ac under sysdeps. AC_SUBST(libc_cv_test_cc_mprefer_vector_width) AC_SUBST(test_enable_cet) diff --git a/sysdeps/x86/fpu/Makefile b/sysdeps/x86/fpu/Makefile index 91b2444f3a..d847be5c34 100644 --- a/sysdeps/x86/fpu/Makefile +++ b/sysdeps/x86/fpu/Makefile @@ -2,7 +2,10 @@ ifeq ($(subdir),math) # sqrtf128 requires soft-fp. CPPFLAGS += -I../soft-fp -libm-support += powl_helper +libm-support += \ + powl_helper \ + sfp-exceptions \ + # libm-support tests += \ test-fenv-clear-sse \ test-fenv-sse \ diff --git a/sysdeps/x86/fpu/sfp-exceptions.c b/sysdeps/x86/fpu/sfp-exceptions.c new file mode 100644 index 0000000000..385294912b --- /dev/null +++ b/sysdeps/x86/fpu/sfp-exceptions.c @@ -0,0 +1,74 @@ +/* x86_64 soft-fp exception handling for _Float128. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef HAVE_SFP_HANDLE_EXCEPTIONS +#include +#include +#include + +#ifdef __SSE_MATH__ +# define __math_force_eval_div(x, y) \ + do { asm ("" : "+x" (x)); asm volatile ("" : : "x" (x / y)); } while (0) +#else +# define __math_force_eval_div(x, y) \ + do { asm ("" : "+t" (x)); asm volatile ("" : : "f" (x / y)); } while (0) +#endif + +void +__sfp_handle_exceptions (int _fex) +{ + fenv_t temp; + + if (_fex & FP_EX_INVALID) + { + float f = 0.0f; + __math_force_eval_div (f, f); + } + if (_fex & FP_EX_DENORM) + { + asm volatile ("fnstenv\t%0" : "=m" (temp)); + temp.__status_word |= FP_EX_DENORM; + asm volatile ("fldenv\t%0" : : "m" (temp)); + asm volatile ("fwait"); + } + if (_fex & FP_EX_DIVZERO) + { + float f = 1.0f, g = 0.0f; + __math_force_eval_div (f, g); + } + if (_fex & FP_EX_OVERFLOW) + { + asm volatile ("fnstenv\t%0" : "=m" (temp)); + temp.__status_word |= FP_EX_OVERFLOW; + asm volatile ("fldenv\t%0" : : "m" (temp)); + asm volatile ("fwait"); + } + if (_fex & FP_EX_UNDERFLOW) + { + asm volatile ("fnstenv\t%0" : "=m" (temp)); + temp.__status_word |= FP_EX_UNDERFLOW; + asm volatile ("fldenv\t%0" : : "m" (temp)); + asm volatile ("fwait"); + } + if (_fex & FP_EX_INEXACT) + { + float f = 1.0f, g = 3.0f; + __math_force_eval_div (f, g); + } +} +#endif From patchwork Wed Feb 11 18:55:29 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 129980 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 755954BA2E14 for ; Wed, 11 Feb 2026 19:22:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 755954BA2E14 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=qt6F6evk X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx1-xb130.google.com (mail-yx1-xb130.google.com [IPv6:2607:f8b0:4864:20::b130]) by sourceware.org (Postfix) with ESMTPS id D8C794BA2E12 for ; Wed, 11 Feb 2026 19:19:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8C794BA2E12 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8C794BA2E12 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837580; cv=none; b=prRw3w8YyH355bXhGTYm25aJvass8g1GxgL82MzsbWlRj0mpDz8AJtglgoVypg6VxvgU5qWQ1QfKP/m9ZUqUij0LrfavWZH3yv7SC3qRL87TDRdRpu/908bm71ilb8myHx7oOiqdhELihHAeNorZY9qo4hkjvoUAQEDVjlYX14I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837580; c=relaxed/simple; bh=P9VJMB8hl8z2c2lo7+LghVeNAAaWtyO7I8wGdoEZ9dA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oYW/IXar9tJHDYGy8V6bLwsvxwA/7x9cse9F0XVHuvzWRsvzN/J5fos//r0CDXFCYYnEm44FEsjVJDmJ1aWuKDQ4Vo3evE84yBMMQLI3fExFTIqchdem1WMqsoZvu++1bvUlKK60+glkTMCG4Rxz2A6U9lVPLm9XkCxZX4TGHjI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8C794BA2E12 Received: by mail-yx1-xb130.google.com with SMTP id 956f58d0204a3-64ad62a294bso4958609d50.1 for ; Wed, 11 Feb 2026 11:19:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770837579; x=1771442379; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xvvt0v9UlFx2HqNLMA643I46ttgn3zvktgcDTKbtmek=; b=qt6F6evkYwKGQCkmnnmEskhmd9/HWLnWMd1M35jnRcYX6j5Sq3ZVpfVTq+zvkMKt2M 9AwRRP699Xi3WWhHboDnfmoW/5xMxZF5J1a+2GYnr2P0D9GKGMzd3e+AoN7AQ/v2a6JO 2cZtb9VWnER/tzu3zBf80gxoAFbCUl/HIz3Oblp+9ORYrwK9PxKRokcRtANw6zK5InT5 u7DMwl2fMSLgxbsre4L1hIqCcG4HYOxXWDuzZqYRprCLE0vd8GEVGUAdlqdkkT2hGMJq 2ohLHT7ZU1iJduMDJ2SCB1k9C6FfsK7dY0dMU3gvkKV7+1e7SMKYuvuyDHXxv0P3FXcT MFiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770837579; x=1771442379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=xvvt0v9UlFx2HqNLMA643I46ttgn3zvktgcDTKbtmek=; b=YTGeq3blKeC/Hl9IvATeq3lrioOuBQLMqCDraGAeRfgxaH3QTC2TIMtJfHf0Ws22sM /v/fCERQeEEgm9hTCjUgBYl+7JEVIE9GfMH+habO9bx53hbCZgZcV3BbzndFnwNGJM4d O3xA/RpX5Ai2OXyKKPHyeOpjbRfFmoEppl6SS2GDn25HFqyT23hrSBaxwXnjraBBocWb kZ01iwmUjDw2oJl5J84ceLesLUCbd7ASHJJM/Grgm0rJdHis9dXmMwZSQzDvcrcqZGam BmEY/1QFpxnxv0XLe311DTQhKkHUv9peAhbQWZaEU34LGBhTIztL5Ryb8kPR66QxCSyh B+/w== X-Gm-Message-State: AOJu0YyrYAlNkcOFr/TaXlH81/EkzsiIrUEvJkkp9ozCBiV/BwIBY6IT qUuzrj81VPfFc0Fb2rBeGO0ptMKjM9NBqbL+3m0+7ZKdwEdJN7b+zoN3h9HGs2NPcdTljlCWf1u bRpPJqRc= X-Gm-Gg: AZuq6aI+XhSM/ruTz9CkueHN0pHZlZZsaQyhJicKu4VoZs2xIWzdlaciPxqvsjMVM5e 0RB3DaoBgWdNbsh+s/MoFc9RohA0vo30CVody7mha+fy6NggfqHYleaAy4gi5Zt0XzZgH6TdpX1 uOjOi5doKRv1I18neU0gzhd1S9uYvqahK/QhqcvDbvyJ4IDQWcjs0NxGjpR2piYjHB4B3ezHSKl wQk0mBSQ64jkftd5kIa9iBuAVNh8DLfMEwH8hgkpubsE5Uyf9//5YZaAmzQR2+E4bC2SWdIEPW1 sSujtfsm+7aYvYrjmDfdLGoaZhN8kuyKOASt2Ti57cm4/m/xGrVH5MPyPset+OdzRpndlOXCZco kpNGZC1Qv4KGb69vsCPptbQWdykR+4gq41Igusu8aA8F1VtknjkyxxhvKrK5iq9OseoWFLXL0zq 3iFNocIxTExg8KbVkk0vZZXoY47vbhEDHMxzw= X-Received: by 2002:a05:690e:4249:b0:649:e440:26a5 with SMTP id 956f58d0204a3-64bbaa2805dmr278567d50.15.1770837578722; Wed, 11 Feb 2026 11:19:38 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:42d3:8bd2:a06b:9b74:4887]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64afc9b5932sm2786042d50.21.2026.02.11.11.19.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 11:19:38 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Sam James , Collin Funk , "H . J . Lu" Subject: [PATCH 2/5] configure: Parametrize runtime libraries to support compiler-rt Date: Wed, 11 Feb 2026 15:55:29 -0300 Message-ID: <20260211191928.988805-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260211191928.988805-1-adhemerval.zanella@linaro.org> References: <20260211191928.988805-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Historically, the build system has hardcoded references to `-lgcc` and `-lgcc_eh`, explicitly assuming the use of the GCC runtime. This prevents building glibc with alternative toolchains, specifically clang configured with `--rtlib=compiler-rt`, where these libraries are replaced by `libclang_rt.builtins`. This patch introduces a mechanism to dynamically detect the compiler's underlying runtime library. The logic works as follows: 1. It queries the compiler using `-print-libgcc-file-name`. 2. It parses the output path to determine if `libgcc` or `compiler-rt` is in use. 3. Based on this detection, it parametrizes the build variables for the static runtime and exception handling libraries (replacing hardcoded `-lgcc` and `-lgcc_eh`). This ensures that the build system correctly links against the active compiler runtime—whether it is the traditional libgcc or LLVM's compiler-rt—without requiring manual overrides. --- Makeconfig | 12 ++++++------ configure | 33 +++++++++++++++++++++++++++++++++ configure.ac | 19 +++++++++++++++++++ dlfcn/Makefile | 2 +- elf/Makefile | 4 ++-- support/Makefile | 4 ++-- 6 files changed, 63 insertions(+), 11 deletions(-) diff --git a/Makeconfig b/Makeconfig index 01d02180b9..6a05e1d973 100644 --- a/Makeconfig +++ b/Makeconfig @@ -716,20 +716,20 @@ else endif libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed gnulib-arch = -gnulib = -lgcc $(gnulib-arch) -gnulib-tests := -lgcc $(libgcc_eh) +gnulib = $(libgcc-name) $(gnulib-arch) +gnulib-tests := $(libgcc-name) $(libgcc_eh) gnulib-extralibdir = $(dir $(shell $(CC) -print-file-name=libgcc_s.so$(libgcc_s.so-version))) static-gnulib-arch = # By default, elf/static-stubs.o, instead of -lgcc_eh, is used to # statically link programs. When --disable-shared is used, we use # -lgcc_eh since elf/static-stubs.o isn't sufficient. ifeq (yes,$(build-shared)) -static-gnulib = -lgcc $(static-gnulib-arch) +static-gnulib = $(libgcc-name) $(static-gnulib-arch) else -static-gnulib = -lgcc -lgcc_eh $(static-gnulib-arch) +static-gnulib = $(libgcc-name) $(libgcc_eh-name) $(static-gnulib-arch) endif -static-gnulib-tests := -lgcc -lgcc_eh $(libunwind) -libc.so-gnulib := -lgcc +static-gnulib-tests := $(libgcc-name) $(libgcc_eh-name) $(libunwind) +libc.so-gnulib := $(libgcc-name) endif +preinit = $(addprefix $(csu-objpfx),crti.o) +postinit = $(addprefix $(csu-objpfx),crtn.o) diff --git a/configure b/configure index 2b9425232e..60103b8068 100755 --- a/configure +++ b/configure @@ -9368,6 +9368,39 @@ printf "%s\n" "$libc_cv_have_libgcc_s" >&6; } config_vars="$config_vars have-libgcc_s = $libc_cv_have_libgcc_s" +# Check which runtime library compiler uses +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for the usable compiler runtime library" >&5 +printf %s "checking for the usable compiler runtime library... " >&6; } +if test ${libc_cv_libgcc_usable+y} +then : + printf %s "(cached) " >&6 +else case e in #( + e) libc_cv_libgcc_usable=no + libgcc_name=`${CC-cc} $CFLAGS $CPPFLAGS -print-libgcc-file-name | sed 's:.*/::'` + case "$libgcc_name" in + libgcc*) + libc_cv_libgcc=-lgcc + libc_cv_libgcc_eh=-lgcc_eh + ;; + libclang_rt*) + libc_cv_libgcc=-lclang_rt.builtins + libc_cv_libgcc_eh= + ;; + *) { { printf "%s\n" "$as_me:${as_lineno-$LINENO}: error: in '$ac_pwd':" >&5 +printf "%s\n" "$as_me: error: in '$ac_pwd':" >&2;} +as_fn_error $? "non supported compiler runtime library +See 'config.log' for more details" "$LINENO" 5; } ;; + esac + libc_cv_libgcc_usable=yes ;; +esac +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_libgcc_usable" >&5 +printf "%s\n" "$libc_cv_libgcc_usable" >&6; } +config_vars="$config_vars +libgcc-name = $libc_cv_libgcc" +config_vars="$config_vars +libgcc_eh-name = $libc_cv_libgcc_eh" + # Check if compiler runtime library provides __sfp_handle_exceptions { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for __sfp_handle_exceptions support" >&5 diff --git a/configure.ac b/configure.ac index 39d32ecf7f..add61dd826 100644 --- a/configure.ac +++ b/configure.ac @@ -2134,6 +2134,25 @@ AC_CACHE_CHECK([whether $CC can link against -lgcc_s], libc_cv_have_libgcc_s, [d LIBS="$old_LIBS"]) LIBC_CONFIG_VAR([have-libgcc_s], [$libc_cv_have_libgcc_s]) +# Check which runtime library compiler uses +AC_CACHE_CHECK([for the usable compiler runtime library], [libc_cv_libgcc_usable], [dnl + libc_cv_libgcc_usable=no + libgcc_name=`${CC-cc} $CFLAGS $CPPFLAGS -print-libgcc-file-name | sed 's:.*/::'` + case "$libgcc_name" in + libgcc*) + libc_cv_libgcc=-lgcc + libc_cv_libgcc_eh=-lgcc_eh + ;; + libclang_rt*) + libc_cv_libgcc=-lclang_rt.builtins + libc_cv_libgcc_eh= + ;; + *) AC_MSG_FAILURE([non supported compiler runtime library]) ;; + esac + libc_cv_libgcc_usable=yes]) +LIBC_CONFIG_VAR([libgcc-name], [$libc_cv_libgcc]) +LIBC_CONFIG_VAR([libgcc_eh-name], [$libc_cv_libgcc_eh]) + # Check if compiler runtime library provides __sfp_handle_exceptions LIBC_TRY_CC_AND_TEST_LINK([for __sfp_handle_exceptions support], [void __sfp_handle_exceptions (int); __sfp_handle_exceptions (0)], diff --git a/dlfcn/Makefile b/dlfcn/Makefile index 14de193ab8..00341dd476 100644 --- a/dlfcn/Makefile +++ b/dlfcn/Makefile @@ -187,7 +187,7 @@ $(objpfx)bug-atexit1.out: $(objpfx)bug-atexit1-lib.so $(objpfx)bug-atexit2.out: $(objpfx)bug-atexit2-lib.so ifneq (,$(CXX)) -LDLIBS-bug-atexit3-lib.so = -lstdc++ -lgcc_eh +LDLIBS-bug-atexit3-lib.so = -lstdc++ $(libgcc_eh) $(objpfx)bug-atexit3-lib.so: $(libsupport) $(objpfx)bug-atexit3.out: $(objpfx)bug-atexit3-lib.so endif diff --git a/elf/Makefile b/elf/Makefile index 396e97b5e7..3782045d06 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1519,7 +1519,7 @@ $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a echo ".globl $$symbol"; \ echo "$$symbol:"; \ done | $(CC) -o $@T.o $(ASFLAGS) -c -x assembler - - $(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T + $(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ $(gnulib) '-Wl,-)' -Wl,-Map,$@T rm -f %@T.o $@.o mv -f $@T $@ @@ -1549,7 +1549,7 @@ $(objpfx)rtld-libc.a: $(objpfx)librtld.mk FORCE $(MAKE) -f $< -f rtld-Rules $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(objpfx)rtld-libc.a - $(LINK.o) -nostdlib -nostartfiles -r -o $@ '-Wl,-(' $^ -lgcc '-Wl,-)' \ + $(LINK.o) -nostdlib -nostartfiles -r -o $@ '-Wl,-(' $^ $(gnulib) '-Wl,-)' \ -Wl,-Map,$@.map generated += librtld.map librtld.mk rtld-libc.a librtld.os.map diff --git a/support/Makefile b/support/Makefile index bd60466ad0..4c36f45129 100644 --- a/support/Makefile +++ b/support/Makefile @@ -296,14 +296,14 @@ CFLAGS-temp_file.c += -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 ifeq (,$(CXX)) LINKS_DSO_PROGRAM = links-dso-program-c -LDLIBS-links-dso-program-c = -lgcc +LDLIBS-links-dso-program-c = $(gnulib) ifeq ($(have-libgcc_s),yes) CFLAGS-links-dso-program-c.c += -fexceptions LDLIBS-links-dso-program-c += -lgcc_s $(libunwind) endif else LINKS_DSO_PROGRAM = links-dso-program -LDLIBS-links-dso-program = -lstdc++ -lgcc -lgcc_s $(libunwind) +LDLIBS-links-dso-program = -lstdc++ $(gnulib) $(libgcc_s) $(libunwind) endif ifeq (yes,$(have-selinux)) From patchwork Wed Feb 11 18:55:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 129978 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 627254BA23DF for ; Wed, 11 Feb 2026 19:21:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 627254BA23DF Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=iWH4t66g X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx1-xb131.google.com (mail-yx1-xb131.google.com [IPv6:2607:f8b0:4864:20::b131]) by sourceware.org (Postfix) with ESMTPS id 58D394BA23C6 for ; Wed, 11 Feb 2026 19:19:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 58D394BA23C6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 58D394BA23C6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837582; cv=none; b=Uv6jOps9NEsj3DFpzETT4HvRTn39s36w0irYJh7q3dkmeb1chPalSooWG1hRd3W4KLULNqqgCYbKgfBw4wc15C2RH2rHxQsSagjjDRw0GBFEcxWnsiTPiOlxT5vvSlmqRLCB1PGcC92orWOz9n6zXb5sM6/gm65ajpoVkDXD3ws= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837582; c=relaxed/simple; bh=fVAC7FueF0cRYdtdePNnR1PULC70mOdMr+8B9LUF+jw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=o5cw1sV2bGJ8LyB2QmSBtymUBdSS86fRCcntqFjz3nMdXO/md3qZ9Qh6Erzz+u4NXUdCS7/SYUyuyuRhpFyKp/BV9te8fhfSihpJArg6zPZqleyn3135roNXto/lP5fCDMWvTvxIr/Keq3j9tSDAxaIm3QFAwwDpbuUBVVFehgM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58D394BA23C6 Received: by mail-yx1-xb131.google.com with SMTP id 956f58d0204a3-64acd19e1dfso5084892d50.0 for ; Wed, 11 Feb 2026 11:19:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770837581; x=1771442381; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5Rxo8meWfHRHpcucjXirpsApfLMEN4LUWn9psc8Yeaw=; b=iWH4t66gDj/g+uuCLeiVV5Im8ska9UWeIC3ZTy+OBMZmdYC14hy9vysenJwLyDXQdj Dm1xZARmNUIgK5AteIXwQnMu+Hq2kFqtzo6jFfPSWevljdSJ1DcaG56Ak+qeV9xgz3Gd lklsko4MrjIX/6I0/q1LxGQhiGMVCROqE+3HHcNax/lfg4bjcitiHtRv0djnV+L4uFWz BNTQvHgdpXMBxHzIVLfQa2Fi55EMs33ov/UxCz4ybQ25+FwsJKthd/IYNVdnXgm6gtOL Wyd3jBsMlDd3jeK2gdJ1xQ9XgzBsSw217c205ebk92hIaJiHRJbez2mgqRH5VmcAYS5G gSnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770837581; x=1771442381; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=5Rxo8meWfHRHpcucjXirpsApfLMEN4LUWn9psc8Yeaw=; b=dE8oixfKU/xiWHGF2u7CMfiEjS+seVdCkCP57bWbSpXk9CX+U+3Y1RUEoSAAwHx+cc nBNPsJ7ct3BubQP9oWCJVJwlv4k2eANcbdcq6SZCG5R7Qed2WGy5aJ5n+N04O54C2ciz x89J5zeXBSHbX387A5xrgQ2V4PBHRmZUDmXqm2dtnP1jEveBQjPOQ/qOqa9KfBahcJTF k2JTS+/emxRbcyOBi336aILXEtJcrcLVV/yYz7lW90AWqstfpaCmIjKtEKv39zBUBGOn 9REffhwyqnj/DIY4WgrTHpB93Mv54qqvSTFBKoBJ0NsmzVg46aLRP+e1nmI4Tp1QcvPt NZFg== X-Gm-Message-State: AOJu0YxCxF432i44n/hJs/TrcQizXVijPZdCRkPPUVGyRfjO5SNj68DU VSb5CK0vYwt/FUMx9dk08uVa9wkuJ6NWyeEJN6puXwezV/lPfzYC5qkZYxX8hXD+kQN1GCGfAjI eUEC61fQ= X-Gm-Gg: AZuq6aIZu+lRG/uxEZ1MdnXrzQlo9Cp7uwLM/8L5gBapy3ff+dO5QFfm1riFIbDIm8+ Pma8DbPTmG0ArPUAnUWEsWAtE812uTsCXuM029U85dqqeaAEHx7zBz/fbFo3hfQnAmn8xgjZErM bK25AXnc19Ohq8nsSZkjyavvmJizSVCSFWx2e4itYCYs2YmG/XYd8suCUwvGh+QmAQ2gapkE/si YEkfklbe5FS2LvRQzpT10Pwc6kss93eBf/cJyIo4ZJjiUYMBrkgmPCRqKzZUh5EBp02aaYdFQPa +sGqoj40OnLJydiROAunyvDN3xpnltrZCIlFyxfZaSl8iyjjplEKO9ygRddBcYdnrqghdHdv7wS R6COB16DIj9TCJTwatnmmYDd1P9dv8j55kC8pJPrJYDZKu2D91opNLh15U3pynZZedKW6ntf0Xl I9nh7G8/h2nkdLvGlzSIRrXzBdJQylP0Y5yGo= X-Received: by 2002:a05:690e:1284:b0:649:d200:a7ff with SMTP id 956f58d0204a3-64bbaae042fmr352724d50.63.1770837581063; Wed, 11 Feb 2026 11:19:41 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:42d3:8bd2:a06b:9b74:4887]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64afc9b5932sm2786042d50.21.2026.02.11.11.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 11:19:40 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Sam James , Collin Funk , "H . J . Lu" Subject: [PATCH 3/5] configure: Repurpose have-cc-with-libunwind for clang support Date: Wed, 11 Feb 2026 15:55:30 -0300 Message-ID: <20260211191928.988805-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260211191928.988805-1-adhemerval.zanella@linaro.org> References: <20260211191928.988805-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The `have-cc-with-libunwind` check (and its corresponding macro HAVE_CC_WITH_LIBUNWIND) was historically specific to IA64, intended to supplement libgcc with libunwind. Since this logic is unused in current GCC configurations, this patch repurposes it to support clang-based toolchains that utilize LLVM's libunwind instead of libgcc_s. The configure script now detects if the compiler natively supports unwinding via `-lunwind`. Additionally, when this mode is enabled, `-lclang_rt.builtins` is explicitly added to the `libgcc_eh` definition. This is necessary because `links-dso-program` otherwise fails to link due to a missing `__gcc_personality_v0` symbol. It appears that clang does not automatically link the builtins providing this personality routine when `rlink-path` is actively used during the build. --- Makeconfig | 6 ++++-- Makerules | 3 ++- config.make.in | 1 - configure | 24 +++++++++++------------- configure.ac | 21 ++++++++++----------- support/Makefile | 2 +- 6 files changed, 28 insertions(+), 29 deletions(-) diff --git a/Makeconfig b/Makeconfig index 6a05e1d973..ea509dd3bc 100644 --- a/Makeconfig +++ b/Makeconfig @@ -711,10 +711,12 @@ link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnuli ifndef gnulib ifneq ($(have-cc-with-libunwind),yes) libunwind = + libgcc_s = -lgcc_s else - libunwind = -lunwind + libunwind = -lunwind $(libgcc-name) + libgcc_s = $(libunwind) endif -libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed +libgcc_eh := -Wl,--as-needed $(libgcc_s) -Wl,--no-as-needed gnulib-arch = gnulib = $(libgcc-name) $(gnulib-arch) gnulib-tests := $(libgcc-name) $(libgcc_eh) diff --git a/Makerules b/Makerules index 30c3559a28..180cbee251 100644 --- a/Makerules +++ b/Makerules @@ -565,7 +565,8 @@ $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \ -B$(csu-objpfx) $(load-map-file) \ $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \ $(link-test-modules-rpath-link) \ - -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) + -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \ + $(libgcc_eh) endef # This macro is similar to build-shlib but it does not define a soname diff --git a/config.make.in b/config.make.in index fca75ab5d3..42889716e4 100644 --- a/config.make.in +++ b/config.make.in @@ -69,7 +69,6 @@ no-fortify-source = @no_fortify_source@ have-selinux = @have_selinux@ have-libaudit = @have_libaudit@ have-libcap = @have_libcap@ -have-cc-with-libunwind = @libc_cv_cc_with_libunwind@ bind-now = @bindnow@ have-cxx-thread_local = @libc_cv_cxx_thread_local@ have-loop-to-function = @libc_cv_cc_loop_to_function@ diff --git a/configure b/configure index 60103b8068..07445c7d95 100755 --- a/configure +++ b/configure @@ -661,7 +661,6 @@ libc_cv_test_static_pie libc_cv_z_execstack libc_cv_test_no_error_execstack ASFLAGS_config -libc_cv_cc_with_libunwind libc_cv_insert libc_cv_protected_data INSTALL_INFO @@ -7069,32 +7068,31 @@ if test $libc_cv_have_sdata_section = yes; then fi -{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libunwind-support in compiler" >&5 -printf %s "checking for libunwind-support in compiler... " >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether the compiler links with libunwind" >&5 +printf %s "checking whether the compiler links with libunwind... " >&6; } if test ${libc_cv_cc_with_libunwind+y} then : printf %s "(cached) " >&6 else case e in #( - e) - cat > conftest.c < conftest.c <&1 >/dev/null | grep ' -lunwind ' >/dev/null; then - libc_cv_cc_with_libunwind=yes - else - libc_cv_cc_with_libunwind=no - fi - rm -f conftest* ;; +libc_cv_cc_with_libunwind=no +if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static -o conftest \ + conftest.c -v 2>&1 | grep -e '-lunwind' -e 'libunwind' >/dev/null; then + libc_cv_cc_with_libunwind=yes +fi +rm -f conftest* ;; esac fi { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_cc_with_libunwind" >&5 printf "%s\n" "$libc_cv_cc_with_libunwind" >&6; } - if test $libc_cv_cc_with_libunwind = yes; then printf "%s\n" "#define HAVE_CC_WITH_LIBUNWIND 1" >>confdefs.h fi +config_vars="$config_vars +have-cc-with-libunwind = $libc_cv_cc_with_libunwind" ASFLAGS_config= { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking whether --noexecstack is desirable for .S files" >&5 diff --git a/configure.ac b/configure.ac index add61dd826..4e138e09a1 100644 --- a/configure.ac +++ b/configure.ac @@ -1289,22 +1289,21 @@ if test $libc_cv_have_sdata_section = yes; then AC_DEFINE(HAVE_SDATA_SECTION) fi -AC_CACHE_CHECK(for libunwind-support in compiler, - libc_cv_cc_with_libunwind, [ - cat > conftest.c < conftest.c <&1 >/dev/null | grep ' -lunwind ' >/dev/null; then - libc_cv_cc_with_libunwind=yes - else - libc_cv_cc_with_libunwind=no - fi - rm -f conftest*]) -AC_SUBST(libc_cv_cc_with_libunwind) +libc_cv_cc_with_libunwind=no +if ${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static -o conftest \ + conftest.c -v 2>&1 | grep -e '-lunwind' -e 'libunwind' >/dev/null; then + libc_cv_cc_with_libunwind=yes +fi +rm -f conftest*]) if test $libc_cv_cc_with_libunwind = yes; then AC_DEFINE(HAVE_CC_WITH_LIBUNWIND) fi +LIBC_CONFIG_VAR([have-cc-with-libunwind], [$libc_cv_cc_with_libunwind]) ASFLAGS_config= AC_CACHE_CHECK(whether --noexecstack is desirable for .S files, diff --git a/support/Makefile b/support/Makefile index 4c36f45129..ea6f2880aa 100644 --- a/support/Makefile +++ b/support/Makefile @@ -299,7 +299,7 @@ LINKS_DSO_PROGRAM = links-dso-program-c LDLIBS-links-dso-program-c = $(gnulib) ifeq ($(have-libgcc_s),yes) CFLAGS-links-dso-program-c.c += -fexceptions -LDLIBS-links-dso-program-c += -lgcc_s $(libunwind) +LDLIBS-links-dso-program-c += $(libgcc_s) $(libunwind) endif else LINKS_DSO_PROGRAM = links-dso-program From patchwork Wed Feb 11 18:55:31 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 129976 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 490FA4BA2E12 for ; Wed, 11 Feb 2026 19:20:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 490FA4BA2E12 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=teMNDbYw X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx1-xb135.google.com (mail-yx1-xb135.google.com [IPv6:2607:f8b0:4864:20::b135]) by sourceware.org (Postfix) with ESMTPS id 7D9F54BA23C3 for ; Wed, 11 Feb 2026 19:19:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D9F54BA23C3 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7D9F54BA23C3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837584; cv=none; b=FQyNYmCwnLW0H5hFhB6Hm5JlqJ2s9uXxuGL4QEQf3GVD2ElVAl5fzRcht1DMqRuW2ULBK4IY73bV6Q3+GTiMLtsiKt1NPbzzR9Y8BLcTveRVCfr/vzfpksUnIJw035y736Z+qaVUKQYxSb4MYYhftdSL4/kkPsAb2/2nPNMRASo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837584; c=relaxed/simple; bh=OjLql++NUHOIhN8bvdnNgzsgYPOWCjx62u+a3qHklk4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=osjsMOGQcauU9NnJ/n9G734bqHirJrYGM5nCgLiXv7oehZN3bnucrM0usPXQzOmwt+jWliCCNWyVKFu7b40o9nFcplBADM6S4aMAmscMBL6B82sfjPHvw7KFk4fLjs7YSiuGdiZkwWqyAbEHNyB0MpfI6XG+LXYybTkVrZFw0zk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D9F54BA23C3 Received: by mail-yx1-xb135.google.com with SMTP id 956f58d0204a3-6481bd173c0so4939514d50.2 for ; Wed, 11 Feb 2026 11:19:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770837583; x=1771442383; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4u4b/o374R/lR2W1gzye662FC8lqNNEbCobUcSYaIM0=; b=teMNDbYwIdBl0f9+ZpvsMub5qZX0a+m9bl4JlZ0OXJTvYg9MBm+2mc1myVHeuHCyut rdb/aZm2A5tSpQtJrbXEcPCW6YuA++qyPDi0Tg2IB4yKJjZnate8tdJ21EfBIdWq4vci RK1ZoCHus0kIKw1cIQfAj7lcrH5uSeWFpR4r0HdoTdgF2V391LtEbSdZzpAXiKeRKCaN /2qwmpSniD9/av4ZzmsIQFpTSeYNH5awTMc0OG2VUmCgyiSFKQ5HeIgTvnufXLqlwFOC K3Iik8DkYsAMZZInsBB5FlwySFsbwRvLvSyuWRwiFFMUUI7g7YcUcBl5iL7HkRA2kVZB MYfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770837583; x=1771442383; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=4u4b/o374R/lR2W1gzye662FC8lqNNEbCobUcSYaIM0=; b=Cu392iYdptL/lPdGQht4Rndk+CGr0bT5kDbrsqXLLxqvAGIhAE1D36+Kf7At3BA4jU ceioasxpt7e1fUj909lFrbV9wJiR4tlcUm7SaF9jExLBU5TxYD7Tpt3EjJlQ/p6cO8AO ZdjdoYY+Vqy5tfPn2npcKVpJmVFUhDFJ52Avi2IDyWrqXlmhrNQXWpjWBcRlM6MqAz96 B77/yaitn4DrJlkIzTWRaXY8fsQ2+/4OPyNnF7ZA2vz1XWzjB+tjhMfE46igcpg4sbRl 1Cu7NzwxDqmDwhqoCN94pwYCC+eWG9COjg3LkU3io/p3oOeWpp3BXjrdSmCU+qI5CVjP nmXw== X-Gm-Message-State: AOJu0YxXhD47RCuJboGAOfwvRQCUR3GKd571ak+WVVfa9UuNH1WHzkWB VoiD6ChDAulgY4OkuBei6ZEFDdWBGQu2SSF/WXnDYNjzr0xQfC9qualiAEbumUASkhnG9wVepgP NFjqSdLI= X-Gm-Gg: AZuq6aKWqLcEGAziwlAMuQXFDhJRzAU8iGkALBRaYjoo0xJt2AG4xzHkV0bZDCDMsoZ UFl+Jfqbf+jokNlu2jLVapm8YRG6K9B7XRTtozqEqYIDFbb6Xij0W9wXGjXL8nZcyBeOoUcWVQy Cg7HRcsEbHViSIT1q8sUAIloMk598FGSd8Nf4lK0zpNZtTyN6laExC3CZTqs+3N6LNjHOcCMgDz AMXLa1Fl8pqk+H66j6RCGaIh9JB2Z+CvK3W/fgX4IYyaQFlpypgoumOGxOIglmQtDyQwhP0mwa6 1ccvkOzTQehnK2GHJkovTcugVSPaYr/kELmCYXBq1eU7UVVMiMeg2Tb/D4SwPy8VQNjijBT5asz vOyab8uixEhmhYjYLNacM63eXYzAxUQesaXUihYv4EmLKyaM7NWwOr19aPAMZP/fvp3Gu0Jz3HX gIrM1mmdT3WVgSJtLEVDXpV6iw7ssjaGi9kdHuGnScWq712g== X-Received: by 2002:a05:690e:1515:b0:645:5297:3e65 with SMTP id 956f58d0204a3-64bbaa39211mr388128d50.11.1770837583420; Wed, 11 Feb 2026 11:19:43 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:42d3:8bd2:a06b:9b74:4887]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64afc9b5932sm2786042d50.21.2026.02.11.11.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 11:19:43 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Sam James , Collin Funk , "H . J . Lu" Subject: [PATCH 4/5] nptl: Only issues __libc_unwind_link_get for SHARED Date: Wed, 11 Feb 2026 15:55:31 -0300 Message-ID: <20260211191928.988805-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260211191928.988805-1-adhemerval.zanella@linaro.org> References: <20260211191928.988805-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The compiler already optimizes it away for static builds. --- nptl/pthread_exit.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nptl/pthread_exit.c b/nptl/pthread_exit.c index 4d320e608f..4c15171992 100644 --- a/nptl/pthread_exit.c +++ b/nptl/pthread_exit.c @@ -24,12 +24,14 @@ void __pthread_exit (void *value) { +#ifdef SHARED { struct unwind_link *unwind_link = __libc_unwind_link_get (); if (unwind_link == NULL) __libc_fatal (LIBGCC_S_SO " must be installed for pthread_exit to work\n"); } +#endif __do_cancel (value); } From patchwork Wed Feb 11 18:55:32 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 129979 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 0123B4BA23C3 for ; Wed, 11 Feb 2026 19:22:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0123B4BA23C3 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=M+I1BZXf X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-yx1-xb131.google.com (mail-yx1-xb131.google.com [IPv6:2607:f8b0:4864:20::b131]) by sourceware.org (Postfix) with ESMTPS id F10D84BA23E1 for ; Wed, 11 Feb 2026 19:19:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F10D84BA23E1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F10D84BA23E1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837587; cv=none; b=Sd/y7kaHp0Nv4Fc91BdhvwIY+Jv1O1SYeCeZa3PKtYtXdNqROkr+x9qIXJLjDwTAghkce3XW2dlGJ0fsq+cfgULJ4bTKeTzsIorEiadZaeLnWHQqrORkXgy+VDlKs0fXq/7/qCqPQAB/H3ursDN7zS3YacjjQ1kEECwFYLmoXtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1770837587; c=relaxed/simple; bh=WUdHH5ZUo9jyKs3pjl2PZRJzKPyeAGJ75Xk3Bozhe3U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=B/HmzgeoIoT8U9inE78P1ffZ2utMCzzAeWqcm37CpsmJx+s68iJvj7YTk1U5QB76RP3eun2KH2W+N5LF0a6+n5GcIr/2p9+IurEG8PL4PBAxeVTMAzmu0u3fnV3lJma6baRAN13MSeE7ISr9BHSqDPSD3L22tkkLgjxbpphU5W4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F10D84BA23E1 Received: by mail-yx1-xb131.google.com with SMTP id 956f58d0204a3-649278a69c5so6590563d50.3 for ; Wed, 11 Feb 2026 11:19:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1770837586; x=1771442386; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zs2iaqsvHRxxOekfBkJ0J1EMxSAB9Oeg09Gv84Nr7ZY=; b=M+I1BZXfI3oCjmK3DkWbvHo6LdADVdwCvX24jWLvlFnELG+O7TWEkHtr6uwoc+VOKS m7++1mSU5eSU6cHJtv6aJRVpcsbVeFVkrbfHZIjjJUuL8cPXmsI92XIhETo2HXBHdM/R DXG/9sJDOrgqbeLXpjhHWkzFoiDEc6fGqwrBP7/fNjh7yUxS5sCXdyw/+1WL6D5GsdIC OFa6YqY6L7RYTbJc4LBgp+IiQaRgD1DB9EA16P9mhk6+IV4w4cdDQQgu52IqXSk+m1AP J6n7p1LnCu7EhnC1j9zSFllOj3YsBgHbCap5A9cbLKzO2Yo3i5Ca7FU1d+Ym5eU6Zvr/ Uc4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770837586; x=1771442386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=zs2iaqsvHRxxOekfBkJ0J1EMxSAB9Oeg09Gv84Nr7ZY=; b=EMiy6/F+dlsE4Xg8uFpgtYQe/ylcA2Oryo8wygrUqTzcV1vjy2zECoaqh9KhMZlEz7 o2eytcGoYIbZdRJjf/sTt3VRhzrwKMs7j8xl9ysR+d3ZBitQ3XWh5I8tEEHxYpgdvQ2r nFqeHjD3XSnDkJtMOK/U7EwAhNtkjCdE4AZ3IOuqmw6VELauXj8BhnPrC+NwGFJx+p8/ 3oD4XiZBQuehSzpJxVSNwX8/GG596pUatmS4kSUy7l9/RDjTd6ydMr3oax1QNge9b3m4 R/VOaVP9LqYZDlRk4OSaSd20AzffDJLoBrMAIGPTqY7w8i7roYTfahBZsGQfwKLArk9V OQ/g== X-Gm-Message-State: AOJu0YxML1IMlCvBG6Zk4eyL8aL3FIzG2MtnC5n3a+FAtRty59CSUl/4 LhskYE/8+syygtC3PEGgtv5qlF6iRm8kuE71rBaCSc/mwVftP+gfLfiKYhsBd0/2h6kgd2Bnw+Y eDiZMBCQ= X-Gm-Gg: AZuq6aKzqNISmIUDjr0/C/ovcqskCKQ086g60V2o4D/swcdRA1ThjR+ANbLvXFfmg8F Owg3C8pSb4r5tuoYOEvj0I6OGy7qZCpxOHZKP+X6PdDtl6mfFcId2mST9j7rLGU7km4Ri34TYPl P9bId5pByiIC6X6xdelZItP8uirfAGhOWkuNetQ5JnkeakdCL+daQ2CNwd0XjTZ8H+4Bu5WnRS1 D+GU9eOXYT10xU1t+onV3T1GbtCEhHmADT99tHi7VyTIvza9eUvvKLT4qmSsNZTrF2JCgZjeF9u FvYJ4X0UoERmwP0uV3TsX8PmHv7LaPvIchhdp+eAOJSKrI1wa5OpSPMLTFFQXfjbJa6ngfXDkVo qkmMdSwWDnTlJdgNmi9PIuQXFPteBle35kvYh3hSFfvU09uXsUX7NIIls6z4hOKNdsNMnLlKsIp ZFZtCAgI5FQC5MBdCyPatbYUfCS0TirSCGAsk= X-Received: by 2002:a05:690e:481:b0:649:eb42:582 with SMTP id 956f58d0204a3-64bbaa0c2efmr307293d50.2.1770837585782; Wed, 11 Feb 2026 11:19:45 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c2:42d3:8bd2:a06b:9b74:4887]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-64afc9b5932sm2786042d50.21.2026.02.11.11.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Feb 2026 11:19:45 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Sam James , Collin Funk , "H . J . Lu" Subject: [PATCH 5/5] Support loading libunwind instead of libgcc_s Date: Wed, 11 Feb 2026 15:55:32 -0300 Message-ID: <20260211191928.988805-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260211191928.988805-1-adhemerval.zanella@linaro.org> References: <20260211191928.988805-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The 'unwind-link' facility allows glibc to support thread cancellation and exit (pthread_cancel, pthread_exiti, backtrace) by dynamically loading the unwind library at runtime, preventing a hard dependency on libgcc_s within libc.so. When building with libunwind (for clang/LLVM toolchains), two assumptions in the existing code break: 1. The runtime library is libunwind.so instead of libgcc_s.so. 2. libgcc relies on __gcc_personality_v0 to handle unwinding mechanics. libunwind exposes the standard '_Unwind_*' accessors directly. This patch adapts `unwind-link` to handle both environments based on the HAVE_CC_WITH_LIBUNWIND configuration: * The UNWIND_SONAME macro now selects between LIBGCC_S_SO and LIBUNWIND_SO. * For libgcc, it continues to resolve `__gcc_personality_v0`. * For libunwind, it instead resolves the standard _Unwind_GetLanguageSpecificData, _Unwind_SetGR, _Unwind_SetIP, and _Unwind_GetRegionStart helpers. * unwind-resume.c is updated to implement wrappers for these accessors that forward calls to the dynamically loaded function pointers, effectively shimming the unwinder. Tests and Makefiles are updated to link against `$(libunwind)` where appropriate. --- elf/Makefile | 2 ++ misc/unwind-link.c | 34 ++++++++++++++++++++++++++++++++- nptl/pthread_cancel.c | 2 +- nptl/pthread_exit.c | 2 +- shlib-versions | 2 ++ sysdeps/generic/unwind-link.h | 13 +++++++++++++ sysdeps/generic/unwind-resume.c | 32 +++++++++++++++++++++++++++++++ 7 files changed, 84 insertions(+), 3 deletions(-) diff --git a/elf/Makefile b/elf/Makefile index 3782045d06..6e5f98c8c9 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -2769,6 +2769,8 @@ $(objpfx)tst-big-note-lib.so: $(objpfx)tst-big-note-lib.o $(LINK.o) -shared -o $@ $(LDFLAGS.so) $(dt-relr-ldflag) $< $(objpfx)tst-unwind-ctor: $(objpfx)tst-unwind-ctor-lib.so +LDLIBS-tst-unwind-ctor += $(libunwind) +LDFLAGS-tst-unwind-ctor-lib.so = -Wl,--unresolved-symbols=ignore-all CFLAGS-tst-unwind-main.c += -funwind-tables -DUSE_PTHREADS=0 diff --git a/misc/unwind-link.c b/misc/unwind-link.c index 6019dacf66..c5c1a3ea69 100644 --- a/misc/unwind-link.c +++ b/misc/unwind-link.c @@ -37,6 +37,12 @@ static void *global_libgcc_handle; may depend on unwinding. */ __libc_lock_define (static, lock); +#ifndef HAVE_CC_WITH_LIBUNWIND +# define UNWIND_SONAME LIBGCC_S_SO +#else +# define UNWIND_SONAME LIBUNWIND_SO +#endif + struct unwind_link * __libc_unwind_link_get (void) { @@ -48,7 +54,7 @@ __libc_unwind_link_get (void) /* Initialize a copy of the data, so that we do not need about unlocking in case the dynamic loader somehow triggers unwinding. */ - void *local_libgcc_handle = __libc_dlopen (LIBGCC_S_SO); + void *local_libgcc_handle = __libc_dlopen (UNWIND_SONAME); if (local_libgcc_handle == NULL) { __libc_lock_unlock (lock); @@ -72,8 +78,19 @@ __libc_unwind_link_get (void) local.ptr___frame_state_for = __libc_dlsym (local_libgcc_handle, "__frame_state_for"); #endif +#ifndef HAVE_CC_WITH_LIBUNWIND local.ptr_personality = __libc_dlsym (local_libgcc_handle, "__gcc_personality_v0"); +#else + local.ptr__Unwind_GetLanguageSpecificData + = __libc_dlsym (local_libgcc_handle, "_Unwind_GetLanguageSpecificData"); + local.ptr__Unwind_SetGR + = __libc_dlsym (local_libgcc_handle, "_Unwind_SetGR"); + local.ptr__Unwind_SetIP + = __libc_dlsym (local_libgcc_handle, "_Unwind_SetIP"); + local.ptr__Unwind_GetRegionStart + = __libc_dlsym (local_libgcc_handle, "_Unwind_GetRegionStart"); +#endif UNWIND_LINK_EXTRA_INIT /* If a symbol is missing, libgcc_s has somehow been corrupted. */ @@ -84,7 +101,15 @@ __libc_unwind_link_get (void) assert (local.ptr__Unwind_GetIP != NULL); #endif assert (local.ptr__Unwind_Resume != NULL); +#ifndef HAVE_CC_WITH_LIBUNWIND assert (local.ptr_personality != NULL); +#else + assert (local.ptr__Unwind_GetLanguageSpecificData != NULL); + assert (local.ptr__Unwind_SetGR != NULL); + assert (local.ptr__Unwind_GetIP != NULL); + assert (local.ptr__Unwind_SetIP != NULL); + assert (local.ptr__Unwind_GetRegionStart != NULL); +#endif PTR_MANGLE (local.ptr__Unwind_Backtrace); PTR_MANGLE (local.ptr__Unwind_ForcedUnwind); @@ -96,7 +121,14 @@ __libc_unwind_link_get (void) #if UNWIND_LINK_FRAME_STATE_FOR PTR_MANGLE (local.ptr___frame_state_for); #endif +#ifndef HAVE_CC_WITH_LIBUNWIND PTR_MANGLE (local.ptr_personality); +#else + PTR_MANGLE (local.ptr__Unwind_GetLanguageSpecificData); + PTR_MANGLE (local.ptr__Unwind_SetGR); + PTR_MANGLE (local.ptr__Unwind_SetIP); + PTR_MANGLE (local.ptr__Unwind_GetRegionStart); +#endif __libc_lock_lock (lock); if (atomic_load_relaxed (&global_libgcc_handle) != NULL) diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c index 5fe31c266c..6757ea2ba4 100644 --- a/nptl/pthread_cancel.c +++ b/nptl/pthread_cancel.c @@ -87,7 +87,7 @@ __pthread_cancel (pthread_t th) { struct unwind_link *unwind_link = __libc_unwind_link_get (); if (unwind_link == NULL) - __libc_fatal (LIBGCC_S_SO + __libc_fatal (UNWIND_SONAME " must be installed for pthread_cancel to work\n"); } #endif diff --git a/nptl/pthread_exit.c b/nptl/pthread_exit.c index 4c15171992..1ed5ed52c4 100644 --- a/nptl/pthread_exit.c +++ b/nptl/pthread_exit.c @@ -28,7 +28,7 @@ __pthread_exit (void *value) { struct unwind_link *unwind_link = __libc_unwind_link_get (); if (unwind_link == NULL) - __libc_fatal (LIBGCC_S_SO + __libc_fatal (UNWIND_SONAME " must be installed for pthread_exit to work\n"); } #endif diff --git a/shlib-versions b/shlib-versions index b1fd0a5eab..32093228c4 100644 --- a/shlib-versions +++ b/shlib-versions @@ -68,3 +68,5 @@ libmvec=1 # The malloc debug library libc_malloc_debug=0 + +libunwind=1 diff --git a/sysdeps/generic/unwind-link.h b/sysdeps/generic/unwind-link.h index 1150cda219..ea39e525d2 100644 --- a/sysdeps/generic/unwind-link.h +++ b/sysdeps/generic/unwind-link.h @@ -34,6 +34,12 @@ unwind_arch_adjustment (void *prev, void *addr) # include # include +# ifndef HAVE_CC_WITH_LIBUNWIND +# define UNWIND_SONAME LIBGCC_S_SO +# else +# define UNWIND_SONAME LIBUNWIND_SO +# endif + # if UNWIND_LINK_FRAME_STATE_FOR struct frame_state; # endif @@ -50,7 +56,14 @@ struct unwind_link #if UNWIND_LINK_FRAME_STATE_FOR struct frame_state *(*ptr___frame_state_for) (void *, struct frame_state *); #endif +#ifndef HAVE_CC_WITH_LIBUNWIND _Unwind_Reason_Code (*ptr_personality) PERSONALITY_PROTO; +#else + __typeof (_Unwind_GetLanguageSpecificData) *ptr__Unwind_GetLanguageSpecificData; + __typeof (_Unwind_SetGR) *ptr__Unwind_SetGR; + __typeof (_Unwind_SetIP) *ptr__Unwind_SetIP; + __typeof (_Unwind_GetRegionStart) *ptr__Unwind_GetRegionStart; +#endif UNWIND_LINK_EXTRA_FIELDS }; diff --git a/sysdeps/generic/unwind-resume.c b/sysdeps/generic/unwind-resume.c index de176a1f72..18c40501bb 100644 --- a/sysdeps/generic/unwind-resume.c +++ b/sysdeps/generic/unwind-resume.c @@ -38,11 +38,43 @@ _Unwind_Resume (struct _Unwind_Exception *exc) } #endif +#ifndef HAVE_CC_WITH_LIBUNWIND _Unwind_Reason_Code __gcc_personality_v0 PERSONALITY_PROTO { return UNWIND_LINK_PTR (link (), personality) PERSONALITY_ARGS; } +#else +void * +_Unwind_GetLanguageSpecificData (struct _Unwind_Context *context) +{ + return UNWIND_LINK_PTR (link (), _Unwind_GetLanguageSpecificData) (context); +} + +void +_Unwind_SetGR (struct _Unwind_Context *context, int index, _Unwind_Word val) +{ + UNWIND_LINK_PTR (link (), _Unwind_SetGR) (context, index, val); +} + +_Unwind_Ptr +_Unwind_GetIP (struct _Unwind_Context *context) +{ + return UNWIND_LINK_PTR (link (), _Unwind_GetIP) (context); +} + +void +_Unwind_SetIP (struct _Unwind_Context *context, _Unwind_Ptr val) +{ + UNWIND_LINK_PTR (link (), _Unwind_SetIP) (context, val); +} + +_Unwind_Ptr +_Unwind_GetRegionStart (struct _Unwind_Context *context) +{ + return UNWIND_LINK_PTR (link (), _Unwind_GetRegionStart) (context); +} +#endif _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *exc, _Unwind_Stop_Fn stop,