From patchwork Tue Jun 23 12:47:42 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: 137634 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 459BC4BA798D for ; Tue, 23 Jun 2026 12:49:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 459BC4BA798D 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=Zxhciswt X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1232.google.com (mail-dl1-x1232.google.com [IPv6:2607:f8b0:4864:20::1232]) by sourceware.org (Postfix) with ESMTPS id C5C004BA2E2A for ; Tue, 23 Jun 2026 12:48:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C5C004BA2E2A 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 C5C004BA2E2A Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1232 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218917; cv=none; b=OzRMmgBJZEk71DXeJngajmd4ZJBJCQhjOrtrVKJrfoXDOywy5pGy8lcHM40FS6yLNjVGzSXeoaYsdSIdwePZp6PD+2jdjLb+U3IT98fad86NeUwK5I6fhxXtDpsOlr8euRXUMTQaJMLPCg1QstuBNP/Vp/1OXQw0hAZR929LoJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218917; c=relaxed/simple; bh=SyZ2zDOketYtpMiiA32zWC2oubF4VgVzpiRxk63k5do=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=hEdKpl0mTKhSmQSm47ru2mfOSf5xzk+u2Szs7mlE0m2XbmCgZ9ontfwYzlJpVAEu0SZ+J2FzQhJs9apenSaRbEupE1bhBRyaU02dF1QlN9jUFQ/QHoFCC7xw0UsZqAn4GXRDKfIM6Dhnif70XkN+3AttoNqx9brqON8aGsCozsg= 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=Zxhciswt DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C5C004BA2E2A Received: by mail-dl1-x1232.google.com with SMTP id a92af1059eb24-139a71baa35so9221121c88.0 for ; Tue, 23 Jun 2026 05:48:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782218917; x=1782823717; 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=WTX2e9yg9actFMk6XuJ9vEmo66cTr5pSRt5HJGKPSOA=; b=ZxhciswtKjo8wQjupCQ7sLrDRxy/vwtaF7r9J2n0/ReqTCspuKzs2wD9azvhqkO8t0 BajUyAeAcshnSjVnX3tcB3BxsBvHA7kmpD5hHbQaSF3lALpbeWqWF+lEN3xp/rtjQgFq kW1g1+wZyxqCM0pB4KJfmY1iEuIS5EHk7gh+b2DszsGOnMTyzgofyCHT/Xp5M//wdiKN fGEdto9/WyCld9MGwmaKLasqwBGLdSKQMvAwRC/l/D6tk067Rrfr/KkhDf/hkUgE0agC 1o+cfCFNiG9Sk7X7bJ/xFbk4OuT3au3IGfT8jTwSBNGfpAa5pQU2XrqbTGZ8ekpH8BFJ NQjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782218917; x=1782823717; 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=WTX2e9yg9actFMk6XuJ9vEmo66cTr5pSRt5HJGKPSOA=; b=p3Zjd5YR9PRiuw6KshLB9fZmZ/dpOnrTB/su3p/HmJLUR5rxdESb9xfeybpOw0Xf4Z 0ALUX1tPCVjhQXRmkKqdJOJEQ+32oUyrgXDbPiCBpVuGTYuYnh9cQpVL5wPOT05MsCOh OalnLL4yJL/aS89FF8LJSdPRSTibVjBp7cPQWFLE3LaoA3h3hTr/yptoBv75TbdamcjJ 4UjCLbCaTJyWoX+LWetfpW53C2idOizi0uEjwIJ5f+oRniVACICgslSm6zi1nL6ZiAFH a6AsDic+b5OGXGLkzW2RRewVqQX1iULN9RpXKNIWFMaqCOtjEcWgeONgV74lNdmdaKgZ cIZw== X-Gm-Message-State: AOJu0YwbffxUnBFJ2TIO9JLlvnJaR+7KptZCEqvZJMUlvl5LbFZSn74A ayJN3Lgz9DfExwQK9sOGYQ4G3a2C0S0pGqWIE2+6GkYCD9qAtF/9vOWOpS/5Ldyzvfk1n+fS+En 8JEnI X-Gm-Gg: AfdE7cl52MXiY8RAjVKub/1nW+4Yi81Ew5gMLqAPBy8cn/StyVPisBsAVv36bRGTTAG 5MPUQhtK9lqzrObsGeVNW9AswbQwwfwSQusNbpcwIi9r2g+1vU3J4ROXM/YRT/+3PrzgpTxE1Nn LkWRi8GbWHnHvMMLZhFL2tyN5B3mw7As1zy7OrXna+8f0M5JTa2uKFVLHqR4TvAONFGpsY7nFuf nh3DD2gMEL/cOyo1gmDCS+PHVlHrWWzQ4wmsC4ReK2nH7iUG7k6KXm/2YzGub8Jmw579S9DaVRj bGfnoC/KLvBmHKTbxoQ36jM0Qd0B+cXfyAYl+GiRCbbCE9E9nWZgsJ/ogXs0/S3iK49Khjpt5Rs YOq+DnIUbcP7r7Y0Vk9eP8ISs+eKFF0Td8CbnDvMWkkcrsc5gewoPIi/EG5kQ5mHylV2UnuWije eIwCWfSiecQVriJeLNvbfeRVif X-Received: by 2002:a05:7022:7a6:b0:139:cca6:54e1 with SMTP id a92af1059eb24-139cca65507mr309877c88.8.1782218916377; Tue, 23 Jun 2026 05:48:36 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d170:82d3:e54e:278a:ac84]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-139adca1b18sm12183777c88.3.2026.06.23.05.48.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 05:48:35 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v10 1/5] nptl: Add __raise_direct Date: Tue, 23 Jun 2026 09:47:42 -0300 Message-ID: <20260623124831.2165041-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260623124831.2165041-1-adhemerval.zanella@linaro.org> References: <20260623124831.2165041-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_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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. --- 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 a048dbc7323..5b11fd105fd 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 Tue Jun 23 12:47:43 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: 137633 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 2D1B84BA2E13 for ; Tue, 23 Jun 2026 12:49:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D1B84BA2E13 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=mlSCIi69 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1234.google.com (mail-dl1-x1234.google.com [IPv6:2607:f8b0:4864:20::1234]) by sourceware.org (Postfix) with ESMTPS id 66E6A4BA23C2 for ; Tue, 23 Jun 2026 12:48:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66E6A4BA23C2 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 66E6A4BA23C2 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1234 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218920; cv=none; b=YRNMfo8od/7ix23aecVPZPonsddtV9jWQi6O7ikfmYAgb0MjwzmgH1oSaKoKq8ZhV1VEM6vmSMAztKQMjx+jv9x+Px0lNc2fVIJuZm7W8r3IEoBEANq9QLXSelrZ9TGO2HeDDLXg78faQPL3yG9IQxkD0cq73iixGyyX7LVnMoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218920; c=relaxed/simple; bh=2BGnApCh370oQtrwcTR/Rq0zmb2q5Z6FG6b/q5smIrU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nZQEsmXfyX9EvvScPxunkbzq6d8pr0UCsDg69wDyb4AMLB4jXkTWyIU8FDyEM4ba/wxIOTE58WnvPdjWMd/qbAZJ+Ku9M9qZiNNs/Qaycq88NIJHLzAa5z5Gg06ICmM1g2K3ReLjzM17P5N8J2/kbyADoOKBCYWDTciyNpcoFmU= 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=mlSCIi69 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66E6A4BA23C2 Received: by mail-dl1-x1234.google.com with SMTP id a92af1059eb24-139cc9b208aso175821c88.0 for ; Tue, 23 Jun 2026 05:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782218919; x=1782823719; 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=t6jBoOv71GQfUsgQfTkYl10ba3lVOgJr9i4OSKn40YA=; b=mlSCIi69WPjzAk170o1tJpN5MaBHIBpAVrQ5lN3ZDOXR+oY4JQPnEk5gZOrdQ/tq0o HisoQeF07fKeS16cQip0pJ/6ydqv49VqIcSsCR5+4Qh8OhAx/8Rj07EtH4lB6mPzyTIM GPKxwSc1BGGv5uiqavY9WDwTw0vRgShqleJ4KM9URJvv0QH8MLMCMsB0YdDTb1VdqF8Y thKHrMIkX3FjOnmVPyKr8j1CZahAuF09rtjnIhZ+/yVYDUcd6Zi6pBM3MAO257x+pRxl QprCcgJnl9otIpij+1SkKfxAQQpvpgH9bCJyplh1p7OtpNEMtfyfFqxHl9r3HBsvzauy k+1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782218919; x=1782823719; 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=t6jBoOv71GQfUsgQfTkYl10ba3lVOgJr9i4OSKn40YA=; b=KGYpIDr2XicGeG9mv6UGlaKg4b6E9P4JSHmhOFUJHD37ncsPv0JH9lGaJc+D0lCSXq 9ux2Kggdku/rxoEgS4b/FzXxOjbsQijmtq1eTjHtodj0ep0KR9CAPTmjO/7/bZ+IzLuz m5mpR20RiqNzimNqw1yWSeqcS7UJqjLHavOySmJ+y5gvfExNOvAVADAU+D21K5hQFb/a tUcXi2l/DLP52H54aoZC0ws/5Q+aRSvTtw1RDH7oAGoA+wnJ6NEK7sdZCB17Xys6AZCi FwnnTELa4NRKRdRRcxhWxvpE/rexgkO2x4UFWfdjUj4tf1LksfZbwrgZxg1gagJS5tyA TbqA== X-Gm-Message-State: AOJu0YzCNCOY97zFgJHy0+9quy/jaEJHmYCQDLbbTxxYe64IOLtwlfAl Za342J69nMwoql/Tu8hjm1eI8Q96wEswW+NKNaS5YfFsqOAKkygyJj2MnpFI6ER8kS2mN0fPXT7 XkyxM X-Gm-Gg: AfdE7ckLGchfVm4kBTNjPjic1mbkMNO6+BrdFkbIEclEzSKLs5ZgMnGmTbHM1tEdI9u P2QHMFN3U1yI+eWnBBm9Qj9izo/iAiF8c4HasQnoNhGDxCQVQ9IgvkqN5CR6wInQjDW0ZaxFwRj sXWNUvijnkAnCJ8z5wOwyS+jHIuC08DC7JP80oMw/WkoXVg/TPLexhdeN+7I54b2PzFMxjgW7j+ 0MfgEBu7YTctJwnZ5hCgpXBINV6WcV2X84oMUPAgn1EwU0XUJ8RUaS1Y5EMvYiqxiQeJ7PdBXg+ xLk9muuMqofkiAHqqXzF/BiBh51p35AVK07U+fz/BloqwU7oeexo0eaUoFsJRq0Q04E/8axNf3C JIrIoQna15FJywB1bnH5SBVnHhS5fgWkwaTyesob+c+suQ+8fMV4Sq/m/BeZ4zL5CXqpxaC+zCT x099JpIDmBEoBrN7E4WXpOycN+ X-Received: by 2002:a05:7022:20d:b0:139:7bac:db41 with SMTP id a92af1059eb24-139c705bb41mr1572516c88.28.1782218919093; Tue, 23 Jun 2026 05:48:39 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d170:82d3:e54e:278a:ac84]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-139adca1b18sm12183777c88.3.2026.06.23.05.48.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 05:48:38 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v10 2/5] Use _dl_writev on __libc_message_impl Date: Tue, 23 Jun 2026 09:47:43 -0300 Message-ID: <20260623124831.2165041-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260623124831.2165041-1-adhemerval.zanella@linaro.org> References: <20260623124831.2165041-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 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_NONE, TXREP 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..613384fac6b 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 Tue Jun 23 12:47:44 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: 137636 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 60B784BA2E27 for ; Tue, 23 Jun 2026 12:50:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 60B784BA2E27 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=oYtC5Hd7 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1234.google.com (mail-dl1-x1234.google.com [IPv6:2607:f8b0:4864:20::1234]) by sourceware.org (Postfix) with ESMTPS id 977EA4BA2E1E for ; Tue, 23 Jun 2026 12:48:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 977EA4BA2E1E 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 977EA4BA2E1E Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1234 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218922; cv=none; b=CiXsY3ePlwdJ4gc6ABeIvbWM0R99c3Iqg4qeDL/IiTNdD+0UuuSizLZtpTWtkwbGl9IxTyrE0SBTdVHS7XZ9ygGPJgDKx9c3OoH+lupf9PRH9OYF928rKB6rbYEQ+LAPpJK0Bi3a3aXIF6TGj9dSgo8tzwE+9LTRGNg10t9fl+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218922; c=relaxed/simple; bh=7He/N7TwavbJF5ejRUpVZCgrczGMYH+kg3EcXU9OZTo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Ubua3n97JI5ZN4HQKH5FzuJ06OlD4ubCMEquZo9rMzBeOsobtlwn0bVekyHYwuJlX5eUY9sRFwmKPRCYCOXYJ5is2PW7VWayJZf9af1T9uB+8ksuOHVrH4tcTENqfKxIdZZv/bnzfesfjF3bBm4MAm8U5JLJq6mgnnQVZLZt6Ik= 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=oYtC5Hd7 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 977EA4BA2E1E Received: by mail-dl1-x1234.google.com with SMTP id a92af1059eb24-1390f75d8bbso5903509c88.0 for ; Tue, 23 Jun 2026 05:48:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782218922; x=1782823722; 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=2fhRcjHq/94/SI8WbLcZrBnePTXocZKPHm/a0a2GBd4=; b=oYtC5Hd7AmicYGLiJPFlEKVLELTgoInr5jgWQIx5IGSw3g/t6wIg43E6YbAwELANBm F8yXKGNe1oLR1ivdpINYBypAJkcC5mftbVmyE7JUHsDtqIZDUaJJGacZojuYxS+fzbDB VA8umWMC4M9p0XbY3mFmgxzSyAA9asA54zM7FJiAEHtKC1Ya/6/rJd1fKj8gPhBZ6Xue 3wWR1yo0R7JWe9T0FPgKydDmj2gKeMn30T1VxMl7QPFq/Jk9NUOn43VYU49NQEXfsFgm uAhCa/TykGlzmSTJaRGSG47+lmK7W2WKrV/inWu7XRKV0M8+3PGFTGoVmyr4/XHNP1Sy 8CPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782218922; x=1782823722; 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=2fhRcjHq/94/SI8WbLcZrBnePTXocZKPHm/a0a2GBd4=; b=AevRywV0c1vSvl+MGdM4Rl71wyJy79LmagQ8DTJobAzOOimEe7Fl/LjyGCwuqDfpxJ rEgYo3QKJzFaZV5chIguGJ9OFxInWwLCJEBo4RpyLVPsoOPU74G89utQWNLP3U7756N8 afowDHFCnjK30LSfoAkQkgBUFONbNXpNz3EMWPwgWpDxrl7JlX43QTRhKETOYjl7hqY8 nadJxIEYkBbKS8nPCTlahhBmLJ9JggNhbOdL7QAYUgkKmVDKVt5t6v9BjsfIkQwh6k43 Elg63o9pzymx5kfGZWgErQtZzNnY/ZJtCv5bVjNco2C7n6fOnyASnQgStbEoowRJIMon tphQ== X-Gm-Message-State: AOJu0YyDRahrCUvVM3YmuQ5K1qgZlyshMc2Br+iH8vq2RILIa5Zzolo7 y3jc5yUAJ02dFFwi5TcKlFLzHaTQx+uU02kOz45tPjqfiHQr6jpsGXA2Ee+qpPPq+IIxikdAwQW V67s1 X-Gm-Gg: AfdE7cmgMpbB1ObNZSIiOrdokp8NanyrbeqHG4tp/JdghrPVIgsazuyx8Dk70sbnEW6 PRjx7bzr1DWi/yFeI477K+pdO8YNS0yOy3hl0bOzgdpgYghwp8yeRt1lY0kjsH0YjbSBjCZDyoH Bd59Nr4wXk2N68qKtH5y7jl+DAXd3fMeLLtvK8Oo+cEEamm4k8jm8McoZPvnwjyrWNJwGGnZe0d f4MYLXHbFT/BxBUPaW3qFmNkLDpYPFJscO4TxUZpM4X+E2VK+76OmxDY5B59EY8db2VX0konDDI G2M8ZjljipJ4RbbEVkT1qxV/+a2D7e2k6h3zVny/+ZCzzsSIvDl5fJnlb1wqae6FkHCs8tbh0ZG 1+wrhlDWJb79f+q7q2sxWtUApbRcX7bj8YeHVxcRC7be8d5OmKtuLjZurqlnqpmbLTgBUOKmLXJ N5r7mudsu3bii2Jff4IUWdrIHO X-Received: by 2002:a05:7022:419c:b0:12d:b7e5:a691 with SMTP id a92af1059eb24-139c5cdacaamr1855163c88.7.1782218920870; Tue, 23 Jun 2026 05:48:40 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d170:82d3:e54e:278a:ac84]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-139adca1b18sm12183777c88.3.2026.06.23.05.48.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 05:48:40 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v10 3/5] Fix assert during static startup (BZ 33326) Date: Tue, 23 Jun 2026 09:47:44 -0300 Message-ID: <20260623124831.2165041-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260623124831.2165041-1-adhemerval.zanella@linaro.org> References: <20260623124831.2165041-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_NONE, TXREP 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 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 | 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 ++ sysdeps/generic/dl-mmap.h | 34 ++++++++++++++++ .../lp64/multiarch/dl-symbol-redir-ifunc.h | 1 + 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 | 35 ++++++++++++++++ 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 | 12 ++++-- .../x86_64/multiarch/dl-symbol-redir-ifunc.h | 21 ++++++++++ 29 files changed, 385 insertions(+), 11 deletions(-) create mode 100644 elf/tst-assert-startup-static.c 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 65144282941..ae75301a986 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -279,6 +279,7 @@ tests-static-normal := \ # tests-static-normal tests-static-internal := \ + tst-assert-startup-static \ tst-atrandom-scrub-static \ tst-dl-printf-static \ tst-dl_find_object-static \ @@ -298,6 +299,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 @@ -3705,3 +3712,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..66bc5d4913b --- /dev/null +++ b/elf/tst-assert-startup-static.c @@ -0,0 +1,40 @@ +/* Check if assert works 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 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 0910e321d24..38b8bcadcb9 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/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..d2c875533a5 100644 --- a/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h @@ -22,6 +22,7 @@ #ifndef SHARED 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..75bd82eab37 --- /dev/null +++ b/sysdeps/powerpc/powerpc64/be/multiarch/dl-symbol-redir-ifunc.h @@ -0,0 +1,27 @@ +/* Symbol redirection 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 164aac9dca2..9c9b90b08eb 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..5527bcbe454 --- /dev/null +++ b/sysdeps/s390/string-bitops.h @@ -0,0 +1,27 @@ +/* Zero byte detection, define whether to use stdbit.h s390 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 + . */ + +/* 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 additional 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 5b11fd105fd..2376538840e 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..cd8f7ffaa68 --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/dl-mmap.c @@ -0,0 +1,35 @@ +/* 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 cannot 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..27b1ca6cee1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/dl-mmap.h @@ -0,0 +1,27 @@ +/* mmap wrapper for dynamic loader. 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 + . */ + +#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..375ed80b58d --- /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 cannot 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 929df14a6f1..efe350cf8f4 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -42,8 +42,14 @@ sysdep_routines += \ strrchr-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-strlen-generic.o = $(no-stack-protector) +CFLAGS-strlen-generic.op = $(no-stack-protector) + CFLAGS-memcpy_noalignment.c += -mno-strict-align -# Called during static initialization -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..60ae34e1ac8 100644 --- a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h @@ -73,6 +73,27 @@ 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 Tue Jun 23 12:47:45 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: 137635 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 E85BA4BA2E12 for ; Tue, 23 Jun 2026 12:50:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E85BA4BA2E12 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=mTHfi9gs X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x122a.google.com (mail-dl1-x122a.google.com [IPv6:2607:f8b0:4864:20::122a]) by sourceware.org (Postfix) with ESMTPS id BFEDB4B9DB76 for ; Tue, 23 Jun 2026 12:48:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFEDB4B9DB76 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 BFEDB4B9DB76 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::122a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218923; cv=none; b=uSY8lNlkt9Uk9Yr1nbFY2KP7Ydzga8BuuIiVvY0f2YhhwBGQVl2B11SLR8F3o6dwjnejDC6GFa/iOxf2ZEVGW7tMXN29ioom1OBiZiwAe7x4ywXu1Yp0zlqkgkVXwU0AePvJb/o2VL7Q9YOLFdvLkeWlM0vx3bEbv0yVDWcQqHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218923; c=relaxed/simple; bh=xGV+vHzbIxyWkSd+qyUgb0KY4iTNhw+ov/ssKu00lIM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=AF4ELJNOEJFRTB8sqV2OyDRJpywxRb7b3ST1IU7jlabH6MWDFjv2bKwVinrkg6/wvkxHDkf5V5Z5GCs3tE94vbQxVwz4Mq9Og397F1Mr61qbHYV80HGyMEwx5Sp9y+Y+UA5ZkVOL0IJiaY+zfJ6Um2l6hwiCbfwh96PIB/yL8uQ= 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=mTHfi9gs DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BFEDB4B9DB76 Received: by mail-dl1-x122a.google.com with SMTP id a92af1059eb24-139b914bab6so2616540c88.1 for ; Tue, 23 Jun 2026 05:48:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782218923; x=1782823723; 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=lAY8AXAuOI8JWRqg7Z1FItJE+truVmXrULujTMDe40Q=; b=mTHfi9gsoB6a6TRJ6v0jt6yhcy2LhZ6sy5Cpt9UinJEv3XScyBgfg3Uki8DnaovuqD 6OPEzfb/BmzRa11iYyLLEQqAuPN8ANsGuxNG+A75PPx1rVRoyuDRblogdPjkCEFThYyi Gynj1M/Hmw//cHbMP/d4TlsdJn4BpCLpVUIh/LIuRBmsn2xUSbECX2E6JofJwQsXq9ZF 2vIFexImAS8/0siIGhFFpQArWVQnJhxaZfVPW0871u9XcOUwPh16jMygAYRR+Ca50oY9 E8+YMbieAnjqFoFHGD5r2bR1T3ZMPE3x/azwjLDdfKcfVnoY5yKp1VLIRDkYkZvBdLcU qvfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782218923; x=1782823723; 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=lAY8AXAuOI8JWRqg7Z1FItJE+truVmXrULujTMDe40Q=; b=UqBZkSjcSgrJxHTYpqMKUatHFeoIfw6Bq7j/2h85GnRUAncjSoAgyUJXUYPFWA6whd R1JNpXz3cOKcnh6O77zDqz+STeMzvZdZifybNR5ZHRgjlzd0p8HxYNpuKhZg/icIduco nGmOkYIJTUX+dQ6FUBL24WaGDjaMc4G34jdVgRW85sJ4m9qv1J2k4QA922Mb06my+s5W s76RM6fGikUNcWGdT+MFLt0GXt4J6UEIyhHMS27p3kJbmDOYpxN5pYkjE9wGAlVM+4wp 4JVfl6vjXoAo9XwrcFWLfC6801F6QXBLPVk0wA5ujOGJCTB8l53zWa/lYyQJKcAvfiVT UABw== X-Gm-Message-State: AOJu0YxK+mYt4uZ1vujM0HmSIMn9TOI3cVQAspvAiUvJf6QY9Y6P6Idd F1a27FQi43xOv9y61sLB6442FlJpPkJdxvlssyakTDEwqZnLXOxHlcqAE7Dgk3QcWiTzPqSfr1r V1ZTf X-Gm-Gg: AfdE7cn+y5kOmRgbe+4R+sUAYJIgrbZGnM3Ipw0BiB+rOZq8TntDzy10I9k4S8eQfew 6ACnb10Tq6ldLBcKHGnuDp3JBj/X2Zp8LYIjIFNx5UOUyfSKrFx4QtvHGdCWT3t2mzfWZswRp3A 0Hx8YaBQk+nNDpNJnpwbLvpFypaNE3rIaExFpTshPu90xwQLAxS+GTlaQqEUCcEc6Km/uVuYQ4X HuoG0DqT8obT5NQGd5Ih3HJZTWqAazsO/MdaeDyo7Q3X29ww4aouLpB+92JuS3rk+/r85IKgHH4 RaDG3TFvaAutLFbNSUn5dVSAgFYMhTPyn1VuLueJUvI/ihjNhUv+rL0Szbm59EnWo+VXEsNQMaC CFAbrQftqzCRAmUo17Z4ycXwKXMxxGISu5u/5NCyZUaJdCyNR9T9PCjxYrxRCCBO211IdNyLHkD ENG+QFjgyoIiMKRTBe7cMEvPorHbSYikfp8R8= X-Received: by 2002:a05:7022:f68c:b0:138:1569:6f1 with SMTP id a92af1059eb24-139c6ed3b00mr1482485c88.11.1782218922505; Tue, 23 Jun 2026 05:48:42 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d170:82d3:e54e:278a:ac84]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-139adca1b18sm12183777c88.3.2026.06.23.05.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 05:48:42 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v10 4/5] elf: Allow RPATH/RUNPATH for static-pie (BZ 33326) Date: Tue, 23 Jun 2026 09:47:45 -0300 Message-ID: <20260623124831.2165041-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260623124831.2165041-1-adhemerval.zanella@linaro.org> References: <20260623124831.2165041-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_NONE, TXREP 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 ae75301a986..9b0f10c7cc5 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1241,7 +1241,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 @@ -3723,3 +3727,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 e5ba71fef18..1a931380c32 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -545,7 +545,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; @@ -1694,7 +1694,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 Tue Jun 23 12:47:46 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: 137637 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 084764BA2E3B for ; Tue, 23 Jun 2026 12:50:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 084764BA2E3B 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=Lbp7uIag X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1234.google.com (mail-dl1-x1234.google.com [IPv6:2607:f8b0:4864:20::1234]) by sourceware.org (Postfix) with ESMTPS id 776A54BA23D5 for ; Tue, 23 Jun 2026 12:48:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 776A54BA23D5 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 776A54BA23D5 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1234 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218925; cv=none; b=AmspsjkiM6V+XL1VnqMx1uv94rFanloMzU9Xcv2qijy03xCdpBUcrN1STnvz7sKZKEXTJqTDQAECpTuajpoQRO4OGkyguToqjkYJCiBv2GcG4eiRTfYMOcSNomHUry5zkSGljkFNwFYJgBuFUDcyurAYaslwixY4utf2sNnpvt0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1782218925; c=relaxed/simple; bh=cYNyQaLQDgyNCYNOWqe1SvAGk62cuDOfbRZNv6XktkY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=R4FmjSnjrSPGb0nFBjt4eyFvWRJA8R1DEVWEwQaQdl1j+TgtjlzBgNG55CAHwkayuq/upL2OP0lnU7RiS+Zab2XOx6yIAQ+VD3ErIp6AHo5yu6PPfTsYrnzY+3TIuC4E/4qI69wAJCmvTm5AsgisQ+mre9t2tG7Wza4bEO4cLmc= 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=Lbp7uIag DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 776A54BA23D5 Received: by mail-dl1-x1234.google.com with SMTP id a92af1059eb24-13981833e13so6108533c88.1 for ; Tue, 23 Jun 2026 05:48:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1782218924; x=1782823724; 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=HRpQPsTVY+nmfE6Z3800kB/VRagvxYdtOHISq+S5b5U=; b=Lbp7uIag3ZyUer6+2IrPpq7DBwXzf+fCdJtDcU9mfd543vyx87axScWKI2bZVkiVp/ gMdL9hgGLPMksyeGJa9Bg2fBu8znsqSOhd5W9wnNcEA/QTgCC8qT+BQ2JRAidOnD7DyU A06iaWL83db2ww6SfYK5L1Q5X5nwoMV2zkwGWaQevhae7NQFsyLTuOmF3mshaUg4hd+1 zSGjFIyK+Z9SJ8wJiKUiwGFIu/8LKbGw11L6dOmD0/jtODL84iE1xNC+QYpoTiZII9ms oD/V8C/OjHYggVjKtfFrOruiYn4GSXCIfiaW7si9iFUKZCDNw57/0gRDAvdCyedxOlDq nSMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782218924; x=1782823724; 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=HRpQPsTVY+nmfE6Z3800kB/VRagvxYdtOHISq+S5b5U=; b=SteZoa5e//4brQwL8OGJnAVkY2OtaEwRZV93KCVVHxguJw8F+vawNdJNkGOVRpGgDz A5iZ6rNDerEP/9TVunXyBN+0KvwJH+IMZl2rYWLxdHxSNF5jCzhkUCTZzd2B5wV90F5y BCyHwF7ZZh494LvAxOeE0cDR5CACkLku88BjV0koHWucbT/yn9vdNW9F78FwC8MNhXK9 ujqbN5pEh1BXMqdj0NJDD7VCj0ojbf8XXYkZw7iuP8DSKREtHauI/dI7rm9pMshUkQ3+ BJmI7ekUgQM3jcnnxxz5tbqGVnf6V1ZjhCmFDqleIrKrQVT3ThMeyjEktjf3hpHKaprG H6/A== X-Gm-Message-State: AOJu0YxupEn+rUcMVHBje5tOU2LodHzxrCCsY87peJH7qc3E994keKO7 IouhurWC0NESO85hKahCxRr8tgqTO2VoHccWh8tRBy8m6keXdvnc+XB+/3Z9+y+c2C/EKAyuZ4C b2j/u X-Gm-Gg: AfdE7cnorO6nZtSvUw0h0o587jijyrjleFRUobrTP0ESPEFxrROQLJqlhEH4vnQx7Sj 7ztQxR5mBaussG/SHp3aCiICOfY0Ih+hX/YkifdR/NL+a9JfsgUUlaWfiAD1kkWakCPZmXlzCxR l5gFkemCwR1EITS1XVd+yvO0dXlvLq4+NKD1PqDSOPaRo/s9//PpKC3UKoHz003rtLvVrsRno9n Y5g1XyV+UH3Z8321hEhyBpdXZgA/9h4IMXEThuh72eVJrlGLYWNpr6Qch6o/uZQUe8Np6y3xXUz XaIdYcXIrBLUVn2bh+DTLylfwpc8EdKuRrZoV7cqP69NAmn+Pe9azB+2Qp/ECF38auAd0VAXvTw 02VScpSfBWgo0LtCi4bEqz/pc/fuS8stnsLaMQbsD+JpDGPJIUa5SmeyCmR5ae4BfEx7W7yiOXT b2DW1aBcvJ0mI0pXFD+6VwZqN5 X-Received: by 2002:a05:7022:203:b0:134:dfd0:9760 with SMTP id a92af1059eb24-139c5cd8ad5mr1971064c88.5.1782218924181; Tue, 23 Jun 2026 05:48:44 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c0:d170:82d3:e54e:278a:ac84]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-139adca1b18sm12183777c88.3.2026.06.23.05.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2026 05:48:43 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v10 5/5] elf: Remove __chk_fail from dl-minimal.c Date: Tue, 23 Jun 2026 09:47:46 -0300 Message-ID: <20260623124831.2165041-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260623124831.2165041-1-adhemerval.zanella@linaro.org> References: <20260623124831.2165041-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, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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. --- 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 9b0f10c7cc5..7ae62d0bf12 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1578,6 +1578,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