From patchwork Wed Mar 18 19:34:12 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 131922 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 D40504C3180C for ; Wed, 18 Mar 2026 19:37:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D40504C3180C 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=Dw+kskuz X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dy1-x1335.google.com (mail-dy1-x1335.google.com [IPv6:2607:f8b0:4864:20::1335]) by sourceware.org (Postfix) with ESMTPS id F3F724B196D3 for ; Wed, 18 Mar 2026 19:35:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F3F724B196D3 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 F3F724B196D3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1335 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862503; cv=none; b=YtcXV0zUrOnT45yaqvzYnnd0jJFTzxvvdMmbOZnvslHS3vpPsjE+ssq1eJfugmEH7iYV6y9B1YX0yo6sTjGMcR4KiF2c/K5nkdozwOERMWvcFEPgdm1qBySOCBLIO9mz9mcxXXMcjZlr9ONhPDWXmAjC9v+kiAGNIUx27XWp/O8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862503; c=relaxed/simple; bh=HcFj522Jj4ABEymZbb8lh+hugtOM04RQLDNghvO9GuQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=RYcHivhRcp1YSsVoDO4CEpIy5CcL+JJcV+/wzDAuw7aU8QbpgXx+mHcCGQeFnazutI/BZ9QLCnGh7/FYWFfNNLFkoascL51pkxyvpq2C5VVx6C9oRi+bBhNKAmBIEY4WiVsnSxUsHP4GOTuVAGyZsBRdGMLWFM/CO7RtL0g1ZdQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F3F724B196D3 Received: by mail-dy1-x1335.google.com with SMTP id 5a478bee46e88-2b4520f6b32so509751eec.0 for ; Wed, 18 Mar 2026 12:35:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1773862502; x=1774467302; 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=YqVtf1Y91sP4bNakMMDwc1QDAm2i4btaq1BCC9NGsP8=; b=Dw+kskuzDVBlKjYN/7sU1hXHGTH4gf7raEZKIkvmSHayAdIJeNr60G1mI/cISrGtMH jmH6lGNnvyT6RlITP/toXpi41UWsdZLVR0mGS7reXKPe9GydGYF+oPcw06N7gh37Tx2I Qd5dHBz/KhyItu4Eoc6J1Bfg5zcS/zKQBfsrv3uCHIKbk1Go+WgwIZ9r3nno5QsTdJcg aUssKmUX6aXAU/8HpQ6qGfBxsZJF3xukBJhOkmnKA98HiRmZiS9qtnHjUxovhQSvdzn6 O7qItHWDvRiF07f7NTCQg4yDjD/Xfl59fnkUxyaLZD2xj+XRFfWGNKpazqAyk/V9qL/a xo7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773862502; x=1774467302; 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=YqVtf1Y91sP4bNakMMDwc1QDAm2i4btaq1BCC9NGsP8=; b=l0KlwtqnEKVKizbul9LKHjqpdhkkAuV/kxcfiAoXPtxAXGmw7Vz/F6zRpX3Uy6cjjv vqOAIn9abRQvAYb/EVyOCRaqtAdJM3+TIMSkRoqL7QoY8HBVXbo4NKFC2QiWr5q+sJCW eLclKXNaHHdBeDnnJeGbH4P/OxQJaqJy5z9+Aeiwoa/BWdOmEfWQR/K2YUpkau3BixNG xDEbDEDB4NTnIQ9QOZIEOVVLbZXi743XoyldVvbCBqPTRVHwgbGDxpGrSEDYi+OUJXEf SkM5XfUxG8JhmF8r3g1bBuEx+E15f9kpv12fHKOtZyZhhdeHWrXyigIN/wk1FdDqdc0t Y14A== X-Gm-Message-State: AOJu0YxDJ+eFbSsEnNkJTDU69mlK6gwJ1WDw93uUr8jWxSQgg/MoWZEk fWeh1Qqk6UqWaGFMTeC0NkIOQrMiWgLpOqYRihN9mMRnt9ZMHrVPrlaY3q8gADzXtwZx/PUxnVl kJN+h X-Gm-Gg: ATEYQzxMAkfVJ9Qwya/LBJsCeyC1aSPbxSYrO8IXOT8ufHUhDWUhcKO/WjuY8eO/i+F ZJ6L/hd5JSb3IP4zCMrIKcmHdZ9G8VU0OckWTGgjDUC/V3L+kYa7DY43jHosLOyUl92nmr5OlrP xNKFeFf5txhht6ebZhXqy/N/Zmfho8ZKta9IHZ/iXwjvkUCyMWsvsxy/0zseNWcb4B8wkaL9G4N F7HM1XIGWz1s9lb8jfLKl+9T51q+VmIb9tEtzlXP+vh6kbpYvPfUTAftNWkJisRpptNEjB92/wm lVDXosaFupAujVd55OZttK+b85cTqFpsJpP8JhFHRDRFwBlDYmt3FeqbtGJuj5RI5cMwONsvd1u QMMycA4cwYeiGJGK9PT7r5hyz2/nrdTTSCq7hTCCtlUDhy9bEQv2tea9uRudh1LjJkvMBtGlJIn XJtjI3NX/bf8iFbCVflktTqxv3wAscz4b1OFG7yTnvMKp6qg== X-Received: by 2002:a05:7022:225:b0:129:ea6:a3c7 with SMTP id a92af1059eb24-1299b9c25dcmr2187622c88.0.1773862501294; Wed, 18 Mar 2026 12:35:01 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:f5a4:2159:38c8:c951:d029]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-129b4147522sm4238937c88.15.2026.03.18.12.34.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 12:35:00 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer , Samuel Thibault Subject: [PATCH v8 1/6] nptl: Add __raise_direct Date: Wed, 18 Mar 2026 16:34:12 -0300 Message-ID: <20260318193454.2466865-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> References: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 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 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 function sends a signal to current thread using raw syscalls. Reviewed-by: Florian Weimer --- include/signal.h | 3 +++ nptl/pthread_kill.c | 21 +++++++------------ sysdeps/posix/raise.c | 2 +- sysdeps/unix/sysv/linux/Makefile | 4 ++++ sysdeps/unix/sysv/linux/raise_direct.c | 29 ++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/raise_direct.c diff --git a/include/signal.h b/include/signal.h index 73f18dddd7..099d721514 100644 --- a/include/signal.h +++ b/include/signal.h @@ -65,6 +65,9 @@ extern int __xpg_sigpause (int sig); /* Allocate real-time signal with highest/lowest available priority. */ extern int __libc_allocate_rtsig (int __high); +/* Similar to raise, but does not set errno. */ +extern int __raise_direct (int signo) attribute_hidden; + # if IS_IN (rtld) extern __typeof (__sigaction) __sigaction attribute_hidden; extern __typeof (__libc_sigaction) __libc_sigaction attribute_hidden; diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c index 221689e36a..bc038e9824 100644 --- a/nptl/pthread_kill.c +++ b/nptl/pthread_kill.c @@ -29,20 +29,13 @@ __pthread_kill_implementation (pthread_t threadid, int signo, int no_tid) { struct pthread *pd = (struct pthread *) threadid; if (pd == THREAD_SELF) - { - /* Use the actual TID from the kernel, so that it refers to the - current thread even if called after vfork. There is no - signal blocking in this case, so that the signal is delivered - immediately, before __pthread_kill_internal returns: a signal - sent to the thread itself needs to be delivered - synchronously. (It is unclear if Linux guarantees the - delivery of all pending signals after unblocking in the code - below. POSIX only guarantees delivery of a single signal, - which may not be the right one.) */ - pid_t tid = INTERNAL_SYSCALL_CALL (gettid); - int ret = INTERNAL_SYSCALL_CALL (tgkill, __getpid (), tid, signo); - return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0; - } + /* There is no signal blocking in this case, so that the signal is + delivered immediately, before __pthread_kill_internal returns: a signal + sent to the thread itself needs to be delivered synchronously. (It is + unclear whether Linux guarantees the delivery of all pending signals + after unblocking in the code below. POSIX only guarantees delivery + of a single signal, which may not be the right one.) */ + return __raise_direct (signo); /* Block all signals, as required by pd->exit_lock. */ internal_sigset_t old_mask; diff --git a/sysdeps/posix/raise.c b/sysdeps/posix/raise.c index 8abe8d4cad..cf0770f1c8 100644 --- a/sysdeps/posix/raise.c +++ b/sysdeps/posix/raise.c @@ -23,7 +23,7 @@ int raise (int sig) { - int ret = __pthread_kill (__pthread_self (), sig); + int ret = __raise_direct (sig); if (ret != 0) { __set_errno (ret); diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index c6bd97abf1..8797c5c9b3 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -455,6 +455,10 @@ tests += \ endif ifeq ($(subdir),signal) +sysdep_routines += \ + raise_direct \ + # sysdep_routines + tests-special += \ $(objpfx)tst-signal-numbers.out \ # tests-special diff --git a/sysdeps/unix/sysv/linux/raise_direct.c b/sysdeps/unix/sysv/linux/raise_direct.c new file mode 100644 index 0000000000..d38bd10817 --- /dev/null +++ b/sysdeps/unix/sysv/linux/raise_direct.c @@ -0,0 +1,29 @@ +/* Internal function to send a signal to itself. Linux version. + 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 + . */ + +#include +#include +#include + +int +__raise_direct (int signo) +{ + pid_t tid = INTERNAL_SYSCALL_CALL (gettid); + int ret = INTERNAL_SYSCALL_CALL (tkill, tid, signo); + return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0; +} From patchwork Wed Mar 18 19:34:13 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 131920 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 B39194C31807 for ; Wed, 18 Mar 2026 19:36:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B39194C31807 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=r9mELCPT X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x122d.google.com (mail-dl1-x122d.google.com [IPv6:2607:f8b0:4864:20::122d]) by sourceware.org (Postfix) with ESMTPS id D9A684C31815 for ; Wed, 18 Mar 2026 19:35:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9A684C31815 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 D9A684C31815 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::122d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862508; cv=none; b=T/xSYdUXjxfe7y7+7l6JeFVilPZM8dwLZ5GcrBO4jNZeU3u2Sn2g2KdZe8E1zKV7UnJKM28ATozuy5/ZOP0l+esi0RWRo8zYQ7XH1bGJJ4hehJkYwU5giqJfkOWd2Dxj8JpNmWX0syYuaLkMbcGZXCHkxTRDt+Ls7JVF0gI7y5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862508; c=relaxed/simple; bh=QAfxGXvxePAZKAEdFJR2ddWLYOQrH62cyFj3y6rd/bU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GTyky0cnoXrUJOAIrVFteDd5nvMHeRT+J5mOVRH2ru5yRfgxM6n5oqd2juwLp6ZnYKfMipVXW1E+2GtIrAJ/5X8N3QBeknvftEX2KLFMgE6PZ5RBYDrjGGZiZxBRWIfb3nL0FdyhBG10Zm2UjsNo5HFvPZGtmUwwgh4m8gFzBHI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D9A684C31815 Received: by mail-dl1-x122d.google.com with SMTP id a92af1059eb24-12732165d1eso397453c88.1 for ; Wed, 18 Mar 2026 12:35:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1773862506; x=1774467306; 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=gPwpKfxM7s3snpZFFuAp0zWNRAdOBfbKZca7h29wtTw=; b=r9mELCPTq/QhK8Ws/B4g3cgEM57FsMKvsi0uqJxtFNBGdSrB2Vkf6332wjNSjmKmAW s15oF/eexGR/sc9W0FHucUb1j2la+Rk9Pffn68J3t0PTLJBnGgI0yIgM9PReQimxm82+ G8HYOCFRGotXJdbwCJRlihbc+mBqovkWvqMcS/1D4peyXW5ld32k9gS76kmfC2u3Hmpx ux6jbB0bvDkuhw7d43z1Nia04MbY3bl7ctunwoKreJl80DHBc97w2CpybxMzrkhC7hOW Wp7QKHvUCqPYvllk2CooOwk3LZAI1BLwgLcjCquNturu6qvQcepIHrNRyPu0oB/SCiQf 6GJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773862506; x=1774467306; 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=gPwpKfxM7s3snpZFFuAp0zWNRAdOBfbKZca7h29wtTw=; b=pkDH5Bz6tOj6IC6ueZeD2DnRf9t0AmW6/LYn04qZQH28NHhOX3qoOKpG/rVUZpAIG5 M5q0HorOateBkWm3bGLgFgicPTP42lCEcDlJaZErMzoLlIownS4lvCLNAp1fSv2Ekzj/ Akc+olMnfdaMX5Mqxh8tLgYprW+j3IRFnR66HW3HibnJ05i34HNJuIdpKGlaB2yKlcR0 sDF31oUNXMUvzbc109pxqKgVJdEqx7B9o1uhWA7Up4VZlsPk26kSb+DY7xz+nLgQ7zNs GaLnbE/vVVKld0BXX+ABzKEcTcb6SadQ7M3SRJpE2vjuFkMxZHc0gxaQcWOTtLuk+CRJ ReKg== X-Gm-Message-State: AOJu0YzxTAyIhSLLYmouDH0c7CbJrVlowpcKYzLRgZ9ochQuX31xYK1A CfcItdU4Y0TkWf7eHC2/b56Lc1cAz2gYsEupSyG3cjfEG6Oz6TLnm2FmOfdkQlNzobPDjXg8Hdz DfCOl X-Gm-Gg: ATEYQzycyjhKI3HGJQmkcYXC4+NLp7XkQCtASOOQhgpcs+Tpmkzs+P4bhszznySKXKU NqXg3II7TKivF2N11w3bHbmeCxtbvV3KM8tkZqVJlRZJWxX8z+mNJ04viKcBxxw1+IqnmDNVInW Tvj5wF8Mu3+2ApWAaCTxNWLPMg2/PRTMO1jztyKGtENf3wVDxflfIeRVHV3ShEEXSwFnZ8/WC6A 5H+ab319HwtsbjQbMChPTvnYRId/rtQhvwatctmGzVVHlj27WbJU6h7cJqJcjJGOI2G2yuusdCl YRuKiq7zFI2fyZ+jld1UWTwXrvlC5UVWGGuy4CfKfyFSVYrEG4MzX/O8fRNU3/Up0aO/QWtA5Cp xZP+AhFHV8RvvevrfEHDZiNgw/hI8UoIl46FG1yjxbOevguWq7fl3kML38Nxb/vmle0djg/RFeg v6RHQKEH4/iJEn7zzKXVTAZ9O1/OGusb4CoJY= X-Received: by 2002:a05:7022:6b97:b0:128:ea68:27f6 with SMTP id a92af1059eb24-129a714f49fmr2156393c88.36.1773862505846; Wed, 18 Mar 2026 12:35:05 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:f5a4:2159:38c8:c951:d029]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-129b4147522sm4238937c88.15.2026.03.18.12.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 12:35:04 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer , Samuel Thibault Subject: [PATCH v8 2/6] Use _dl_writev on __libc_message_impl Date: Wed, 18 Mar 2026 16:34:13 -0300 Message-ID: <20260318193454.2466865-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> References: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 And change _dl_writev to return a negative errno in case of failure. This keeps the required semantics for not setting errno on failure and allows removing the Linux libc_fatal.c implementation. It also makes it simple to use the writev syscall during process startup, especially on i386, where it requires disabling vDSO. Checked on x86_64-linux-gnu and i686-linux-gnu. Reviewed-by: Florian Weimer --- {elf => sysdeps/generic}/dl-writev.h | 18 +++++++------- sysdeps/posix/libc_fatal.c | 15 ++++++------ sysdeps/unix/sysv/linux/dl-writev.h | 12 ++++------ sysdeps/unix/sysv/linux/libc_fatal.c | 36 ---------------------------- 4 files changed, 20 insertions(+), 61 deletions(-) rename {elf => sysdeps/generic}/dl-writev.h (80%) delete mode 100644 sysdeps/unix/sysv/linux/libc_fatal.c diff --git a/elf/dl-writev.h b/sysdeps/generic/dl-writev.h similarity index 80% rename from elf/dl-writev.h rename to sysdeps/generic/dl-writev.h index a235942605..024b780bf2 100644 --- a/elf/dl-writev.h +++ b/sysdeps/generic/dl-writev.h @@ -20,37 +20,35 @@ #include #include -/* This is used from only one place: dl-misc.c:_dl_debug_vdprintf. - Hence it's in a header with the expectation it will be inlined. - - This is writev, but with a constraint added and others loosened: +/* This is writev, but with a constraint added and others loosened: 1. Under RTLD_PRIVATE_ERRNO, it must not clobber the private errno when another thread holds the dl_load_lock. - 2. It is not obliged to detect and report errors at all. - 3. It's not really obliged to deliver a single atomic write + 2. It's not really obliged to deliver a single atomic write (though it may be preferable). */ -static inline void +static inline ssize_t _dl_writev (int fd, const struct iovec *iov, size_t niov) { /* Note that if __writev is an implementation that calls malloc, this will cause linking problems building the dynamic linker. */ + ssize_t r; #if RTLD_PRIVATE_ERRNO /* We have to take this lock just to be sure we don't clobber the private errno when it's being used by another thread that cares about it. Yet we must be sure not to try calling the lock functions before the thread library is fully initialized. */ if (__glibc_unlikely (_dl_starting_up)) - __writev (fd, iov, niov); + _r = _writev (fd, iov, niov); else { __rtld_lock_lock_recursive (GL(dl_load_lock)); - __writev (fd, iov, niov); + r = __writev (fd, iov, niov); __rtld_lock_unlock_recursive (GL(dl_load_lock)); } #else - __writev (fd, iov, niov); + r = __writev (fd, iov, niov); #endif + return r == -1 ? -errno : r; } diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index 4f11315c2a..3f0e302b5e 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include #include @@ -28,14 +29,14 @@ #include FATAL_PREPARE_INCLUDE #endif -#ifndef WRITEV_FOR_FATAL -# define WRITEV_FOR_FATAL writev_for_fatal -static bool -writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total) +static void +writev_for_fatal (int fd, const struct iovec *iov, size_t niov) { - return TEMP_FAILURE_RETRY (__writev (fd, iov, niov)) == total; + ssize_t cnt; + do + cnt = _dl_writev (fd, iov, niov); + while (cnt == -EINTR); } -#endif /* At most a substring before each conversion specification and the trailing substring (the plus one). */ @@ -108,7 +109,7 @@ __libc_message_impl (const char *vma_name, const char *fmt, ...) if (iovcnt > 0) { - WRITEV_FOR_FATAL (fd, iov, iovcnt, total); + writev_for_fatal (fd, iov, iovcnt); total = ALIGN_UP (total + sizeof (struct abort_msg_s) + 1, GLRO(dl_pagesize)); diff --git a/sysdeps/unix/sysv/linux/dl-writev.h b/sysdeps/unix/sysv/linux/dl-writev.h index 89f69f8ab1..ceb98a35e6 100644 --- a/sysdeps/unix/sysv/linux/dl-writev.h +++ b/sysdeps/unix/sysv/linux/dl-writev.h @@ -19,19 +19,15 @@ #include #include -/* This is used from only one place: dl-misc.c:_dl_debug_vdprintf. - Hence it's in a header with the expectation it will be inlined. - - This is writev, but with a constraint added and others loosened: +/* This is writev, but with a constraint added and others loosened: 1. Under RTLD_PRIVATE_ERRNO, it must not clobber the private errno when another thread holds the dl_load_lock. - 2. It is not obliged to detect and report errors at all. - 3. It's not really obliged to deliver a single atomic write + 2. It's not really obliged to deliver a single atomic write (though it may be preferable). */ -static inline void +static inline ssize_t _dl_writev (int fd, const struct iovec *iov, size_t niov) { - INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); + return INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); } diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c deleted file mode 100644 index 120cdffaf9..0000000000 --- a/sysdeps/unix/sysv/linux/libc_fatal.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Catastrophic failure reports. Linux version. - Copyright (C) 1993-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 - . */ - -#include -#include -#include -#include - -static bool -writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total) -{ - ssize_t cnt; - do - cnt = INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); - while (INTERNAL_SYSCALL_ERROR_P (cnt) - && INTERNAL_SYSCALL_ERRNO (cnt) == EINTR); - return cnt == total; -} -#define WRITEV_FOR_FATAL writev_for_fatal - -#include From patchwork Wed Mar 18 19:34:14 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 131921 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 740A04BB3BAD for ; Wed, 18 Mar 2026 19:36:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 740A04BB3BAD 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=BLWckpnl X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1229.google.com (mail-dl1-x1229.google.com [IPv6:2607:f8b0:4864:20::1229]) by sourceware.org (Postfix) with ESMTPS id E14CD4C3183B for ; Wed, 18 Mar 2026 19:35:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E14CD4C3183B 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 E14CD4C3183B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1229 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862510; cv=none; b=a+y5HL9Sk4LXdrI1I5SEwxxnFrzeXhptdeZ4CbhgKyKdcZqwLjV4uxtbZVKG3ks828Cla5gvizDf032pfm17jQqsfviOXPMz+U3VERzH+3QcLqmD3hbGJ3fjQeRItpUu9F0CrcPk/jQqQCEj7O6Oyl9ItxRPplk/MNaAGDdDA00= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862510; c=relaxed/simple; bh=WwoMWUQT49YF+ZAPSEB1m7mBkJV26OasmSW5eYcZEmc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Ff3b+d0je1Xl7HIgJXhROmVmzCqBvie1DSSJWbko/qZxDXu6hL/gkzj7E5WTp/JuE4EkBh+GbXiG5gtrC+nP1FNzNEqTVyEVOAIYTpwHAMkgozC4O/lJEbSfOSMH93KYsMpQZM4rXSdzp9oK/48D5RgmSVbQcD2HCFu5p5IhVmc= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E14CD4C3183B Received: by mail-dl1-x1229.google.com with SMTP id a92af1059eb24-12776bebe9fso497482c88.1 for ; Wed, 18 Mar 2026 12:35:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1773862508; x=1774467308; 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=77zVOOXse/n2wNWc0w2UdYEzCsqPiFzlIkaSY69n+7Y=; b=BLWckpnlocMMAwBReepAjVFzZQgwM8QY9cU/KTwC3wPSR1+OPt2CAuvAO5Si1hlAQl yUpBNZg+N1SIjoqr1FJrhQOOVSng1mx17+SO0eHn1Z+4vMAiQA5FuYZVWswriUcISJ5n w6O1AX9M5eUoos7nfFjDhWfsZ22W3Ye0kAaqugsTRoY1QB1E+DuxkRxGiShppS+ywQEa Jt5zvMNT+Py4muBOoKu4IqB3mC247hVArnRe2nDMRok5ICXbC138qPxh6AorUL1tkwxB zGZA6HXuUjr04RVBe6SWXlx+jwwdhzgeyIQbNuH9hSVDG/P2rnYnVZa90uqUgj9WH/uL 0faQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773862508; x=1774467308; 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=77zVOOXse/n2wNWc0w2UdYEzCsqPiFzlIkaSY69n+7Y=; b=RCwZB4QPMnGH7WrUMfZ0+3y4qzHz1HJofBfUYM2P8oFBGMtOUoDvyuRiDiMZth50sa m1VgAHxK05ZHqmSq+e6gafIr6mFGPg5kzK/T7ORrR0D9QuxXPHYmaOdqCzj8RfpxpGW4 crzDWs80rdsOs6cQfMD4IhzvgpRaQC+nNWbZiV4mAaamnSarM0EpUBvPnkPDg93RhzPc aO36qssVZBsEesE44kLAF0+R9C+rJF7NiOHW5D0Sk9rbpqghGwmZ7xuD6I8zHkofp4hG 795bbhFNFCvibSUa5dDeTmnFSHWm3n+Zby0hCclMUTJrrS6fIrWROTja3+YlesRZE7JC Hqkw== X-Gm-Message-State: AOJu0YyGYOMecfQl1/3xTVqlnUH1OzpqkHlLHc8fWzUbleaIY0yFlbRU sYnW8K9vrle2wNp/AnTIc0E5iTajJghYCFjoj4ScOkLSVvdgVyK37okqzdNAz7J1edPI2nBbCnS TPHtS X-Gm-Gg: ATEYQzwtDqIaAf+OHbe2byt1chbzSP7PhAnlSA2cCgg8TslgENyPkQJaAfV+xZ9ej90 wtJvqevtuSB7H7F7Tm6ikd17OO5EBhwolDSEunXi/ATBtkEmn1Tucak7Sd3Vo6bKE0u9U1QbE7H 8mQnk1OQqr8k4wFknGWxE+2IOaHRoLnhy8kpcltWkNYPpUYn7ShQQyNOOAfU9hmOlUWpGIzE3iT p1vDYky7w2xRJx+jE7RkHaclV2udxiGKEZQ0ugr2sNF0+XtPMJVThy4uyQRAKNGw6NpURs7JKdl gjHO1c+iBjM2hvm1iUT5eGK/72GoxIGiPxHCRYWhrqREPqSwi1LuN53+hCO/YvvU4gYflgL7Btd RdSdbtWbzETa2rvQ+CZ6WxuYSrHVe5cLZRbxCxEWSzDAFaBfDFlByEpCB2LtTTlshQnMCSWwdSN zBNcpFwuY2yy+vYQUvgOd70fXzU0y4nw26TE4= X-Received: by 2002:a05:7022:423:b0:11e:161:c008 with SMTP id a92af1059eb24-129a716192bmr2455557c88.26.1773862507955; Wed, 18 Mar 2026 12:35:07 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:f5a4:2159:38c8:c951:d029]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-129b4147522sm4238937c88.15.2026.03.18.12.35.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 12:35:07 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer , Samuel Thibault Subject: [PATCH v8 3/6] Fix assert during static startup (BZ 33326) Date: Wed, 18 Mar 2026 16:34:14 -0300 Message-ID: <20260318193454.2466865-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> References: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> 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, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, 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 BZ#33326 testcase triggers an assertion during process startup, which results in a segmentation fault instead of an error message and process termination with a SIGABRT. The assert issues __libc_message_impl, which in turn might call string functions depending on the ABI (strchrnul, strlen, memcpy/mempcpy), system calls (writev and mmap), and finally the abort call. Since each function may be called during process startup, before self-relocation and/or the thread pointer being set up, the functions should be built without stack protection. The dl-symbol-redir-ifunc.h is also expanded to cover strlen/memcpy/mempcpy/strchrnul on multiple architectures that implement ifunc. On i386, syscalls should not use the vDSO ("call *%gs:SYSINFO_OFFSET") during program statuup because thread pointer is not yet initialized. This requires __raise_direct, _dl_writev, and _dl_mmap to use I386_USE_SYSENTER. To avoid possible sysdep.h I386_USE_SYSENTER redefinition, all implementations are done on their own translation unit. The s390x requires not calling libgcc for the generic strchrnul-c (via ctz/clz macros) due to a libgcc issue: the __clzdi2 builtin is not built against a hidden reference to __clz_tab, which creates a GOT reference for static-pie (and it cannot be called before self-relocation). Creating a test case is challenging. For static-pie, the assert is only called for ill-formed ELF files on elf_get_dynamic_info and by some targets on ELF_DYNAMIC_RELOCATE (although not all targets use assert in their dl-machine.h). Some targets also issue __libc_fatal on ARCH_SETUP_IREL, but also only for ill-formatted ELF files. The test employs a different strategy and overrides the __tunables_init symbol, which is invoked immediately before self-relocation and TLS setup. The test is built with -Wl,-z,muldefs to avoid linker issues. I checked on aarch64, x86_64, i686, s390x (qemu), sparc (qemu), mips64el (qemu), armhf, riscv, and powerpc. --- assert/Makefile | 5 +++ elf/Makefile | 17 +++++++- elf/tst-assert-startup-static.c | 40 +++++++++++++++++++ libio/Makefile | 5 +++ stdlib/Makefile | 5 +++ string/Makefile | 1 + .../aarch64/multiarch/dl-symbol-redir-ifunc.h | 1 + sysdeps/aarch64/multiarch/memcpy_generic.S | 4 ++ .../armv7/multiarch/dl-symbol-redir-ifunc.h | 27 +++++++++++++ sysdeps/generic/dl-mmap.h | 34 ++++++++++++++++ .../lp64/multiarch/dl-symbol-redir-ifunc.h | 2 + sysdeps/posix/libc_fatal.c | 12 ++++-- .../powerpc32/power4/multiarch/Makefile | 5 +++ .../be/multiarch/dl-symbol-redir-ifunc.h | 27 +++++++++++++ .../le/multiarch/dl-symbol-redir-ifunc.h | 1 + sysdeps/powerpc/powerpc64/multiarch/Makefile | 1 + .../riscv/multiarch/dl-symbol-redir-ifunc.h | 1 + sysdeps/s390/Makefile | 5 +++ .../s390/multiarch/dl-symbol-redir-ifunc.h | 4 ++ sysdeps/s390/string-bitops.h | 27 +++++++++++++ .../sparcv9/multiarch/dl-symbol-redir-ifunc.h | 3 ++ .../sparc64/multiarch/dl-symbol-redir-ifunc.h | 3 ++ sysdeps/unix/sysv/linux/Makefile | 12 ++++++ sysdeps/unix/sysv/linux/i386/Makefile | 14 +++++++ sysdeps/unix/sysv/linux/i386/dl-mmap.c | 36 +++++++++++++++++ sysdeps/unix/sysv/linux/i386/dl-mmap.h | 27 +++++++++++++ sysdeps/unix/sysv/linux/i386/dl-writev.c | 32 +++++++++++++++ sysdeps/unix/sysv/linux/i386/dl-writev.h | 15 ++++--- sysdeps/unix/sysv/linux/i386/raise_direct.c | 26 ++++++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 7 ++++ .../x86_64/multiarch/dl-symbol-redir-ifunc.h | 32 +++++++++++++++ 31 files changed, 422 insertions(+), 9 deletions(-) create mode 100644 elf/tst-assert-startup-static.c create mode 100644 sysdeps/arm/armv7/multiarch/dl-symbol-redir-ifunc.h create mode 100644 sysdeps/generic/dl-mmap.h create mode 100644 sysdeps/powerpc/powerpc64/be/multiarch/dl-symbol-redir-ifunc.h create mode 100644 sysdeps/s390/string-bitops.h create mode 100644 sysdeps/unix/sysv/linux/i386/dl-mmap.c create mode 100644 sysdeps/unix/sysv/linux/i386/dl-mmap.h create mode 100644 sysdeps/unix/sysv/linux/i386/dl-writev.c create mode 100644 sysdeps/unix/sysv/linux/i386/raise_direct.c diff --git a/assert/Makefile b/assert/Makefile index 4c253a344a..541929c3b6 100644 --- a/assert/Makefile +++ b/assert/Makefile @@ -33,6 +33,11 @@ routines := \ assert-perr \ # routines +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-__libc_assert_fail.o = $(no-stack-protector) +CFLAGS-__libc_assert_fail.op = $(no-stack-protector) + tests := \ test-assert \ test-assert-2 \ diff --git a/elf/Makefile b/elf/Makefile index 7f039b5563..29d771ef7a 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -277,6 +277,7 @@ tests-static-normal := \ # tests-static-normal tests-static-internal := \ + tst-assert-startup-static \ tst-dl-printf-static \ tst-dl_find_object-static \ tst-env-setuid-tunables \ @@ -288,6 +289,10 @@ tests-static-internal := \ tst-tunables-enable_secure \ # tests-static-internal +tests-special += \ + $(objpfx)tst-assert-startup-static.out \ + # tests-special + CRT-tst-tls1-static-non-pie := $(csu-objpfx)crt1.o tst-tls1-static-non-pie-no-pie = yes @@ -3532,7 +3537,6 @@ $(objpfx)tst-origin.out: tst-origin.sh $(objpfx)tst-origin $(objpfx)tst-dlopen-sgid.out: $(objpfx)tst-dlopen-sgid-mod.so - ifeq ($(run-built-tests),yes) $(objpfx)tst-tls-debug-recursive.out: tst-tls-debug-recursive.sh \ $(objpfx)tst-recursive-tls \ @@ -3554,3 +3558,14 @@ $(objpfx)tst-dl-debug-exclude.out: tst-dl-debug-exclude.sh \ $(objpfx)tst-recursive-tls > $@; \ $(evaluate-test) endif + +CFLAGS-tst-assert-startup-static.c += $(no-stack-protector) +LDFLAGS-tst-assert-startup-static = -Wl,-z,muldefs + +$(objpfx)tst-assert-startup-static.out: $(objpfx)tst-assert-startup-static + $(test-program-cmd-before-env) \ + $(run-program-env) \ + $< > $@ 2>&1; echo "status: $$?" >> $@; \ + grep -q 'Fatal glibc error: tst-assert-startup-static' $@ \ + && grep -q '^status: 134$$' $@; \ + $(evaluate-test) diff --git a/elf/tst-assert-startup-static.c b/elf/tst-assert-startup-static.c new file mode 100644 index 0000000000..a3312cd9e5 --- /dev/null +++ b/elf/tst-assert-startup-static.c @@ -0,0 +1,40 @@ +/* Check if assert work during program startup. + 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 + . */ + +#include +#include + +/* The __tunables_init is called just before self-relocation and TLS setup, + and the __libc_assert_fail is used internally for assert() calls. */ +extern _Noreturn __typeof (__assert_fail) __libc_assert_fail; + +void __tunables_init (char **env) +{ +/* The assert called by the loader/startup issues __libc_assert_fail instead + of __libc_assert, and __libc_assert_fail does issues the translation + routines (which would require additional handling to be called at this + point, like disable stack protection). So issue the internal routine + directly, instead of using assert here. */ + __libc_assert_fail ("error", __FILE__, __LINE__, __func__); +} + +int main (int argc, char *argv[]) +{ + /* Fail with a different error code than abort. */ + exit (EXIT_FAILURE); +} diff --git a/libio/Makefile b/libio/Makefile index 08e1e0ec25..ec6b78c495 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -185,6 +185,11 @@ endif CPPFLAGS += $(libio-mtsafe) +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-libc_fatal.o = $(no-stack-protector) +CFLAGS-libc_fatal.op = $(no-stack-protector) + # Support for exception handling. CFLAGS-fileops.c += -fexceptions CFLAGS-fputc.c += -fexceptions diff --git a/stdlib/Makefile b/stdlib/Makefile index 04596b53b1..8a39121777 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -528,6 +528,11 @@ generated += \ tst-putenvmod.so \ # generated +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-abort.o = $(no-stack-protector) +CFLAGS-abort.op = $(no-stack-protector) + CFLAGS-bsearch.c += $(uses-callbacks) CFLAGS-qsort.c += $(uses-callbacks) CFLAGS-system.c += -fexceptions diff --git a/string/Makefile b/string/Makefile index aa0b0c2f57..969726cccb 100644 --- a/string/Makefile +++ b/string/Makefile @@ -287,6 +287,7 @@ CFLAGS-wordcopy.c += $(no-stack-protector) CFLAGS-strncmp.c += $(no-stack-protector) CFLAGS-memset.c += $(no-stack-protector) CFLAGS-strlen.c += $(no-stack-protector) +CFLAGS-strchrnul.c += $(no-stack-protector) ifeq ($(run-built-tests),yes) $(objpfx)tst-svc-cmp.out: tst-svc.expect $(objpfx)tst-svc.out diff --git a/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h index 9f772614bf..a686fd1f92 100644 --- a/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h @@ -19,6 +19,7 @@ #ifndef _DL_IFUNC_GENERIC_H #define _DL_IFUNC_GENERIC_H +asm ("memcpy = __memcpy_generic"); asm ("memset = __memset_generic"); asm ("strlen = __strlen_generic"); diff --git a/sysdeps/aarch64/multiarch/memcpy_generic.S b/sysdeps/aarch64/multiarch/memcpy_generic.S index c6d09081f4..d622268305 100644 --- a/sysdeps/aarch64/multiarch/memcpy_generic.S +++ b/sysdeps/aarch64/multiarch/memcpy_generic.S @@ -42,3 +42,7 @@ #endif #include "../memcpy.S" + +#if IS_IN (rtld) +strong_alias (memcpy, __memcpy_generic) +#endif diff --git a/sysdeps/arm/armv7/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/arm/armv7/multiarch/dl-symbol-redir-ifunc.h new file mode 100644 index 0000000000..4a6c81aa8d --- /dev/null +++ b/sysdeps/arm/armv7/multiarch/dl-symbol-redir-ifunc.h @@ -0,0 +1,27 @@ +/* Symbol redirection for loader/static initialization code. Linux/ARM + version. + 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 _DL_IFUNC_GENERIC_H +#define _DL_IFUNC_GENERIC_H + +#ifndef __ARM_NEON__ +asm ("memcpy = __memcpy_vfp"); +#endif + +#endif diff --git a/sysdeps/generic/dl-mmap.h b/sysdeps/generic/dl-mmap.h new file mode 100644 index 0000000000..f786be0930 --- /dev/null +++ b/sysdeps/generic/dl-mmap.h @@ -0,0 +1,34 @@ +/* mmap wrapper for dynamic loader. + 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 _DL_MMAP_H +#define _DL_MMAP_H + +#include + +/* This mmap call is used to allocate some memory to backup assert() messages + before TLS setup is done (which setup the thread pointer used by some ABIs + to issues syscalls). */ + +static inline void * +_dl_mmap (void *addr, size_t len, int prot, int flags) +{ + return __mmap (addr, len, prot, flags, -1, 0); +} + +#endif diff --git a/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h index 8af00d2846..43f50f8bcc 100644 --- a/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h @@ -20,8 +20,10 @@ #define _DL_IFUNC_GENERIC_H #ifndef SHARED +asm ("memcpy = __memcpy_aligned"); asm ("memset = __memset_aligned"); asm ("memcmp = __memcmp_aligned"); +asm ("__strchrnul = __strchrnul_aligned"); asm ("strlen = __strlen_aligned"); #endif diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index 3f0e302b5e..1ff20d4feb 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -16,7 +16,12 @@ License along with the GNU C Library; if not, see . */ +/* Mark symbols hidden in static PIE for early self relocation to work. */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include +#include #include #include #include @@ -24,6 +29,7 @@ #include #include #include +#include #ifdef FATAL_PREPARE_INCLUDE #include FATAL_PREPARE_INCLUDE @@ -113,9 +119,9 @@ __libc_message_impl (const char *vma_name, const char *fmt, ...) total = ALIGN_UP (total + sizeof (struct abort_msg_s) + 1, GLRO(dl_pagesize)); - struct abort_msg_s *buf = __mmap (NULL, total, - PROT_READ | PROT_WRITE, - MAP_ANON | MAP_PRIVATE, -1, 0); + struct abort_msg_s *buf = _dl_mmap (NULL, total, + PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE); if (__glibc_likely (buf != MAP_FAILED)) { buf->size = total; diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/Makefile b/sysdeps/powerpc/powerpc32/power4/multiarch/Makefile index 3a49b855ca..60ba2e50d2 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/Makefile +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/Makefile @@ -11,4 +11,9 @@ sysdep_routines += memcpy-power7 memcpy-a2 memcpy-power6 memcpy-cell \ strchr-power7 strchr-ppc32 \ wordcopy-power7 wordcopy-ppc32 \ memmove-power7 memmove-ppc + +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-strchrnul-ppc32.o = $(no-stack-protector) +CFLAGS-strchrnul-ppc32.op = $(no-stack-protector) endif diff --git a/sysdeps/powerpc/powerpc64/be/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/powerpc/powerpc64/be/multiarch/dl-symbol-redir-ifunc.h new file mode 100644 index 0000000000..560f57366b --- /dev/null +++ b/sysdeps/powerpc/powerpc64/be/multiarch/dl-symbol-redir-ifunc.h @@ -0,0 +1,27 @@ +/* Symbol rediretion for loader/static initialization code. + 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 _DL_IFUNC_GENERIC_H +#define _DL_IFUNC_GENERIC_H + +#ifndef SHARED +asm ("__mempcpy = __mempcpy_ppc"); +asm ("__strchrnul = __strchrnul_ppc"); +#endif + +#endif diff --git a/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h index 4680092cd8..03f6f12032 100644 --- a/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h @@ -21,5 +21,6 @@ asm ("memset = __memset_power8"); asm ("__mempcpy = __mempcpy_power7"); +asm ("__strchrnul = __strchrnul_power8"); #endif diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile index c9178223a8..0437a05a89 100644 --- a/sysdeps/powerpc/powerpc64/multiarch/Makefile +++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile @@ -40,3 +40,4 @@ endif # Called during static initialization CFLAGS-strncmp-ppc64.c += $(no-stack-protector) +CFLAGS-strchrnul-ppc64.c += $(no-stack-protector) diff --git a/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h index 24b78711e3..69a0790838 100644 --- a/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h @@ -21,6 +21,7 @@ #ifndef SHARED asm ("memset = __memset_generic"); +asm ("memcpy = __memcpy_generic"); #endif #endif diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile index 985b4f25ee..078c0d165d 100644 --- a/sysdeps/s390/Makefile +++ b/sysdeps/s390/Makefile @@ -104,6 +104,11 @@ routines_no_fortify += \ # routines_no_fortify endif +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-strchrnul-c.o = $(no-stack-protector) +CFLAGS-strchrnul-c.op = $(no-stack-protector) + ifeq ($(subdir),wcsmbs) sysdep_routines += wcslen wcslen-vx wcslen-c \ wcsnlen wcsnlen-vx wcsnlen-c \ diff --git a/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h index a128cd05bd..3721f3d95b 100644 --- a/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h @@ -21,11 +21,15 @@ #include #include +#include #define IFUNC_SYMBOL_STR1(s) #s #define IFUNC_SYMBOL_STR(s) IFUNC_SYMBOL_STR1(s) +#ifndef SHARED asm ("memset = " IFUNC_SYMBOL_STR(MEMSET_DEFAULT)); asm ("memcmp = " IFUNC_SYMBOL_STR(MEMCMP_DEFAULT)); +asm ("__strchrnul = " IFUNC_SYMBOL_STR(STRCHRNUL_DEFAULT)); +#endif #endif diff --git a/sysdeps/s390/string-bitops.h b/sysdeps/s390/string-bitops.h new file mode 100644 index 0000000000..f660d019c7 --- /dev/null +++ b/sysdeps/s390/string-bitops.h @@ -0,0 +1,27 @@ +/* Zero byte detection, define whether to use stdbit.h + 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 + . */ + +/* s390x support static-pie and the libgcc implementation for + __builtin_clzl/__builtin_ctzl might access extern data that is not marked + as hidden, which creates additiona GOT access that is used before + self-relocation. */ +#if __ARCH__ > 6 +# define HAVE_BITOPTS_WORKING 1 +#else +# define HAVE_BITOPTS_WORKING 0 +#endif diff --git a/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h index ffe1eee87d..1a76efd542 100644 --- a/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h @@ -19,6 +19,9 @@ #ifndef _DL_IFUNC_GENERIC_H #define _DL_IFUNC_GENERIC_H +#ifndef SHARED asm ("memset = __memset_ultra1"); +asm ("memcpy = __memcpy_ultra1"); +#endif #endif diff --git a/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h index ffe1eee87d..1a76efd542 100644 --- a/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h @@ -19,6 +19,9 @@ #ifndef _DL_IFUNC_GENERIC_H #define _DL_IFUNC_GENERIC_H +#ifndef SHARED asm ("memset = __memset_ultra1"); +asm ("memcpy = __memcpy_ultra1"); +#endif #endif diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 8797c5c9b3..18727605ce 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -114,6 +114,11 @@ sysdep_routines += \ xstat \ xstat64 \ # sysdep_routines +# +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-setvmaname.o = $(no-stack-protector) +CFLAGS-setvmaname.op = $(no-stack-protector) CFLAGS-gethostid.c = -fexceptions CFLAGS-tee.c = -fexceptions -fasynchronous-unwind-tables @@ -459,6 +464,13 @@ sysdep_routines += \ raise_direct \ # sysdep_routines +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-raise.o = $(no-stack-protector) +CFLAGS-raise.op = $(no-stack-protector) +CFLAGS-raise_direct.o = $(no-stack-protector) +CFLAGS-raise_direct.op = $(no-stack-protector) + tests-special += \ $(objpfx)tst-signal-numbers.out \ # tests-special diff --git a/sysdeps/unix/sysv/linux/i386/Makefile b/sysdeps/unix/sysv/linux/i386/Makefile index f1f8c3f44c..9a70905df8 100644 --- a/sysdeps/unix/sysv/linux/i386/Makefile +++ b/sysdeps/unix/sysv/linux/i386/Makefile @@ -28,3 +28,17 @@ ifeq ($(subdir),rt) librt-routines += sysdep librt-shared-only-routines += sysdep endif + +ifeq ($(subdir),elf) +sysdep_routines += \ + dl-mmap \ + dl-writev \ + # sysdep-routines + +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-dl-mmap.o = $(no-stack-protector) +CFLAGS-dl-mmap.op = $(no-stack-protector) +CFLAGS-dl-writev.o = $(no-stack-protector) +CFLAGS-dl-writev.op = $(no-stack-protector) +endif diff --git a/sysdeps/unix/sysv/linux/i386/dl-mmap.c b/sysdeps/unix/sysv/linux/i386/dl-mmap.c new file mode 100644 index 0000000000..ab6f96300f --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/dl-mmap.c @@ -0,0 +1,36 @@ +/* mmap wrapper for dynamic loader. Linux/i386 version. + 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 + . */ + +/* This mmap call is used to allocate some memory to backup assert() messages + before TLS setup is done, so it can not use "call *%gs:SYSINFO_OFFSET" + during startup in static PIE. */ +#if BUILD_PIE_DEFAULT +# define I386_USE_SYSENTER 0 +#endif + +#include +#include +#include +#include + +void * +_dl_mmap (void *addr, size_t len, int prot, int flags) +{ + return (void *) MMAP_CALL (mmap2, addr, len, prot, flags, -1, 0); +} + diff --git a/sysdeps/unix/sysv/linux/i386/dl-mmap.h b/sysdeps/unix/sysv/linux/i386/dl-mmap.h new file mode 100644 index 0000000000..291f92ee14 --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/dl-mmap.h @@ -0,0 +1,27 @@ +/* mmap wrapper for dynamic loader. + 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 _DL_MMAP_H +#define _DL_MMAP_H + +/* i386 requires out-of-line implementation because it sets + I386_USE_SYSENTER to 0 to avoid use the vDSO. */ +void * _dl_mmap (void *addr, size_t len, int prot, int flags) + attribute_hidden; + +#endif diff --git a/sysdeps/unix/sysv/linux/i386/dl-writev.c b/sysdeps/unix/sysv/linux/i386/dl-writev.c new file mode 100644 index 0000000000..ef6a6a20b8 --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/dl-writev.c @@ -0,0 +1,32 @@ +/* writev wrapper for the dynamic linker. Linux/i386 version. + Copyright (C) 2013-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 + . */ + +/* This writev call is used to assert() before TLS setup is done, so it can + not use "call *%gs:SYSINFO_OFFSET" during startup in static PIE. */ +#if BUILD_PIE_DEFAULT +# define I386_USE_SYSENTER 0 +#endif + +#include +#include + +ssize_t +_dl_writev (int fd, const struct iovec *iov, size_t niov) +{ + return INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); +} diff --git a/sysdeps/unix/sysv/linux/i386/dl-writev.h b/sysdeps/unix/sysv/linux/i386/dl-writev.h index 8327d32374..d92c74d712 100644 --- a/sysdeps/unix/sysv/linux/i386/dl-writev.h +++ b/sysdeps/unix/sysv/linux/i386/dl-writev.h @@ -16,9 +16,14 @@ License along with the GNU C Library; if not, see . */ -#if BUILD_PIE_DEFAULT -/* Can't use "call *%gs:SYSINFO_OFFSET" during startup in static PIE. */ -# define I386_USE_SYSENTER 0 -#endif +#ifndef _DL_WRITEV_H +#define _DL_WRITEV_H -#include +#include + +/* i386 requires out-of-line implementation because it sets + I386_USE_SYSENTER to 0 to avoid use the vDSO. */ +ssize_t _dl_writev (int fd, const struct iovec *iov, size_t niov) + attribute_hidden; + +#endif diff --git a/sysdeps/unix/sysv/linux/i386/raise_direct.c b/sysdeps/unix/sysv/linux/i386/raise_direct.c new file mode 100644 index 0000000000..b23b8e5386 --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/raise_direct.c @@ -0,0 +1,26 @@ +/* Internal function to send a signal to itself. Linux/i386 version. + 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 + . */ + +/* This is called from abort() (issued by assert()) before TLS setup is done, + so it can not use "call *%gs:SYSINFO_OFFSET" during startup in static + PIE. */ +#if BUILD_PIE_DEFAULT +# define I386_USE_SYSENTER 0 +#endif + +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index a865090a53..484ff77f7d 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -8,6 +8,13 @@ sysdep_routines += \ memset-vector \ # sysdep_routines +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-memset-generic.o = $(no-stack-protector) +CFLAGS-memset-generic.op = $(no-stack-protector) +CFLAGS-memcpy-generic.o = $(no-stack-protector) +CFLAGS-memcpy-generic.op = $(no-stack-protector) + CFLAGS-memcpy_noalignment.c += -mno-strict-align # Called during static initialization CFLAGS-memset-generic.c += $(no-stack-protector) diff --git a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h index b607e525f2..15968896c0 100644 --- a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h @@ -54,6 +54,38 @@ asm ("memcmp = " HAVE_MEMCMP_IFUNC_GENERIC); asm ("strlen = " HAVE_STRCMP_IFUNC_GENERIC); +#if MINIMUM_X86_ISA_LEVEL >= 4 +# define HAVE_MEMPCPY_IFUNC_GENERIC "__mempcpy_evex_unaligned" +#elif MINIMUM_X86_ISA_LEVEL == 3 +# define HAVE_MEMPCPY_IFUNC_GENERIC "__mempcpy_avx_unaligned" +#else +# define HAVE_MEMPCPY_IFUNC_GENERIC "__mempcpy_sse2_unaligned" +#endif + +asm ("__mempcpy = " HAVE_MEMPCPY_IFUNC_GENERIC); + + +#if MINIMUM_X86_ISA_LEVEL >= 4 +# define HAVE_STRCHRNUL_IFUNC_GENERIC "__strchrnul_evex" +#elif MINIMUM_X86_ISA_LEVEL == 3 +# define HAVE_STRCHRNUL_IFUNC_GENERIC "__strchrnul_avx2" +#else +# define HAVE_STRCHRNUL_IFUNC_GENERIC "__strchrnul_sse2" +#endif + +asm ("__strchrnul = " HAVE_STRCHRNUL_IFUNC_GENERIC); + + +#if MINIMUM_X86_ISA_LEVEL >= 4 +# define HAVE_STRLEN_IFUNC_GENERIC "__strlen_evex" +#elif MINIMUM_X86_ISA_LEVEL == 3 +# define HAVE_STRLEN_IFUNC_GENERIC "__strlen_avx2" +#else +# define HAVE_STRLEN_IFUNC_GENERIC "__strlen_sse2" +#endif + +asm ("strlen = " HAVE_STRLEN_IFUNC_GENERIC); + #endif /* SHARED */ #endif From patchwork Wed Mar 18 19:34:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 131924 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 85F014C31806 for ; Wed, 18 Mar 2026 19:39:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 85F014C31806 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=b+cwVwM3 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x122b.google.com (mail-dl1-x122b.google.com [IPv6:2607:f8b0:4864:20::122b]) by sourceware.org (Postfix) with ESMTPS id BEB6F4C3181B for ; Wed, 18 Mar 2026 19:35:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEB6F4C3181B 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 BEB6F4C3181B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::122b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862511; cv=none; b=euBP69230PhUH3Y7afPjKdkskPq/MFz1PNb3Ey0chrIqk7uWBfIDIHntw/en5mF2TdAanwoq/yQqs9NOC6YwJgtAvBQbrSBtnBNZkj+cl1dVvx4hwLkmbH7t0RC3w/f3yfZ4yT/hYf939ZUVUNI/jhODepgbDZUecD5OIYQPLUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862511; c=relaxed/simple; bh=VGDoQ1L9FmrhaLO0mQ9+B4huwmJm2X+3cdZhNcMWsyE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sZcxasHM/nqzLRjygPFjZypyfsHIxxqY7pdBOnnmH506UqHZ340BPvGdvb9j+GMnVV9/FSnqJTLLyW+kNd7Bap7TcSspZrT3CUB+Hb389C8MBjMCVlIMgq5BJXmTjskW/F0/fhYzsdqb1WPl3HV9LTysC+ct7eTbowD7YQeAWeM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEB6F4C3181B Received: by mail-dl1-x122b.google.com with SMTP id a92af1059eb24-126ea4b77adso286291c88.1 for ; Wed, 18 Mar 2026 12:35:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1773862510; x=1774467310; 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=fCGnXi5bNDJkNd6r9ndXX+wrMhl5VJ+V6iZerRFwyqI=; b=b+cwVwM3ZGri4zG3j0Z6SrHil/hgd2JIab8mEw+UEvet3YEPBkL38PTcHN0DOH0Nhj TDgOcVRoXhz5/qtunIco8bIJRVpKRvIEF4s8FHVerdVsZhYQQ6HLj7RRcPahAZxkTABA wn84a34yN3yleQWVLuMV0Zp1HMx76stBlV0UvQc2M7ZEpwBYQDjrfGdno3l9jI90Pbe6 /9EzCR8Pm0zRoddU+pQVXKzuWdT4h2kVB/vg8gsrrmR0e1RDGMPu+Vmv9rWqkVCtJZEY 5kYB7mMHNcYeZsYIfxVkKGAB2mA+3p9cA2aEGiTIMDdozM6vkOqkU2CocbovTHfDMx8q MtcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773862510; x=1774467310; 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=fCGnXi5bNDJkNd6r9ndXX+wrMhl5VJ+V6iZerRFwyqI=; b=EhHlMcJREGLS6RMr0W690MYN9viBk4r9b4AJWLUWKwFt4W6nkTUA/PwRfFum8indTt ksokmqGWiJcymuCKZGvnme7BAAtP/oWxicWg/RModKJshPZ/6JW7ue8PuzKYB4fiUPGE 98uBEv7OY7YLZwP36qRAEO6Dosw+24SC5Ma0SMxvZdJkGGkM8OBzSQZ57B9snHYszvXp CvdLfhxVvAOZuN91bOXXmSZNcgAZD+5l//CvufVjyUsmZsM9n1HtPZ0+vlonaiO8dpAW 0eEST5oK7+EHNuz8KqSqahDGkf5/cmCL3zg6xUWghFt45uXgrpYjn/RHZDcf9AX5EPEa Ev6g== X-Gm-Message-State: AOJu0YyG5h6UsWbKZtfZrSqVYN8pJ8s7J6qZqIkQxw3GHTKBQhdJEm/t 3Hll8xfX9M1/rKMs8cI0PW9Alu3Btv9C5dxkV1eGRFsKXAjBw9Xx4jRA6kbiXqN3ijIoFohNG07 nKsJR X-Gm-Gg: ATEYQzxEOdE62Fal7Pmm0ceJTSvQja2MK4CPrENe9LN2idJFQwWJTxSpGp/Tet6IKnq TpQ++u69OyHyUUElxy3iGjzJeLoD0RZi98OxQFjhzl10XaG0DCfn+1PDnz9Mhks/Ore7554Fxl4 mG+PWB82J7rHM8ysaVsUzOdEdO/r/s8ZCk7AigsLB2vKdEK+lmqvej1fw6N914Q2wasKUmNeuU7 L1WS5TSSzVA9+ZELHU+4/cifrfAvhPTna+RWztHtw0NqBm8PEpP5IcTxDcI5c5IBhGK0+qlXv9j fLL4PTERUEwCmXhUrMJ+Yvgi4J3WVSQ4JRS+5esXRPvGJfJJ4vuE6E6YwueVwN4kCU0Vo+h9rsB pyr+S/IJwZHBU2NyDGVAdohVp7l2VRG4wzs4+fn/e9cm6FvrUBWQH3JOSaP/EUDlU2zlpcd7meu zW5LlEWtalj05svAwoZscDhMbvA5Ms5PjEs9o= X-Received: by 2002:a05:7022:160b:b0:128:d23d:81a2 with SMTP id a92af1059eb24-129a7160dfamr2336061c88.29.1773862510138; Wed, 18 Mar 2026 12:35:10 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:f5a4:2159:38c8:c951:d029]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-129b4147522sm4238937c88.15.2026.03.18.12.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 12:35:09 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer , Samuel Thibault Subject: [PATCH v8 4/6] elf: Allow RPATH/RUNPATH for static-pie (BZ 33326) Date: Wed, 18 Mar 2026 16:34:15 -0300 Message-ID: <20260318193454.2466865-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> References: <20260318193454.2466865-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_NONE, 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 initial static-pie support (commit 9d7a3741c9e59eba87fb) reused ld.so ELF parsing logic, even though RPATH/RUNPATH should not appear in the static-pie bootstrap. With static PIE, RPATH/RUNPATH on the loader typically indicates a toolchain misconfiguration. However, for static PIE, the presence of RPATH/RUNPATH has no impact because these binaries do not use dynamic linking at runtime. Static binaries do not support rpath because they lack dynamic sections, and adding static-pie support affects only the dlopen function. If static dlopen support is removed, this change has no effect. This change also simplifies elf_get_dynamic_info and removes a difference between dynamic and static binaries. Tested on aarch64-linux-gnu and x86_64-linux-gnu. Reviewed-by: Florian Weimer --- elf/Makefile | 11 ++++++++ elf/dl-load.c | 2 +- elf/dl-reloc-static-pie.c | 2 +- elf/get-dynamic-info.h | 5 ++-- elf/rtld.c | 4 +-- elf/setup-vdso.h | 2 +- elf/tst-pie-rpath-mod.c | 19 ++++++++++++++ elf/tst-pie-rpath-static.c | 52 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 elf/tst-pie-rpath-mod.c create mode 100644 elf/tst-pie-rpath-static.c diff --git a/elf/Makefile b/elf/Makefile index 29d771ef7a..986ef6b388 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1201,7 +1201,11 @@ tests += \ # tests tests-static += \ tst-pie-address-static \ + tst-pie-rpath-static \ # tests-static +modules-names += \ + tst-pie-rpath-mod \ + # modules-names ifeq (yes,$(aligned-65536)) tests += tst-pie-bss-static tests-static += tst-pie-bss-static @@ -3569,3 +3573,10 @@ $(objpfx)tst-assert-startup-static.out: $(objpfx)tst-assert-startup-static grep -q 'Fatal glibc error: tst-assert-startup-static' $@ \ && grep -q '^status: 134$$' $@; \ $(evaluate-test) + +LDFLAGS-tst-pie-rpath-static += -Wl,-rpath,\$$ORIGIN/tst-pie-rpath-static-subdir +CFLAGS-tst-pie-rpath-static.c += -DPFX=\"$(objpfx)\" +ifeq (no,$(build-hardcoded-path-in-tests)) +LDFLAGS-tst-pie-rpath-mod.so += -Wl,-rpath,$(rpath-link) +endif +$(objpfx)tst-pie-rpath-static.out: $(objpfx)tst-pie-rpath-mod.so diff --git a/elf/dl-load.c b/elf/dl-load.c index 7355eef8e7..c5ea40fa4a 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1269,7 +1269,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, if (l->l_ld != NULL) l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr); - elf_get_dynamic_info (l, false, false); + elf_get_dynamic_info (l, false); /* Make sure we are not dlopen'ing an object that has the DF_1_NOOPEN flag set, or a PIE object. */ diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c index bdff2b5ee2..22acd9bb4f 100644 --- a/elf/dl-reloc-static-pie.c +++ b/elf/dl-reloc-static-pie.c @@ -69,7 +69,7 @@ _dl_relocate_static_pie (void) /* Read our own dynamic section and fill in the info array. */ main_map->l_ld = ((void *) l_addr + elf_machine_dynamic ()); - elf_get_dynamic_info (main_map, false, true); + elf_get_dynamic_info (main_map, false); # ifdef ELF_MACHINE_BEFORE_RTLD_RELOC ELF_MACHINE_BEFORE_RTLD_RELOC (main_map, main_map->l_info); diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h index 46faa34acf..9591d00d59 100644 --- a/elf/get-dynamic-info.h +++ b/elf/get-dynamic-info.h @@ -26,8 +26,7 @@ #include static inline void __attribute__ ((unused, always_inline)) -elf_get_dynamic_info (struct link_map *l, bool bootstrap, - bool static_pie_bootstrap) +elf_get_dynamic_info (struct link_map *l, bool bootstrap) { #if __ELF_NATIVE_CLASS == 32 typedef Elf32_Word d_tag_utype; @@ -128,7 +127,7 @@ elf_get_dynamic_info (struct link_map *l, bool bootstrap, #endif if (info[DT_RELR] != NULL) assert (info[DT_RELRENT]->d_un.d_val == sizeof (ElfW(Relr))); - if (bootstrap || static_pie_bootstrap) + if (bootstrap) { assert (info[DT_RUNPATH] == NULL); assert (info[DT_RPATH] == NULL); diff --git a/elf/rtld.c b/elf/rtld.c index e1c2105ba6..783db6eb5c 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -547,7 +547,7 @@ _dl_start (void *arg) /* Read our own dynamic section and fill in the info array. */ bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic (); bootstrap_map.l_ld_readonly = DL_RO_DYN_SECTION; - elf_get_dynamic_info (&bootstrap_map, true, false); + elf_get_dynamic_info (&bootstrap_map, true); #if NO_TLS_OFFSET != 0 bootstrap_map.l_tls_offset = NO_TLS_OFFSET; @@ -1706,7 +1706,7 @@ dl_main (const ElfW(Phdr) *phdr, if (! rtld_is_main) { /* Extract the contents of the dynamic section for easy access. */ - elf_get_dynamic_info (main_map, false, false); + elf_get_dynamic_info (main_map, false); /* If the main map is libc.so, update the base namespace to refer to this map. If libc.so is loaded later, this happens diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h index 0dba7072d5..58b7712046 100644 --- a/elf/setup-vdso.h +++ b/elf/setup-vdso.h @@ -64,7 +64,7 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)), l->l_addr = l->l_map_start - l->l_addr; l->l_map_end += l->l_addr; l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr); - elf_get_dynamic_info (l, false, false); + elf_get_dynamic_info (l, false); _dl_setup_hash (l); l->l_relocated = 1; diff --git a/elf/tst-pie-rpath-mod.c b/elf/tst-pie-rpath-mod.c new file mode 100644 index 0000000000..719eb41e09 --- /dev/null +++ b/elf/tst-pie-rpath-mod.c @@ -0,0 +1,19 @@ +/* Check if RPATH/RUNPATH is allowed for static-pie. + 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 + . */ + +int foo (void) { return 42; } diff --git a/elf/tst-pie-rpath-static.c b/elf/tst-pie-rpath-static.c new file mode 100644 index 0000000000..02fb05d2e6 --- /dev/null +++ b/elf/tst-pie-rpath-static.c @@ -0,0 +1,52 @@ +/* Check if RPATH/RUNPATH is allowed for static-pie. + 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 + . */ + +#include +#include +#include +#include +#include +#include + +#define LIBNAME "tst-pie-rpath-mod.so" +#define TESTSUBDIR PFX "tst-pie-rpath-static-subdir" +#define LIBPATH TESTSUBDIR "/" LIBNAME + +static void +do_prepare (int argc, char **argv) +{ + xmkdir (TESTSUBDIR, 0777); + add_temp_file (TESTSUBDIR); + + support_copy_file (PFX "/" LIBNAME, LIBPATH); + add_temp_file (LIBPATH); +} +#define PREPARE do_prepare + +static int +do_test (void) +{ + void *h = xdlopen (LIBNAME, RTLD_NOW); + int (*foo)(void) = xdlsym (h, "foo"); + TEST_COMPARE (foo (), 42); + xdlclose (h); + + return 0; +} + +#include From patchwork Wed Mar 18 19:34:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 131919 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 0AB184C31807 for ; Wed, 18 Mar 2026 19:36:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0AB184C31807 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=g1ZM7J79 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1230.google.com (mail-dl1-x1230.google.com [IPv6:2607:f8b0:4864:20::1230]) by sourceware.org (Postfix) with ESMTPS id 98B694C31818 for ; Wed, 18 Mar 2026 19:35:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 98B694C31818 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 98B694C31818 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1230 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862513; cv=none; b=fJOGJogSfF206DNoYCQsPfqV4qidaWhZjTM8Co8x8S+xTQbk1lLc1X0YxTOW20QGBjeqCCzDDy6nxS968zYKY6arGdtn6F16H55+RO3HDIFJTSruzCSuiAA7CdLqUF7JTC7/FtGoEz5gNeKTUv+BTVK3EZuwZlGL9U4WmmxTv7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862513; c=relaxed/simple; bh=qX6NaoaqkfI91yEdrUmt5n8mpGEwukgKHbVEDMTo9b4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Ny3W8q3JO4COvmV+aDQvarVMYq1XenWnIkytPOgaZDbah7xS2VALlL+GWTwFm+7jb+cnIEFRlq6BrWz0aBPHn1XYB+jww+e/75gA8EN3NQ7yw2fiTr3ldFEi3uHSnKK5735t50Ii+p2UTNAar3xrSoznhYigubigqykItJR2KY4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 98B694C31818 Received: by mail-dl1-x1230.google.com with SMTP id a92af1059eb24-1271195d2a7so738733c88.0 for ; Wed, 18 Mar 2026 12:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1773862512; x=1774467312; 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=CZteRVy6w3MH5SGP9Xuq3IUuP3eG7VPBPi0329lR9P4=; b=g1ZM7J799d7PJNuaDdoHj7+Y77hBdFpJw8K4swqy/kTsSBJXIWv4OIASfWKMxBnX48 X/rOdAVwUDjz5cYCOt7RCM3aR3quAPUlatkCPEhhnoCeF/ThsaMWTpG+9mvYLbOdN6Nc s+A5WIFtGdr1+2gztsWe2yXMWkyhinOszkefWYFuKQDhOXZIKrBQK23IrPx6zvb0iLlL 7TaQjSmAyevCuRlkvFm3j1swVdSQ6yEetOH11x0BVTNo6Hdv3OGsPmKHJDlv4UMmolcG VznXDnGAn5d2EHILyxw3kFfjUJzDNhmpfDX+RufPgavafTE0X5m4UBTgXiL3MC8fKC/3 v0Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773862512; x=1774467312; 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=CZteRVy6w3MH5SGP9Xuq3IUuP3eG7VPBPi0329lR9P4=; b=WTHhaP5wRmzVeQtOjXasKmxT+xP2cod+OwJjF3wfWN77eM5HWAkK2aYFxtaDbkP1F7 AX28IMDbKwrmrkacHRO26wCsTAp5HXh2Akj1vxZ15hd2rcz88bZASyASD+EjAIArzOXD ZfZmiIB3ESMGU9vOIk3h2B/oaHI/3uSgQeSbp3+o/eC2XnmwyMn3+g5cRjU12RZtlYY2 9hNTcwju7RuBqFU2hQBO/PnovV18UGev4jxDqkWQW6ZdJenwgaUznVU51oHW0Vgyy0sZ RWk2M+6op9VV3oqVSBzLhnihasaWm8J678bV/bdgtyLR1VczircJk+AkjKn6YJICsxQj tVNA== X-Gm-Message-State: AOJu0YwJWdqeZN3V4VceAvD4KCH7trIEcCUBMjsZqWfAHN9ndvez9Nq1 ezASA6GfOaMZUNHMwrobIVYW3GpuqYfAVQS28HjcSM+OaRpuIqI6e3htcA8IjYoqs4/c49bb0UV 3L1/q X-Gm-Gg: ATEYQzz3guiYBPbx4DU/y8bRWpNGHatrI27z0BbMx2D5FLcOf1fWp6diGsDNIEXeZRq rPvemC1ZfBHuVdteNRI3upd1V0WVYG5usKlC60SOXJFFK1XuUhfxhZFOhq1Gt2muFKbYNop97/O jeTtjVcMU2MuGCIvCDpLVB+UVias2RT3heo8ed2MGcA5TjX0J67fecC5XHbjFYCewVK1f3CeQ6w r59ycRvIHUuIk1n2QW6UZO12KQzUzv/W2FFNFaLMCTOTvtaYoZUdGvuz/pzsHrFS2gElHZDXUXh 4UUQlkvrT+5NUeGv7khgHM27KrqBins6LwPUU0ckiOo6avxd73QP8WxILyvgKFUeVgxOYzofH8M 7235IDSV6pL5ohIEwdy+7VXFN4+ELrptjog/PnA8fWzfWZDpExa5h9e/sjbWjR/0Vh3F9r27qVR KfMcUeG30rHPRY9Ni75xdAxYNS+BT8CI9q3sdV7BRtpTJPvw== X-Received: by 2002:a05:7022:6986:b0:127:5cfd:785 with SMTP id a92af1059eb24-1299e86d930mr2288017c88.4.1773862512088; Wed, 18 Mar 2026 12:35:12 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:f5a4:2159:38c8:c951:d029]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-129b4147522sm4238937c88.15.2026.03.18.12.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 12:35:11 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer , Samuel Thibault Subject: [PATCH v8 5/6] elf: Remove __chk_fail from dl-minimal.c Date: Wed, 18 Mar 2026 16:34:16 -0300 Message-ID: <20260318193454.2466865-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> References: <20260318193454.2466865-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 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 elf/rtld-Rules adds $(no-fortify-source) on rtld object, so __chk_fail is never used. Reviewed-by: Florian Weimer --- elf/Makefile | 1 + elf/dl-minimal.c | 8 -------- include/sys/cdefs.h | 1 - 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/elf/Makefile b/elf/Makefile index 986ef6b388..36d2207732 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1508,6 +1508,7 @@ endif # These symbols might be emitted by the compiler when fortify is enabled # (through builtins). rtld-stubbed-symbols += \ + __GI___chk_fail \ __GI___vfprintf_chk \ __GI___vsprintf_chk \ __GI___vsyslog_chk \ diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index 591d49e3f5..4583c48db3 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -163,14 +163,6 @@ __libc_fatal (const char *message) } rtld_hidden_def (__libc_fatal) -void -__attribute__ ((noreturn)) -__chk_fail (void) -{ - _exit (127); -} -rtld_hidden_def (__chk_fail) - #ifndef NDEBUG /* Define (weakly) our own assert failure function which doesn't use stdio. If we are linked into the user program (-ldl), the normal __assert_fail diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h index a676f75f62..33d0a47f43 100644 --- a/include/sys/cdefs.h +++ b/include/sys/cdefs.h @@ -18,7 +18,6 @@ extern void __chk_fail (void) __attribute__ ((__noreturn__)); libc_hidden_proto (__chk_fail) -rtld_hidden_proto (__chk_fail) /* If we are using redirects internally to support long double, we need to tweak some macros to ensure the PLT bypass tricks From patchwork Wed Mar 18 19:34:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 131923 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 846754C3180C for ; Wed, 18 Mar 2026 19:38:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 846754C3180C 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=JOM4IjSg X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x122c.google.com (mail-dl1-x122c.google.com [IPv6:2607:f8b0:4864:20::122c]) by sourceware.org (Postfix) with ESMTPS id B5A384C3181B for ; Wed, 18 Mar 2026 19:35:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B5A384C3181B 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 B5A384C3181B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::122c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862515; cv=none; b=eRyteMAqfRcNlxMmpx0rEls+9BSITyvOcqAU+/Ab24Bz/zYf8ToCrqClRAIQMRYzErB3zhtl5dgfQzy8bBQrUg6Hmd0XQKaj5k2+edablGcnGtu+4YUKaX+g4W2ZHtnCvDcmVgUpenTc5hkxMNkL9YGMjsE2zJA4avOFzOJQVTw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773862515; c=relaxed/simple; bh=MBOwy8MIcRWCdZW8YEQVWPq+sBpudtufllsVsIQmqeA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FfZMSkIXs/g/PuZH4pB1A4kKfyXRipsEa5AWKvDZwhszD46ERnqWmX1Jnx2U6JUs14xLciPEpD+/k+R7lU8XDhJK49SdcvWQiirJu0/m/+lvVIo59l93NcZTF4uJ3DMRarbMVLL21HZsKI2AHJq0fKBJgWCWoLDZw/eiD5z9kMo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5A384C3181B Received: by mail-dl1-x122c.google.com with SMTP id a92af1059eb24-12776bebe9fso497654c88.1 for ; Wed, 18 Mar 2026 12:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1773862514; x=1774467314; 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=pj7P8uq9ExoSI/bag2JrrSGw02qclQ+utX/NqI3NK6Y=; b=JOM4IjSgOSmjpXpUrIsvxNuCBImqv2BU5p3l0U/upWjgC2sQ02dF5JHPdCpCnPOnCM M4zteMd1MxrieT23wWqJ1x1zfOtXQLV7gp4KlxHRxalrNpNqONDT+w4nJZNkqUdZHbYO hdinLOPKEUskkV0V6B4X3h3P91hS6Jc1m11Jfin9SWoaEXcZF89MxFrGdmzylyHHflag epB+DSozx2+HT4jEt1I/GTxJK3vZguv7l4FOZTgI6KD4TQV4ZpRZ9mhMF9NX1G4QsjRo t7sd9zcqUT8ozZfFbVzxm0R/FTrkGJOmJZtLkrJ5Z5JiHPyyOaR1DPouG0pHI8VfjYbO bBTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773862514; x=1774467314; 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=pj7P8uq9ExoSI/bag2JrrSGw02qclQ+utX/NqI3NK6Y=; b=NgLrgsp48LuVrgVI6IN5rhUo3pe8wgiZlpxL2HE2ZYnPZsqpV4NFZ/wIBweTU7wdnK +PVhLkZOMyUcfH106ndDeimRim+aLdPnhkKptysI3ooQHlpUz51RMj0GuEFOzqHVexdH RpJNShzZvOtm/CWgDWJQy5ZsgBVrGCXJo43eV1M2NxwQtxhcY2HX+pvpeUWY1cZbBKUs CjtlKrRG0h9a5QGoC8htFF115oGXJizd5yupBu5CSDHJbDydhHUnnOB5WCntoZVnOwA0 EeNzVhPrMez3BVVc+Vg62tDWJKK82pGDlcr9o9Fyswu4V4o+tFSoQ3qtXH1V+yMU6TMC PmYA== X-Gm-Message-State: AOJu0YyKkLdlObXIWBR7/07p6GdxJSB3OKkZ41ElrpwI0fiebxc/ghUi 0qy0iQkfKYmSi0n7GPTWEbZe696g9q3ynHPpKPuuBz/wcxGcOdIcSpcWr7f5vvqFFWNXCabw/Xo cd5b1 X-Gm-Gg: ATEYQzwfzDhZANqRFhmgqA+LiGse9j5VyvuASGkLhqg2wP+4p982W74gg82ll1Iik5v GpBcF5gEgZ2FjbQPRvby7eW/PGe6oasxIV0n5TSTuEcAP8Jed0gkmBFanUMJ5U8OWPRCYIgVGr0 ieMtK5CdIpEdEZWagrqwm/OYv6RCYbGYJB6OwN/T8U9kJw4jU0+M4IIRZxI5JIa4cPoY580bQEo Hl71O4meyOJzaBGX0LyAsikBBmcJsa0Kugvp8H9s7TWN4dY01YHZjZ7Ckepb9MoLo7Ud93Eno4L 8iVxuRtPggBTkXq6LcblBXDi6UveW9EAkkDnI1ROoyJzvAW2CTJxiV/dunHD3LtP4kdFpE7B6ux zenvvmYeGDxSd/AZZZY+XVOU6xkpCeWKM5EqZCJ+2k34o3HDp/bOCeDRLG3VUoFzpksl27lOwAd refYCY4g/NWkz2mc4ShIvSnKDmpKZIk9Nt2cc= X-Received: by 2002:a05:7022:670d:b0:128:cc34:3616 with SMTP id a92af1059eb24-129a70e2e62mr2797252c88.14.1773862513989; Wed, 18 Mar 2026 12:35:13 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:f5a4:2159:38c8:c951:d029]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-129b4147522sm4238937c88.15.2026.03.18.12.35.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Mar 2026 12:35:13 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer , Samuel Thibault Subject: [PATCH v8 6/6] elf: Raise SIGABRT for assert within ld.so Date: Wed, 18 Mar 2026 16:34:17 -0300 Message-ID: <20260318193454.2466865-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260318193454.2466865-1-adhemerval.zanella@linaro.org> References: <20260318193454.2466865-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, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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 assert static path already properly raises SIGABRT for assert during process startup, while ld.so only prints the error message and issues _exit. This prevents a coredump from being created if the environment is configured to do so. Similar to rtld malloc hooks, the assert symbol __assert_fail and assert_perror_fail need to be relocated to the libc symbol after the final relocation (so dlfcn.h functions call libc __assert_fail instead of dl-minimal.c one). The hook framework is renamed to be more generic, instead of tying to rtld malloc. The Hurd requires a proper __raise_direct implementation, issuing raise or kill pull a lot of symbols that prevents ld.so building. Checked on x86_64-linux-gnu and i686-linux-gnu. --- elf/dl-minimal.c | 82 ++++++++++++++++++++++++-------- elf/rtld.c | 4 +- include/assert.h | 2 + include/rtld-assert.h | 55 +++++++++++++++++++++ include/rtld-malloc.h | 14 ------ include/stdio.h | 2 + sysdeps/generic/ldsodefs.h | 16 +++++++ sysdeps/mach/hurd/Makefile | 6 +++ sysdeps/mach/hurd/raise_direct.c | 29 +++++++++++ 9 files changed, 175 insertions(+), 35 deletions(-) create mode 100644 include/rtld-assert.h create mode 100644 sysdeps/mach/hurd/raise_direct.c diff --git a/elf/dl-minimal.c b/elf/dl-minimal.c index 4583c48db3..c00f4427f8 100644 --- a/elf/dl-minimal.c +++ b/elf/dl-minimal.c @@ -27,23 +27,35 @@ #include #include -/* The rtld startup code calls __rtld_malloc_init_stubs after the +#include +#ifndef ABORT_INSTRUCTION +/* No such instruction is available. */ +# define ABORT_INSTRUCTION +#endif + +/* The rtld startup code calls __rtld_init_stubs after the first self-relocation to adjust the pointers to the minimal implementation below. Before the final relocation, - __rtld_malloc_init_real is called to replace the pointers with the + __rtld_init_real is called to replace the pointers with the real implementation. */ __typeof (calloc) *__rtld_calloc attribute_relro; __typeof (free) *__rtld_free attribute_relro; __typeof (malloc) *__rtld_malloc attribute_relro; __typeof (realloc) *__rtld_realloc attribute_relro; +__typeof (__assert_fail) *__rtld_assert_fail attribute_relro; +__typeof (__assert_perror_fail) *__rtld_assert_perror_fail attribute_relro; +__typeof (__libc_fatal) *__rtld_libc_fatal attribute_relro; void -__rtld_malloc_init_stubs (void) +__rtld_init_stubs (void) { __rtld_calloc = &__minimal_calloc; __rtld_free = &__minimal_free; __rtld_malloc = &__minimal_malloc; __rtld_realloc = &__minimal_realloc; + __rtld_assert_fail = &__assert_fail; + __rtld_assert_perror_fail = &__assert_perror_fail; + __rtld_libc_fatal = &__libc_fatal; } bool @@ -56,8 +68,8 @@ __rtld_malloc_is_complete (void) /* Lookup NAME at VERSION in the scope of MATCH. */ static void * -lookup_malloc_symbol (struct link_map *main_map, const char *name, - struct r_found_version *version) +lookup_symbol (struct link_map *main_map, const char *name, + struct r_found_version *version) { const ElfW(Sym) *ref = NULL; @@ -71,8 +83,19 @@ lookup_malloc_symbol (struct link_map *main_map, const char *name, return _dl_sym_post (result, ref, value, 0, main_map); } +static struct r_found_version +create_r_round_version (const char *name) +{ + return (struct r_found_version) { + .name = name, + .hidden = 0, + .hash = _dl_elf_hash (name), + .filename = NULL + }; +} + void -__rtld_malloc_init_real (struct link_map *main_map) +__rtld_init_real (struct link_map *main_map) { /* We cannot use relocations and initializers for this because the changes made by __rtld_malloc_init_stubs break REL-style @@ -82,16 +105,22 @@ __rtld_malloc_init_real (struct link_map *main_map) rtld relocation (which enables RELRO, after which the pointer variables cannot be written to). */ - struct r_found_version version; - version.name = symbol_version_string (libc, GLIBC_2_0); - version.hidden = 0; - version.hash = _dl_elf_hash (version.name); - version.filename = NULL; + struct r_found_version version = + create_r_round_version (symbol_version_string (libc, GLIBC_2_0)); - void *new_calloc = lookup_malloc_symbol (main_map, "calloc", &version); - void *new_free = lookup_malloc_symbol (main_map, "free", &version); - void *new_malloc = lookup_malloc_symbol (main_map, "malloc", &version); - void *new_realloc = lookup_malloc_symbol (main_map, "realloc", &version); + void *new_calloc = lookup_symbol (main_map, "calloc", &version); + void *new_free = lookup_symbol (main_map, "free", &version); + void *new_malloc = lookup_symbol (main_map, "malloc", &version); + void *new_realloc = lookup_symbol (main_map, "realloc", &version); + void *new_assert_fail = lookup_symbol (main_map, "__assert_fail", &version); + void *new_assert_perror_fail = lookup_symbol (main_map, "__assert_perror_fail", + &version); + + struct r_found_version version_private = + create_r_round_version (symbol_version_string (libc, GLIBC_PRIVATE)); + + void *new_libc_fatal = lookup_symbol (main_map, "__libc_fatal", + &version_private); /* Update the pointers in one go, so that any internal allocations performed by lookup_malloc_symbol see a consistent @@ -100,6 +129,9 @@ __rtld_malloc_init_real (struct link_map *main_map) __rtld_free = new_free; __rtld_malloc = new_malloc; __rtld_realloc = new_realloc; + __rtld_assert_fail = new_assert_fail; + __rtld_assert_perror_fail = new_assert_perror_fail; + __rtld_libc_fatal = new_libc_fatal; } @@ -114,6 +146,18 @@ __sigjmp_save (sigjmp_buf env, int savemask __attribute__ ((unused))) return 0; } +_Noreturn static void +rtld_abort (void) +{ + __raise_direct (SIGABRT); + /* Assume there is no SIGABRT handler installed during process startup, so + there is no need to add a fallback to change the signal disposition, as + the libc implementation does. */ + ABORT_INSTRUCTION; + + _exit (127); +} + /* Define our own version of the internal function used by strerror. We only provide the messages for some common errors. This avoids pulling in the whole error list. */ @@ -172,11 +216,11 @@ void weak_function __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function) { - _dl_fatal_printf ("\ + _dl_error_printf ("\ Inconsistency detected by ld.so: %s: %u: %s%sAssertion `%s' failed!\n", file, line, function ?: "", function ? ": " : "", assertion); - + rtld_abort (); } # ifndef NO_RTLD_HIDDEN rtld_hidden_weak (__assert_fail) @@ -188,11 +232,11 @@ __assert_perror_fail (int errnum, const char *function) { char errbuf[400]; - _dl_fatal_printf ("\ + _dl_error_printf ("\ Inconsistency detected by ld.so: %s: %u: %s%sUnexpected error: %s.\n", file, line, function ?: "", function ? ": " : "", __strerror_r (errnum, errbuf, sizeof errbuf)); - + rtld_abort (); } # ifndef NO_RTLD_HIDDEN rtld_hidden_weak (__assert_perror_fail) diff --git a/elf/rtld.c b/elf/rtld.c index 783db6eb5c..b78757bd11 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -451,7 +451,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info) { ElfW(Addr) start_addr; - __rtld_malloc_init_stubs (); + __rtld_init_stubs (); /* Do not use an initializer for these members because it would interfere with __rtld_static_init. */ @@ -2342,7 +2342,7 @@ dl_main (const ElfW(Phdr) *phdr, rtld_timer_accum (&relocate_time, start); __rtld_mutex_init (); - __rtld_malloc_init_real (main_map); + __rtld_init_real (main_map); /* Update copy-relocated _r_debug if necessary. */ _dl_debug_post_relocate (main_map); diff --git a/include/assert.h b/include/assert.h index c812808f9b..4c9ea5cebb 100644 --- a/include/assert.h +++ b/include/assert.h @@ -1,6 +1,8 @@ #include #ifndef _ISOMAC +# include + /* This prints an "Assertion failed" message and aborts. In installed assert.h this is only conditionally declared, so it has to be repeated here. */ diff --git a/include/rtld-assert.h b/include/rtld-assert.h new file mode 100644 index 0000000000..c171c5ade6 --- /dev/null +++ b/include/rtld-assert.h @@ -0,0 +1,55 @@ +/* Redirection of assert inside the dynamic linker. + 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 _RTLD_ASSERT_H +#define _RTLD_ASSERT_H + +#if IS_IN (rtld) + +extern void (*__rtld_assert_fail)(const char *, const char *, unsigned int, + const char *) attribute_hidden; +extern void (*__rtld_assert_perror_fail)(int, const char *, unsigned int, + const char *) attribute_hidden; +extern void (*__rtld_libc_fatal)(const char *) attribute_hidden; + +__extern_inline _Noreturn void +__assert_fail (const char *assertion, const char *file, unsigned int line, + const char *function) +{ + __rtld_assert_fail (assertion, file, line, function); + __builtin_unreachable (); +} + +__extern_inline _Noreturn void +__assert_perror_fail (int errnum, const char *file, unsigned int line, + const char *function) +{ + __rtld_assert_perror_fail (errnum, file, line, function); + __builtin_unreachable (); +} + +__extern_inline _Noreturn void +__libc_fatal (const char *message) +{ + __rtld_libc_fatal (message); + __builtin_unreachable (); +} + +#endif + +#endif diff --git a/include/rtld-malloc.h b/include/rtld-malloc.h index 8c7cea4060..8f5f40e261 100644 --- a/include/rtld-malloc.h +++ b/include/rtld-malloc.h @@ -62,20 +62,6 @@ realloc (void *ptr, size_t size) return __rtld_realloc (ptr, size); } -/* Called after the first self-relocation to activate the minimal malloc - implementation. */ -void __rtld_malloc_init_stubs (void) attribute_hidden; - -/* Return false if the active malloc is the ld.so minimal malloc, true - if it is the full implementation from libc.so. */ -_Bool __rtld_malloc_is_complete (void) attribute_hidden; - -/* Called shortly before the final self-relocation (when RELRO - variables are still writable) to activate the real malloc - implementation. MAIN_MAP is the link map of the executable. */ -struct link_map; -void __rtld_malloc_init_real (struct link_map *main_map) attribute_hidden; - #else /* !IS_IN (rtld) */ /* This allows static/non-rtld builds to get a pointer to the diff --git a/include/stdio.h b/include/stdio.h index 88166993dd..c6b2a26ec1 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -169,6 +169,8 @@ extern int __gen_tempname (char *__tmpl, int __suffixlen, int __flags, # define __GT_DIR 1 /* create a directory */ # define __GT_NOCREATE 2 /* just find a name not currently in use */ +/* Enable rtld __libc_fatal minimal implementation. */ +# include /* Print out MESSAGE (which should end with a newline) on the error output and abort. */ extern void __libc_fatal (const char *__message) diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h index 15c4659853..6ba9adf36b 100644 --- a/sysdeps/generic/ldsodefs.h +++ b/sysdeps/generic/ldsodefs.h @@ -1436,6 +1436,22 @@ _dl_audit_objclose (struct link_map *l) } #endif /* !SHARED */ +#if IS_IN (rtld) +/* Called after the first self-relocation to activate the minimal malloc + implementation. */ +void __rtld_init_stubs (void) attribute_hidden; + +/* Return false if the active malloc is the ld.so minimal malloc, true + if it is the full implementation from libc.so. */ +_Bool __rtld_malloc_is_complete (void) attribute_hidden; + +/* Called shortly before the final self-relocation (when RELRO + variables are still writable) to activate the real malloc + implementation. MAIN_MAP is the link map of the executable. */ +struct link_map; +void __rtld_init_real (struct link_map *main_map) attribute_hidden; +#endif + #if __PTHREAD_NPTL && defined SHARED /* Recursive locking implementation for use within the dynamic loader. Used to define the __rtld_lock_lock_recursive and diff --git a/sysdeps/mach/hurd/Makefile b/sysdeps/mach/hurd/Makefile index 9c9eb86945..0c2d853a1d 100644 --- a/sysdeps/mach/hurd/Makefile +++ b/sysdeps/mach/hurd/Makefile @@ -334,3 +334,9 @@ endif ifeq ($(subdir),io) tests-unsupported += test-lfs endif + +ifeq ($(subdir),signal) +sysdep_routines += \ + raise_direct \ + # sysdep_routines +endif diff --git a/sysdeps/mach/hurd/raise_direct.c b/sysdeps/mach/hurd/raise_direct.c new file mode 100644 index 0000000000..fd693a6759 --- /dev/null +++ b/sysdeps/mach/hurd/raise_direct.c @@ -0,0 +1,29 @@ +/* Internal function to send a signal to itself. Hurd version. + 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 + . */ + +#include +#include +#include + +int +__raise_direct (int sig) +{ + /* TODO: proper implement it to work correctly on dynamic linker + startup. */ + return 0; +}