From patchwork Fri May 29 16:26:40 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 136094 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6A914BA23C9 for ; Fri, 29 May 2026 16:29:53 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by sourceware.org (Postfix) with ESMTPS id 853C24BA23ED for ; Fri, 29 May 2026 16:28:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 853C24BA23ED 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 853C24BA23ED Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::734 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072109; cv=none; b=NKfUqClDEQInd2k8A+0EOIqWW5k/K5cRVclCn6p18TdMRgePIblZjAdhvT/n7ZppRwbdetfIbaEYEFpAEKMD/B2uB5l2rol/Hom5lA5cGgu3gI6ntRBBDDEVanrKvOY5ErmsDLvZ0nfX5WEFbMDzXzlUtcTfy7ITrBdXmdS4Voo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072109; c=relaxed/simple; bh=X6KMJE46rgYQgBTzSOkXN51GI/BooovUc+nPfSrKT3w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Gjx+oMBZ76oQa2cVnHh86r7UwLLUYbesoXHHsKR+keyGOAqlOge6ETQH9ycxvOkeaPK142oGM71EmPI5FcI2MrI+zMp+IdZEYV0Hvfd7De93h8yLH4NMYM20va9VvMJc4OJNdKEmmG2S1vzB3M4/yI/553wR3WjgfPytIOI8diM= ARC-Authentication-Results: i=1; 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=qc9Ax1/W DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 853C24BA23ED 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=qc9Ax1/W Received: by mail-qk1-x734.google.com with SMTP id af79cd13be357-9153e2708aeso3200185a.0 for ; Fri, 29 May 2026 09:28:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780072107; x=1780676907; 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=x+N5FWmGCEbjdBGeeohgddaZelneea5lS6JCkWbcsdw=; b=qc9Ax1/Wu9QKB/NqJvw9KHwCf298o7nDnLvv5g182Jtnp5FZxFSSiHl9eDhndduw++ IPNc+XGmssZkp6QXvL87smMOsoebAZ4z4G7WRi8J0tZtwq0rtgXg9Q6dRdewLMgz0Ypp CwUoAF5ra9dWzk/VTM+jyjfEOH1Py0JWdQaMsQ4a98Zv0lcOzTgPWFwNPHMtmssy6nLG WInARUaHTOAytwsu1/KD0p9rpdjPnG3QPGf3AITnCZKQCoiguigboi8KPP7PVOgZpxT2 9tkYyL+i6yNVMUFOB5SdVqreNQLQvRguaQCa/h3pQ/5RWjhRtOr+sxk+8Ase3BuOiR8s aSuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780072107; x=1780676907; 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=x+N5FWmGCEbjdBGeeohgddaZelneea5lS6JCkWbcsdw=; b=r2OvZHQ37/SNFL5E2kRQ2OPFmPi4rN8hlKWYmuEQRdYj162J5xyvWzrrJU35JqEFt6 rHgVgOsBgh90EQrfIZXN/sN2O6v1hfJBtP0w19nwnavholuNBXfiBiRP+tsvUXvP8HKN uIY2txibOvKMgWdnhuSPZwWSzbBDfA5slxhJ0zhH25Xq5DBQkRIJ7jTUag9SqhCqJf+k R5jCYtWr4H8KQcITmJal72FKoHPHYOBIEoTU3GTwSG9ZcQBOMKkJIboccEUjkWEohgDb 8hJJAGG5EtbOeL52IJWaQ/YCTlC0RpGOyoR7L+zvKNbrsEudLA/BWAME3TkZiOc+UmEl ym6A== X-Gm-Message-State: AOJu0YzFF7wajvuu8qLZshPH5n7My4QT6llZy1LSyR98cRJWgMbM3Kn4 4g5U03EqvlUvlAEKgKD80Lq3Rqy66nqoGXmMR90eRUkbTWCg17/rOv2Ca3mReY/wxSwo/f2SLxy Xq6B2 X-Gm-Gg: Acq92OFKwGE//pNfsCkLPGrhKFofgz4waDsZpRgLEIc6H8AvDOH4+YZorY8nKO9Fs2D PoDHo1/dUauQz9YhRyJQxc1AyWLnMzluBeI38nGQP3vS50mASyFsVgZ1ZERdvm2AqD1YJjktmwz 5Dh/ivRznylRgByV6WtuGPZ85rtJsHhk7CmsJwHcfCo+OxUYQFQwvkJ+KBlM5T4Mn0wJGOWckoV 3efokHXut9uBoS2DCZWfQIo1/BZdbhz5Ribz3FsfZmqqO5A2GCbgOqAwf8pzqHESlXlWFZe+GZn VNtxbqPx6JERikHLFy7kDtGjCtiGSniosCctWTz9dkYvLpmYTLgf0llrSg/0MvIjnmx2VYHJ0Wj VfxtgFasG/Cx7h7YEMpJXdh52nGMwzRPqc0Z/EBQATbqhffvXKqnYsGN85WvS95ZsYV+Az52K3g 2eJ5mMoIJ1h8TIUSTrRfZSvJsE26+N63EqWuIKE9JWQPFncA== X-Received: by 2002:a05:620a:4402:b0:914:aa94:8e9 with SMTP id af79cd13be357-9153d99d55dmr69483885a.17.1780072107035; Fri, 29 May 2026 09:28:27 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:efc6:96e6:e80e:65cc:b3cd]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9153244c085sm234346985a.6.2026.05.29.09.28.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 09:28:26 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v9 1/5] nptl: Add __raise_direct Date: Fri, 29 May 2026 13:26:40 -0300 Message-ID: <20260529162818.3749464-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260529162818.3749464-1-adhemerval.zanella@linaro.org> References: <20260529162818.3749464-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, URIBL_BLOCKED shortcircuit=no 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 73f18dddd7f..099d7215146 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 221689e36a9..bc038e9824c 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 8abe8d4cad4..cf0770f1c81 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 63e7046cb3a..17f0c309a62 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 00000000000..d38bd10817a --- /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 Fri May 29 16:26:41 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 136095 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7CB524BA23F8 for ; Fri, 29 May 2026 16:30:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CB524BA23F8 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=Z4YBm3ef X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id 261D44BA23F0 for ; Fri, 29 May 2026 16:28:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 261D44BA23F0 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 261D44BA23F0 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::731 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072110; cv=none; b=wUr8b8r60Sn3nO7wY9p7+EzgPykVDts/BP3wJugHA/4aa+l/0C9/zA9hojiJSLwo+24OBOQiPYH/x2TCCaMR830ivquT/MpCpq7FZBmkFK5n/LjK44gm/t9Eibvi9pj2OcAwek9ZrHg+b1K/oTftqq3Uq7aqB/gGPn3If8h7qu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072110; c=relaxed/simple; bh=YswP5jU4NeyREkyGCgo+jwbh9t0F/xRxD5Wfw5jUMVg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MFGqEu3XsdD8KZ3me3lvTb5AKidS49fh72LvtPJDroyEvujrrPRyT0P97DlZeX/hVF2pn+XL+qQN8lG+gKhbFYinMZXvxwdQYLyGNcVLrKqAWJMGb2Z4M7kQDlw4kQNVF3R9J2pgVlaj8am8TnvL8y/+26poLtwBx9SEr8syk2s= ARC-Authentication-Results: i=1; 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=Z4YBm3ef DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 261D44BA23F0 Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-914bb8e95c2so428670385a.1 for ; Fri, 29 May 2026 09:28:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780072109; x=1780676909; 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=5wG5vFq2mSVMNZYXfA1IIENZu1kCP68OeRdV263Q+XA=; b=Z4YBm3ef1q2Mk1QA+iXCNKc6d/gH5OJmaKM1uU22UMEowewRwk09cC296V+6xfc55E BQo124ZCm7u1AEi+s7XKnUBq/xugyjbMW+TVYeiKRFQKcmC7AZXZIb4LigrJlqnNO6Cx 3hUK/gQbF7PmSzxcMb67cONo1Oa5iOX/eLQefLoYz10PvP9TEH/LgISQd8uGFYnbb2T+ mPUSXHXIdr2vcH4GCFuzcoB2MVdXyc/sBabA/B6ICBySP4qxZni+e/gTNgG1I8H1V3U0 GQkPmI4k/wcndWxuP3GRDlQvDscpB7WR0PS9aG8P1EDASbW5S4WcYgixw68Y2EB33bZk hqGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780072109; x=1780676909; 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=5wG5vFq2mSVMNZYXfA1IIENZu1kCP68OeRdV263Q+XA=; b=R98i6fDPww9VXFp49xgbJmyLZ00TBPXTbiFNfeHPMWFQkpmV73Lq6DiWPQfDYShywy dffIh+9uib80N820rdf4iFkZ/l3Oc/TnULaNJqRj0oKPgpBoJV2OHLpWglCDrSsWycbs NLC0dT0NXT8tcHtF8frCLG0uj2B+gfeSRSYW9qww9jan35bsTuTFZ06p3C/VhYnjhIRP mDr7S5jrPwQKGZgzazpDb96AmIL+p2zG5tzuUZhqWhdqLl59VC2X5Bzy/5oONo1CR8Fl 2jtSphVEpnDC+BvmEV0afAJ4jyDOtTlWyAkG0Ecy3WEtQRjDA+9LxDUTw/QIWRLEJxZ2 Z07A== X-Gm-Message-State: AOJu0YwKSYcL4Qf+8Wdnlyy3pBmUKzsqt0rj+dP8vCDHyioL5qO1pcgV sb0I8/ds8ox2cgmm/u18mhLbdqsoMGB6dXttQKqhw3P+bnWyZ4gJImPD/bB/wt0YMYDkTi1IrjI TPNai X-Gm-Gg: Acq92OFaq8YaeTyJcLeF1uWrfWEttyY6XsdKZQw3t2xEp2c24MFSXi0EHNv0reiNMHG PpuxDCsHVtrphDSCocv0HzP3g7mM3jjR6WIpkGse/4qhK9C6iS8J/5B/D/a5eyKI9PRKo+9TpO3 ijMhD0Lk+BISFviMnhk+lCjVcmcLTR4y7lzn1tOIGNInKlh+yQ+aZV88qXpnH8NQmTCHIn2NCQb R+gwoL+bN0bHqWJ92qHcqSpj8BXXjeN0Td8MoS5eoRWv3nQD8e7qkJVPkTJaCtDbC3bPjdI2ycA vtrEi7swmr7RaF7NI68exUlmjbTzc470kyhtw3EF6KmzKDJyoJ1cQwHZSSBizQt0stNLAvOnCNb NjnDjHbvVEd5LQOTBeY/nAKP7XylW7hl7JgDtwlFGAhK5yGHVeH7ZrQA5wmCHjFzThHXkOkEuMD e7jPhYZ75DeNFIKNoKMw2RKFLWkI/msuMydj7CJYyOzoQABA== X-Received: by 2002:a05:620a:8804:b0:913:e5bb:3dcb with SMTP id af79cd13be357-9153da2c45amr55103885a.50.1780072109160; Fri, 29 May 2026 09:28:29 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:efc6:96e6:e80e:65cc:b3cd]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9153244c085sm234346985a.6.2026.05.29.09.28.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 09:28:28 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v9 2/5] Use _dl_writev on __libc_message_impl Date: Fri, 29 May 2026 13:26:41 -0300 Message-ID: <20260529162818.3749464-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260529162818.3749464-1-adhemerval.zanella@linaro.org> References: <20260529162818.3749464-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_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED shortcircuit=no 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 a2359426059..024b780bf25 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 4f11315c2a7..3f0e302b5ea 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 89f69f8ab1c..ceb98a35e66 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 120cdffaf95..00000000000 --- 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 Fri May 29 16:26:42 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 136096 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C3484BA7998 for ; Fri, 29 May 2026 16:30:17 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id 5B32B4BA23E9 for ; Fri, 29 May 2026 16:28:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B32B4BA23E9 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 5B32B4BA23E9 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::72a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072112; cv=none; b=ZKAKK0KcUyIJRC/5+T7lNa5HcNRfy7SKAM0ruuKX4z9EDaxZ8e74ViR6Jy5+b67ScCU8nSkuN2D9k49AzHjQpQ7ysfa1PFH6INGvilgRerUnMd9FGekpm4zkKs3cOvZ7Th+VAmJz9zjBqFBHDYTfBOr4oBte2V6Lij+VHWP4Q20= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072112; c=relaxed/simple; bh=aAEtRUUP1+lK84J/pwPIRPhkR6b1qlCu/kLKJ5B+6Vw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Jugt2oavHxNO2Mu2C/cRrOEz5qvGPYkjmr4pqywvdYGrtAwBW/CozSSx7ZwPMGPjQFIRC6jAY5Ifef9KqANioXe8eDlioraVp1ueloJz48aO3FG9fixnEeJ7yOk7r49ARLq706p7DudPASjjeOFA6CrpnaMQTcw8iWDioKcjpFc= ARC-Authentication-Results: i=1; sourceware.org Received: by mail-qk1-x72a.google.com with SMTP id af79cd13be357-914bf8abeaeso619155985a.0 for ; Fri, 29 May 2026 09:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780072112; x=1780676912; 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=GUKkcIXopM+Kv/6v4WAoRSs4kQjDLGiAxO8cNWxBwp4=; b=Wv6SnkMPK55ASw1CRMnH2oq8mI1FROhZApOW2xU6SrmqVLtI4JyITn6ZGZcaJR0LUx ArOT5NbVaI1aMQf94vTIdlNQMIR76IiRozPVwlSOvTkglGASIIYPUmxTumUWsy5knpRr rE2mvQ+A+fmUV+LD9NLyR8EEQ/fCH58FgDiwEf+AkrMveZwQ/3pf5/h2+KuJ+zGG/vkR gWhSW8oh3ZoC3j/f2R1VTk765v5ytXPC0JT4p+gF1Xgfh4UTATKud9WltCEzCKx3rC+R qmArhzlph+zNKfEqsyLh2vj+gFDda5n/QfH36Ds1e+636c7LuOk1xZxa1ffoLeMC6zRA DPGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780072112; x=1780676912; 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=GUKkcIXopM+Kv/6v4WAoRSs4kQjDLGiAxO8cNWxBwp4=; b=M78qfH5KOjUSXndYejueEvMDmdeP3+5muUmd8lBkbHv3OflDDoxHTJnYq2D8gARzMP 5TLD7/h8tOBSb/q8tKMFrSrriaiIcsMk+suo1VbTIdCSLTyuTzYJ/VhtwxuhvqpvGpL3 kfHWHRz6yA3a17ejK/5oP56ArIdrswxegD6FYcGTVvW7M8ojQDeMGHCMFAVCaypa9Hd9 28gaw6mDAr6XO2g1P97OLwQ3Pu8EROTYNomzM68y6hpZlJy6VF9UvnUyGAzErCjZLQ+b dWPADTAQ++5uT538dYAwzR65d1MMsqA7CkGZhibLXDxEgudHyaBsaFGLNHEf3KUFZu8m QUDA== X-Gm-Message-State: AOJu0Yysdu67uI7fJe8pSKvpj79CJIWFJmJI/KkdkBwU/b4SKidhLktx JRaFLGyF+Z5k0L2BGpUrkvQBwH1h2h4I8xCbvL2YPYNilXuFRai5rta29F1rM76mZoEqWYfMHjh bqtO/ X-Gm-Gg: Acq92OGo6li7tMn/CI1k4Y64hpn41wxOww4NGYEitvAYQ+vi7HfeAVroZefI+zHbbke 0aGy26WOLS6vvyeRVXiBaxjyPvBya+6ZzVHW1yRWD/MviyHTk+hbcMwKmfn/Ve8HH6GRUEx/87m TNqC9VPbhiE464kDzzvWte+EZRjcymkInsbOdoClF4p/S5CMr36ZLOiNPKofiSt2KzC1+L57vX8 u6q9ZpnNCjNNBspM0VX1GlFaGetYDBP4Ak3fkqYL+ZTGwao5K8dgwNu1IXeFs606eV2wlM2py7p AzMf3FbrVYy+MANTEAL315leHJG4cba3tJQMDToznefKBMDBJ3cLRgZbRqNWIg4WVeoGEAkq4mY xlqm7M4cKE8g/3P0Sb8YK1M3pW8VXtCufGLCatytNH3xk4CxbirzITzvgAeeN4mkRv7946ADRpE t4cyxM7x9wnqediuzwV0f70kFJj4xUHCnaS68+Ij0IAITNWw== X-Received: by 2002:a05:620a:371b:b0:915:3d27:a816 with SMTP id af79cd13be357-9153da3ce1fmr59953785a.49.1780072111255; Fri, 29 May 2026 09:28:31 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:efc6:96e6:e80e:65cc:b3cd]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9153244c085sm234346985a.6.2026.05.29.09.28.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 09:28:30 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v9 3/5] Fix assert during static startup (BZ 33326) Date: Fri, 29 May 2026 13:26:42 -0300 Message-ID: <20260529162818.3749464-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260529162818.3749464-1-adhemerval.zanella@linaro.org> References: <20260529162818.3749464-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_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED shortcircuit=no 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 startup 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 | 18 +++++++++ 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 + 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 | 8 ++++ .../x86_64/multiarch/dl-symbol-redir-ifunc.h | 22 ++++++++++ 30 files changed, 414 insertions(+), 8 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 4c253a344ae..541929c3b67 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 a58a902451c..0fed0f270fc 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -278,6 +278,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 \ @@ -296,6 +297,12 @@ tests-static-internal += \ # tests-static-internal endif +ifeq (yes,$(run-built-tests)) +tests-special += \ + $(objpfx)tst-assert-startup-static.out \ + # tests-special +endif + CRT-tst-tls1-static-non-pie := $(csu-objpfx)crt1.o tst-tls1-static-non-pie-no-pie = yes CRT-tst-ifunc-resolver-protector-static-non-pie := $(csu-objpfx)crt1.o @@ -3670,3 +3677,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 00000000000..9fd79a0e243 --- /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 __[]assert[_fail], and __libc_assert_fail does not perform the + translation (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 616107ee105..09b1b907dc2 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -195,6 +195,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 addf7dc99ff..18c8b21910d 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -530,6 +530,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 aa0b0c2f57a..969726cccb0 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 26fcd1977ea..ddfd6bd45d8 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"); #ifndef SHARED diff --git a/sysdeps/aarch64/multiarch/memcpy_generic.S b/sysdeps/aarch64/multiarch/memcpy_generic.S index c6d09081f47..d6222683056 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 00000000000..4a6c81aa8dc --- /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 00000000000..f786be0930c --- /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 1cd204c2f69..4379770c314 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"); asm ("memcpy = __memcpy_unaligned"); asm ("memmove = __memmove_unaligned"); diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index 3f0e302b5ea..1ff20d4feb7 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 3a49b855ca5..60ba2e50d28 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 00000000000..560f57366b2 --- /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 4680092cd8e..03f6f12032a 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 c9178223a87..0437a05a895 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/s390/Makefile b/sysdeps/s390/Makefile index 481e8347925..01e4a4344fd 100644 --- a/sysdeps/s390/Makefile +++ b/sysdeps/s390/Makefile @@ -258,6 +258,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 += \ wcpcpy \ diff --git a/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h index a128cd05bd2..3721f3d95bb 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 00000000000..f660d019c77 --- /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 ffe1eee87d5..1a76efd5425 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 ffe1eee87d5..1a76efd5425 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 17f0c309a62..abf0972dfb2 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 f1f8c3f44cf..9a70905df84 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 00000000000..ab6f96300fb --- /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 00000000000..291f92ee14f --- /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 00000000000..ef6a6a20b82 --- /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 8327d32374e..d92c74d7126 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 00000000000..b23b8e5386f --- /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 2fdd4af3eb7..a10dd30d12b 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -24,8 +24,16 @@ sysdep_routines += \ strncmp-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-strlen-generic.c += $(no-stack-protector) CFLAGS-memset-generic.c += $(no-stack-protector) CFLAGS-memcpy-generic.c += $(no-stack-protector) endif diff --git a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h index 1f3ca20307c..4d9cc5dd914 100644 --- a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h @@ -73,6 +73,28 @@ asm ("memmove = " HAVE_MEMMOVE_IFUNC_GENERIC); asm ("mempcpy = " HAVE_MEMPCPY_IFUNC_GENERIC); 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 Fri May 29 16:26:43 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 136093 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2BBD04BA79A3 for ; Fri, 29 May 2026 16:29:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BBD04BA79A3 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=d0td2MAF X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72c.google.com (mail-qk1-x72c.google.com [IPv6:2607:f8b0:4864:20::72c]) by sourceware.org (Postfix) with ESMTPS id 65F184BA23DD for ; Fri, 29 May 2026 16:28:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 65F184BA23DD 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 65F184BA23DD Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::72c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072114; cv=none; b=XV3GyYzqeVIRNowmO24KNvuaFY0io9DLmei0Ebys3fPvsdQ8GnpC8Xl1c4J0B532L3t/vLZIhcoKZVufTJTxdBaIqyG+AsxAMLHGnKKoIBm/8es/bwnxGQyTugd9WPv3KFjHZi+WJ9ZI+xC/D++Sh+NkJXB1HOAkdEtdgZE/TUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072114; c=relaxed/simple; bh=jjWCZ5S1Eh1p7kp2ZgAa6DGGXXBnNV6dyrPmpUekjPI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=u7L17bSSXSi/mcpYKX95f8NvqjU7ppr9WbG1Lnn8PE/RkTQ2Z2Yj57aqPiEin8hJqojDYX4Ae9zte1VMoFzgYhL2fZpFcOPLKLVbA+AgbzAxPoWee09XsqKEO7XYFFF5J/EuOonLmH+IOvN93MB8ailJ9W+IZJBEsmW3onXqDYU= ARC-Authentication-Results: i=1; sourceware.org Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-914db83362aso609228085a.1 for ; Fri, 29 May 2026 09:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780072114; x=1780676914; 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=RPOC7Eej/IJ6CcbS2IRu1PgdX4eKiE32cUFrVRWzJUE=; b=d0td2MAFooYK2CtQwnr5YL+u419Q7/t/fJ2+hGENqYl3tL9seMbbpqK7IOHuCIVm33 Dzpwv080/2Q5QQjqHyAN0C/ngZXg/i6NSJoGMWCNX1aVdvLzUpN/lMZKAiSPGoBheVtS khp5mahkI4RCc+iL7ghOwcr8W5aT8vw9UIpLSPtQqKPpGB3kO0WNYbE9oxQ+LNGKphfD 3Kn7Z38I5ZWnrgrsQ8bR29j+YGdxydvtJ4Yt+X4VS978rO66l2BVLtalBugrEFfks5Xg ZIAaKM2zK+GK/Exx5QpA0n9ll43xyQTtehD46sY3OIwuPOzFo4lJu4mkXA9IxZgG5Dg5 gGIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780072114; x=1780676914; 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=RPOC7Eej/IJ6CcbS2IRu1PgdX4eKiE32cUFrVRWzJUE=; b=K6v8EdeR9x6JPwPUBBokAHmbsi6WrLEr/CUl+sZHPOgWGh6r6dseXc4iijxIMnE4wx zpidXzMR4LVlVtndNGAZIXpVizig1P2INjZQqSdF8I42iN39/dT4NoZ7yKPEzU/mtbwu TznLCK9jP5uN4cQLg799YVF8Rnw0DKrxxb9AfmIs99CUDjLKPz3j15OcFTl1hOnjtrnu 772MnCpydCx8pG8//Eh336DcatjvH8AOe1dDk+EchZcBfl+5LV/VETnDexCufa7o7fnc /XhWjuvOA55dhLtsDWS7Uii3eU8ULcR2RCQN2F5Xpa3LtGNjLqGotP0wm8CnBu03jmRp CehA== X-Gm-Message-State: AOJu0YzIIEzH+WM171PeatNJs/ONHemdfMYYYzIKQT/R9Cmbi/l6cC2n 6cIVtA0KMev/C7titP81R+ddPn6ivkfok4h20dR87aMeelj5uTjy3mvKID1wsdq1gfY4Yz8vGD5 a/ps2 X-Gm-Gg: Acq92OGp2m5JzTVTIIvwgvSSplzD/huJLDDhB8qp5Mp0CnZnxl0YAqEWqXTuwPGxnnQ G7EQvTTNlRoTHkGEzAaPlUfESCNUXNGddqlvfnwLdnyVSX3UvzzSxPgmaws+MnByRDU9411N4Dm b9YXWsPaKI8fxWg7cSYVmlr93JJYMaO5r+fM7Ey18fLrL2KePOSh8sJY7G5dQHaK/zSew/3c0Jr KQn1Xhf0KJ/Drh/gD8uJgPorirY9tJeWNkwhI4WUuvduywBFp80rJS8V4hV/jzvqK/X4cpjlGUO ggveEyDa/GK//fapQXz1L/bMEC4XOOT6hUnQuSR2GlFYPEd848zuh9I66WFZ1XOMxEu3/OwLiG1 kkk4HB77AAJoETKGYIW/EtXt4gLe3LOWDLEPVHIGVQdEed3HtBwJZGca1lxTmnkzBJ/Ik0uOJqo dkbTKuBM+kbyxOB6xKk0i5muh3aGTATSu0K0Hi4kzP8+7R6CSGMHFIuwt+ X-Received: by 2002:a05:620a:2808:b0:8cd:c152:ee6b with SMTP id af79cd13be357-9153df45552mr27758885a.8.1780072113654; Fri, 29 May 2026 09:28:33 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:efc6:96e6:e80e:65cc:b3cd]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9153244c085sm234346985a.6.2026.05.29.09.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 09:28:32 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v9 4/5] elf: Allow RPATH/RUNPATH for static-pie (BZ 33326) Date: Fri, 29 May 2026 13:26:43 -0300 Message-ID: <20260529162818.3749464-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260529162818.3749464-1-adhemerval.zanella@linaro.org> References: <20260529162818.3749464-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED shortcircuit=no 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 0fed0f270fc..227d7897a2c 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1236,7 +1236,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 @@ -3688,3 +3692,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 95404adae94..586af946112 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1319,7 +1319,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 8463e46147d..ad47b9aef61 100644 --- a/elf/dl-reloc-static-pie.c +++ b/elf/dl-reloc-static-pie.c @@ -72,7 +72,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 46faa34acf4..9591d00d592 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 12e1b4dd71f..a5ae804afe8 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; @@ -1702,7 +1702,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 0dba7072d53..58b77120468 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 00000000000..719eb41e091 --- /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 00000000000..02fb05d2e6c --- /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 Fri May 29 16:26:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 136097 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ABFB84BA23E9 for ; Fri, 29 May 2026 16:31:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABFB84BA23E9 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=Nzxg8qPl X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by sourceware.org (Postfix) with ESMTPS id 6EDB34BA23CE for ; Fri, 29 May 2026 16:28:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6EDB34BA23CE 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 6EDB34BA23CE Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::736 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072116; cv=none; b=m1S9ay5kWDHdSMN0wmC3lTYKmcdSgSY+PXJuQuJK7QFeXl51Ks6cbJ/8Wtu2o2DIQiF7CE3LAGQcukNiofv9yHDdw8vO1Amv6wMdQKp0h7sc/w3JxL6AXnbErydgya1NrAAwRYwQmYD0QbcIBgo5sGQ5Jy3TtS+ZqkZXp9T5DlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780072116; c=relaxed/simple; bh=lsjZRQ8+t/+sGiAlU1g6v0yAkO5wx23UG7idPJ7UvFE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KnPu1tBCx/JazxBt7FYeACUUmHaLJ4Gt92yq9MOLZQwfZRSpYDAeLqzE6+Ww4Jj5ZTtIBmwvxQ16E/iQZHJkZMn6XXzTtZ5ZZX3FqNoAI/6aAOsCL7HhAoy2gw442krOfrMc6gmHK2niJ2O4b5HfjKBtuSAYPIE0RNYPOOG03xU= ARC-Authentication-Results: i=1; sourceware.org Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-914bfa75911so834365885a.1 for ; Fri, 29 May 2026 09:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780072116; x=1780676916; 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=A3HhzwZfK3W+MpT7jh5QH3w+mwyHEqabMmmAZlBF5Gc=; b=Nzxg8qPlZSrMfJt2/+0ON/Z9KqeDmgD5Q3ztt7SoFgBLLI0Vg1Wv/lLtUvp/Vu/WCf NF0rZ1ENONl4N2kUs1yITdYK8mzDd/aVRUZVbk1uxtbHg284IWueGgSoerGwWJk+NXhf zl8KY5DHfnjkQdE2QTXOFStZQhHDvxiQu9r/xnjMULtgn/1Ih0oAoHy315zxLVmuFxth VTPvVJ4RKJVhq6k6vOSnP1VPMiDaVVoqSedR3poWX25a1uq8bb3UghyqSKEdCmm6TfqJ z8cIMA4CVo1+H7wBiFtkSy4LCl6n+faVkSuqlvUB/A8zwBJrku9vzTEwuvu54JMEyXPv eSnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780072116; x=1780676916; 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=A3HhzwZfK3W+MpT7jh5QH3w+mwyHEqabMmmAZlBF5Gc=; b=RvHbZafpZGTrRQJDwDNawQMIGWaZchYdXbiEQzYEyp8rXE7kb6ZbAbvkinvECtnbr+ uVkEYJY+mJhtJfL2mS+TYZiju6bNIMhGjiU+QStBr7yXqAzaEDjuM8l4Jj5xJ4d97vDS FiXCCMMExfr9maspgRQV49S+Qa/kQh3+rg2qJ7c8RA5NRTXnV8kxUe+f5kM/fEVOrMej RkxQEPdCMkF0d7l7bRiKygF+9BsXJi8FPHEhW1qUCAK7A2H42rFS8c9AT8RpSwPyhM/n TyaDph+ojxfNmmpJ783uICwfFlaF5NaolvnsZ4/bu2To8o1ckYDS7imuC7adpMsi6Fp2 Xmcw== X-Gm-Message-State: AOJu0Yxjo72j4YC23ZHvH4U439P1Gqchd+ULw1bJLbt/5AbStY4JDGKs 9mjXU3rVhurg/fN6ZiCSsNBkssm8VWwarVPdQtvgk/gD1gTJeUo4CD40zxhtaaiK0P/OEoW1W24 2vNh1 X-Gm-Gg: Acq92OHj9fziOP4CxytcAVfyqgQPrMrJc+hg4MYUJ/RjYdhJXckwz1Bx2fF0r3qMSxA IZf+xkdVTvFWxUByfjZYeqY5zrmDsUzhUDqmkkQV/KPKwUlUnthv9yXCnAyOxO6EkO/C3BsPyAd tPPksWeNydSwyaZpmEB0BKCNzWC+hNk85ksKidii0M18kpnpan/9NZgkPBZJBwvCn4NJPIvnxJ9 r1X6R5JTt+RpWJDed1hIaIFFXT76evSaLu6CCHqr2VfcfLp/H0enp/0qqJxBaZtpkBI5GHrAs1m ojpwEnPVp6mIl8CZbEyCR4DxSBj894gGLbVR1+aoITIlbifZmRqrBtZNuF3LeMLcFQw4ji7Wb7M ZHsyHfM3OGLefYMm7pW38DLD96RE9K9uiPK2c2nM2mIWEcDOmb/0wPQwot+QjPBWUVBW9Ml28wC pESGHRUK2w2HjUsPxLjP1miX3ER846JSghfrXilODVO4D3AQ== X-Received: by 2002:a05:620a:28c6:b0:8d8:697:1cf2 with SMTP id af79cd13be357-9152fa02ce7mr418728885a.30.1780072115528; Fri, 29 May 2026 09:28:35 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:efc6:96e6:e80e:65cc:b3cd]) by smtp.gmail.com with ESMTPSA id af79cd13be357-9153244c085sm234346985a.6.2026.05.29.09.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2026 09:28:35 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v9 5/5] elf: Remove __chk_fail from dl-minimal.c Date: Fri, 29 May 2026 13:26:44 -0300 Message-ID: <20260529162818.3749464-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260529162818.3749464-1-adhemerval.zanella@linaro.org> References: <20260529162818.3749464-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED shortcircuit=no 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 227d7897a2c..063a1305a02 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1563,6 +1563,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 591d49e3f52..4583c48db3f 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 a676f75f625..33d0a47f431 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