From patchwork Fri Jan 30 12:21:10 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: 129276 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 20B654BA2E2E for ; Fri, 30 Jan 2026 12:24:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20B654BA2E2E 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=RwNpgOCO X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1235.google.com (mail-dl1-x1235.google.com [IPv6:2607:f8b0:4864:20::1235]) by sourceware.org (Postfix) with ESMTPS id D40604BA2E2E for ; Fri, 30 Jan 2026 12:22:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D40604BA2E2E 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 D40604BA2E2E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1235 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769775772; cv=none; b=cJX0eW2h8r+AxOntRLLj/LfSZ3e6cbwajlsDaGJuGx8tpwDYx5o4x5k4tmZ4bofPpx82gUd5ixai34cRoLqv6pYmB+OB5053YShw/jbuCI3F0LgXwwUvf5duiW0Gi3hAo3Zug9kvIEK8GQC2feoC0fUwGVteyXiUgNavrGJ8gi0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769775772; c=relaxed/simple; bh=BAu4TFBFoLIUKs46kv7h3yL3bwh4JYf4dxik8WP9hSs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TvB97/kzUFj9s2Fz1BETwMTDNxdZFUTIt5FjT/gcK/kSa/KBHiRdmTNdp1O3NrjXwtTHHvVhfhJVWlAJc5psz8vWlGj/AYi7wGj4hqC6aIsnbKxOpcU/XA2Lglatws9UUnZBu0/ePgk36AqC9gAuhIjriTRgDyxtvm6NTFLDwJo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D40604BA2E2E Received: by mail-dl1-x1235.google.com with SMTP id a92af1059eb24-124566b6693so792598c88.0 for ; Fri, 30 Jan 2026 04:22:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1769775770; x=1770380570; 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=Qw0l/LTsH5CgFeqg+XarjaTz4uswWL9aK3wa0DrLeS4=; b=RwNpgOCOYEGhB6GVWvhhQCBqs3ZTfDpWNOeCEEZCuBdOXo0Pzg2l35i3sf/ysv5WFQ yZzZEFhogHPIzlSWE4ScTuiaJ3sxyAcYkqxQGnNK2eTDHztDGKLwVczEwkeY0bF9gIkb WqxeaEZCZFsYEf1imhalaNys4jE4TINtLZ9n7tnoqlWVN/62xhGob80jLdpMaSKhMRq0 GjEcmwfzoKYouL68DLYh72RVw5RmNRL4RTPsQvaVBVuSXtGAmL6O+l5lEaExX9ys9nKf N887ZVzH+JAgzJrDIrQRvhTBvIwcs2Km2G6AnNkCeaIISKcoCJXqpWhGzsrVmlem3Ayv d3jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769775770; x=1770380570; 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=Qw0l/LTsH5CgFeqg+XarjaTz4uswWL9aK3wa0DrLeS4=; b=dRT3nhm2gPefg5PoJzPX51qQBcnAssAl4JCmHDlZnGj6WLcaCnuHmHFvQOyrQ9a672 V4iHdDcdD240qBBR1pDvldRX6pOz6oofktIg4SfbYyhMiWUmzzbJ8Hoc9bp4FdXg6KFS 5R044uXrKPvsddTn8E0arwVHs4xGSEExPh5Fjlfn05SUHrOzVDJNo0OTfUhtiblFsLVx 1B3wimRdNq3RngieP63oyVUvvzOmk+/qPncEMwIDfc4YXnfj8OwMRWpcqiyjOzcIL/2z gpAj/n4yFFT5O/9Tn9Bg+Z32C30mFyRDZspcroF1guc2Iy6l20H0zp7wVTfXHsJiw1po y5Nw== X-Gm-Message-State: AOJu0YzWwNBO6TWQum7XfUB+MBiw15yAfnsi4crt9g5MuKeWve8fYh0B VuJMOdAG2YHW8LSghlenVoa/9uV3SCsVGeZcY7m+vN3avMuh0BiKSpK0r9J7+/Ivrh6Kbb6qNl/ h/xYV X-Gm-Gg: AZuq6aLO9ZAgYHW0vpa5SwCtvNXn9tfzzqWDhrIrcD8JLNS9JncrQYGs2ud013WFd/N +D1azedpURDUDo+HdqZmyHoSinBoykt+aTJrFdYn6kJfAwCkOoyPrGFvCVT2gCGk9AozfEpXGr+ pLrLADF27PSMRC6/P1Ft3/WrTb2RMVJnnj5K2GjLTkIEnuCHGr4Tjm0LHIDMY99W1wVGy+ZKDHP QPTzX6GpVAX3MWHRbEXQfTfXyfdamMGba+V7Fz6KMQthDLxRptpTZSvBeNJRMranJKJY9v7hBVu 5sIGwApRARMbYCCj7xf5v8akT5fFpClXt8ntnGeVaoMn/Jm+wB1AUU8vxaaovOW6DGOg7UVYV+D MITtrel7erjWgPL4yiedlu9Qsgj2C3W5Mt29JTK27xf1ecwaT4+lWKSE+SRiJOkYWpI8S1qw9HR RilQRMAYAI814Ko5DxuU6lnqN1lCsKqxiMWRk= X-Received: by 2002:a05:7022:628e:b0:11b:ca88:c4f9 with SMTP id a92af1059eb24-125c0fa4c89mr1281100c88.2.1769775770236; Fri, 30 Jan 2026 04:22:50 -0800 (PST) Received: from ubuntu-vm.. ([187.56.133.167]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a9e0304bsm10047043c88.14.2026.01.30.04.22.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 04:22:49 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer , Wilco Dijkstra Subject: [PATCH v5 1/5] string: Add fallback implementation for ctz/clz Date: Fri, 30 Jan 2026 12:21:10 +0000 Message-ID: <20260130122240.4128717-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> References: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The libgcc implementations of __builtin_clzl/__builtin_ctzl may require access to additional data that is not marked as hidden, which could introduce additional GOT indirection and necessitate RELATIVE relocs. And the RELATIVE reloc is an issue if the code is used during static-pie startup before self-relocation (for instance, during an assert). For this case, the ABI can add a string-bitops.h header that defines HAVE_BITOPTS_WORKING to 0. A configure check for this issue is tricky because it requires linking against the standard libraries, which create many RELATIVE relocations and complicate filtering those that might be created by the builtins. The fallback is disabled by default, so no target is affected. Reviewed-by: Wilco Dijkstra --- sysdeps/generic/string-bitops.h | 26 ++++++++++++++++ sysdeps/generic/string-fzi.h | 54 +++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 sysdeps/generic/string-bitops.h diff --git a/sysdeps/generic/string-bitops.h b/sysdeps/generic/string-bitops.h new file mode 100644 index 0000000000..c4c03fbadf --- /dev/null +++ b/sysdeps/generic/string-bitops.h @@ -0,0 +1,26 @@ +/* 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 + . */ + +/* These macros define whether index_first/index_last macro can use the + stdbit.h routines, otherwise fallback that do not call libgcc is used + instead. + + An architecture can override it is it uses a generic string routines + on process startup and it can not use the libgcc routines for find + trailing/leading zeros. */ +#define HAVE_BITOPTS_WORKING 1 diff --git a/sysdeps/generic/string-fzi.h b/sysdeps/generic/string-fzi.h index 9f74e42dbf..10be1e2e34 100644 --- a/sysdeps/generic/string-fzi.h +++ b/sysdeps/generic/string-fzi.h @@ -22,23 +22,39 @@ #include #include #include +#include +#include -static __always_inline int -clz (find_t c) +static __always_inline unsigned int +ctzb (find_t c) { - if (sizeof (find_t) == sizeof (unsigned long)) - return __builtin_clzl (c); +#if HAVE_BITOPTS_WORKING + return stdc_trailing_zeros (c) / CHAR_BIT; +#else + if (sizeof (find_t) <= 4) + return (((c & -c) >> 7) * 0x00010203) >> 24; else - return __builtin_clzll (c); + return (((c & -c) >> 7) * 0x0001020304050607UL) >> 56; +#endif } -static __always_inline int -ctz (find_t c) +static __always_inline unsigned int +clzb (find_t c) { - if (sizeof (find_t) == sizeof (unsigned long)) - return __builtin_ctzl (c); - else - return __builtin_ctzll (c); +#if HAVE_BITOPTS_WORKING + return stdc_leading_zeros (c) / CHAR_BIT; +#else +# if ULONG_MAX == 0xFFFFFFFFUL + c |= c >> 8; + c |= c >> 16; + return ((c >> 7) * 0x30f0f0f0) >> 28; +# else + c |= c >> 8; + c |= c >> 16; + c |= c >> 32; + return ((c >> 7) * 0x70f0f0f0f0f0f0f0UL) >> 60; +# endif +#endif } /* A subroutine for the index_zero functions. Given a test word C, return @@ -47,12 +63,12 @@ ctz (find_t c) static __always_inline unsigned int index_first (find_t c) { - int r; + unsigned int r; if (__BYTE_ORDER == __LITTLE_ENDIAN) - r = ctz (c); + r = ctzb (c); else - r = clz (c); - return r / CHAR_BIT; + r = clzb (c); + return r; } /* Similarly, but return the (memory order) index of the last byte that is @@ -60,12 +76,12 @@ index_first (find_t c) static __always_inline unsigned int index_last (find_t c) { - int r; + unsigned int r; if (__BYTE_ORDER == __LITTLE_ENDIAN) - r = clz (c); + r = clzb (c); else - r = ctz (c); - return sizeof (find_t) - 1 - (r / CHAR_BIT); + r = ctzb (c); + return sizeof (find_t) - 1 - r; } #endif /* STRING_FZI_H */ From patchwork Fri Jan 30 12:21:11 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: 129275 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id C71AF4BB3BBD for ; Fri, 30 Jan 2026 12:23:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C71AF4BB3BBD 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=CBotcp8H X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x122d.google.com (mail-dl1-x122d.google.com [IPv6:2607:f8b0:4864:20::122d]) by sourceware.org (Postfix) with ESMTPS id A94184BA23DE for ; Fri, 30 Jan 2026 12:22:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A94184BA23DE 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 A94184BA23DE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::122d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769775773; cv=none; b=BzZd8/t91zTTC/lV82GbQjo9wy+f2aDNRucqlZDAS5rVw/IlGYqliMLqbHVYearDWvm8AODC2FkOelI8vV8KP6AQkPtcBNHVDypyoglgSGh904J3hryYdc3nAT0AfR2PITQzqGR111dFGd/KCgQvmf1S4nHD+ZP+tTXFqY9IBwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769775773; c=relaxed/simple; bh=Squh6AUMTTCqyfwJ24HwfKWXzAl/7rxLh3c/gewoUrY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CDr6x7jvbbBxBzy+jf3qYw3iDrrbmqWR4WzXDTy6WfkW9YhFfhdH/W5n5Zg0GDc50EKUsPuBP1aWIjJ+yhY3bB4TCWttaRBvm8RfNymxiR67Ci6CrTa3AVw/UWr6CbJ+pOz+3O09+AZJSibkAh5vdrK0IxEuzJXZaUW8vpC5lMU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A94184BA23DE Received: by mail-dl1-x122d.google.com with SMTP id a92af1059eb24-124a635476fso3019964c88.0 for ; Fri, 30 Jan 2026 04:22:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1769775772; x=1770380572; 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=G7I7axHu2zVYGXQmMTGPZsk/EV89OxAUEBp9UNxgYeY=; b=CBotcp8H9KiLMR01ZCqGPC2HrE6uoh/nWY+T8kecN3EkXqCLE4beeCXZ+5RrVmGG2J F6WNgQtI3mWtCFjKJ4+FpeVZjeY2eW/FCJMrRDSL37MNmYoR12J7+hw3TKRyHWvcdIBZ x4ZA5G/ibvKiBOKTdqwyxrL1QY7ZM4O7pQC8pYgCc7s/0OLDhc8F2n+Y8LBwMASgmc2d EmlA+DQ0fkCVjIxHCSgHCuUgO0Bzc79eZttdaKG/SN5KaB3q3xJFJ18kdLc8AYLjv9yR J6dM81nndY/cmC7iR9Hb+lgHfADIxW+Oj8GwSrmWvMPMZSb0w5KSamPAFeqtaMmVXEWP edIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769775772; x=1770380572; 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=G7I7axHu2zVYGXQmMTGPZsk/EV89OxAUEBp9UNxgYeY=; b=Nwv9cP0LbJSZ/lbTso8gt2KxppNGnhYvkFdGp95S53PYAZyEQDlZdLCyPQWwUw1vMc Ud8Ck/+hIGd8lEtxruqdKVqm29sysrL//Lljtfawswkhl4geHMK5iizHS3zpp0EnbfhB eRSzKF0G1EdCDOPfe+/a05rTjQ35I8DETrdDTjE1HOfcVZUB9v9ruux3iY1D6Sbxp6HE qo4jY1yV/QFW2/+t4PL3MM/q7REXPOX7IG902qzQZoqasvuZKITDx9lhCT/QzH3n/xa5 tC+bQaa24KyEHsKIbABGODUr8coAtBQ3j7rmAWxH8AxYF36fGlU3maeBf/mMZr8iY5tb rUYg== X-Gm-Message-State: AOJu0YxpUMpNyXu40RZ5dVhwZwfnmNkdtuUyiHrUVqffQdbocZV5zgxv +QkRnFIPamHF75z8+Jbm2yTMcfC7M6kw2b9wO+a2fpnXBW1jBEgfCnFd+USuRG3gg3Hb7xvq/3F C03pB X-Gm-Gg: AZuq6aJeh3FfGLiLwPUBu8tdP670rfyk3J3hF/Vv+k6xYguZT/9XjN083MnzQeGbErW PbHJ4ppBmTsZTvgqHEjEdDN8c2+9Ku/rNrn10AbFh2lm8wdLD329YOgc6rCiuo5UB58PtZL1OZb 2Jp9XsprBPIGOykPtrFR9mI7RiNrAr6s3rwEuz8K0Ik8150VwhSxCYMBTNl+HwtchumsJYvTd90 B0Dbl8OfQYzCo7/ZhnpMV6cLlcekl+9xkOHkwLh8JEbvzojPp2WQFnSFjrK676T3DH/nqNmJPG6 DeYDbv24clL2Doldhr0aA52ev751LcMZi65+RZ0FG4ZV7aJirwGVHYu6/pwn/HMe2bCCWl24i5W GS6567KxkpKh4mAk8Pp+6sWYDYwD4kpWkEaN6r/Bxw1zCaiqIBw7ERiKsvbBVXjlH6UCmLhOWZf c+aqN87TQaF/ASl/StD/AcQsTdlHphDAM4SrM= X-Received: by 2002:a05:7022:602:b0:11b:9386:a387 with SMTP id a92af1059eb24-125c100f46emr1277895c88.42.1769775772052; Fri, 30 Jan 2026 04:22:52 -0800 (PST) Received: from ubuntu-vm.. ([187.56.133.167]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a9e0304bsm10047043c88.14.2026.01.30.04.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 04:22:51 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v5 2/5] nptl: Add __raise_direct Date: Fri, 30 Jan 2026 12:21:11 +0000 Message-ID: <20260130122240.4128717-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> References: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The function sends a signal to current thread using raw syscalls. --- include/signal.h | 2 ++ nptl/pthread_kill.c | 21 ++++++------------ signal/raise.c | 1 + sysdeps/htl/raise.c | 1 + sysdeps/posix/raise.c | 2 +- sysdeps/unix/sysv/linux/Makefile | 4 ++++ sysdeps/unix/sysv/linux/raise_direct.c | 30 ++++++++++++++++++++++++++ 7 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/raise_direct.c diff --git a/include/signal.h b/include/signal.h index 73f18dddd7..850554ac3b 100644 --- a/include/signal.h +++ b/include/signal.h @@ -65,6 +65,8 @@ extern int __xpg_sigpause (int sig); /* Allocate real-time signal with highest/lowest available priority. */ extern int __libc_allocate_rtsig (int __high); +extern int __raise_direct (int signo) attribute_hidden; + # if IS_IN (rtld) extern __typeof (__sigaction) __sigaction attribute_hidden; extern __typeof (__libc_sigaction) __libc_sigaction attribute_hidden; diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c index 221689e36a..bc038e9824 100644 --- a/nptl/pthread_kill.c +++ b/nptl/pthread_kill.c @@ -29,20 +29,13 @@ __pthread_kill_implementation (pthread_t threadid, int signo, int no_tid) { struct pthread *pd = (struct pthread *) threadid; if (pd == THREAD_SELF) - { - /* Use the actual TID from the kernel, so that it refers to the - current thread even if called after vfork. There is no - signal blocking in this case, so that the signal is delivered - immediately, before __pthread_kill_internal returns: a signal - sent to the thread itself needs to be delivered - synchronously. (It is unclear if Linux guarantees the - delivery of all pending signals after unblocking in the code - below. POSIX only guarantees delivery of a single signal, - which may not be the right one.) */ - pid_t tid = INTERNAL_SYSCALL_CALL (gettid); - int ret = INTERNAL_SYSCALL_CALL (tgkill, __getpid (), tid, signo); - return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0; - } + /* There is no signal blocking in this case, so that the signal is + delivered immediately, before __pthread_kill_internal returns: a signal + sent to the thread itself needs to be delivered synchronously. (It is + unclear whether Linux guarantees the delivery of all pending signals + after unblocking in the code below. POSIX only guarantees delivery + of a single signal, which may not be the right one.) */ + return __raise_direct (signo); /* Block all signals, as required by pd->exit_lock. */ internal_sigset_t old_mask; diff --git a/signal/raise.c b/signal/raise.c index b6f5cbee4e..86d3968e19 100644 --- a/signal/raise.c +++ b/signal/raise.c @@ -26,6 +26,7 @@ raise (int sig) return -1; } weak_alias (raise, gsignal) +weak_alias (raise, __raise_direct) stub_warning (raise) stub_warning (gsignal) diff --git a/sysdeps/htl/raise.c b/sysdeps/htl/raise.c index 3200f91634..78600a59c6 100644 --- a/sysdeps/htl/raise.c +++ b/sysdeps/htl/raise.c @@ -51,6 +51,7 @@ raise (int signo) else return __kill (__getpid (), signo); } +weak_alias (raise, __raise_direct) libc_hidden_def (raise) weak_alias (raise, gsignal) diff --git a/sysdeps/posix/raise.c b/sysdeps/posix/raise.c index 8abe8d4cad..cf0770f1c8 100644 --- a/sysdeps/posix/raise.c +++ b/sysdeps/posix/raise.c @@ -23,7 +23,7 @@ int raise (int sig) { - int ret = __pthread_kill (__pthread_self (), sig); + int ret = __raise_direct (sig); if (ret != 0) { __set_errno (ret); diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 955d316362..0b86be0d9a 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -454,6 +454,10 @@ tests += \ endif ifeq ($(subdir),signal) +sysdep_routines += \ + raise_direct \ + # sysdep_routines + tests-special += \ $(objpfx)tst-signal-numbers.out \ # tests-special diff --git a/sysdeps/unix/sysv/linux/raise_direct.c b/sysdeps/unix/sysv/linux/raise_direct.c new file mode 100644 index 0000000000..272b328a98 --- /dev/null +++ b/sysdeps/unix/sysv/linux/raise_direct.c @@ -0,0 +1,30 @@ +/* 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) +{ + /* Use direct syscall to avoid external symbols. */ + 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 Jan 30 12:21:12 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129277 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 5BE384BAD149 for ; Fri, 30 Jan 2026 12:26:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BE384BAD149 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=WeEFGKMm X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x122e.google.com (mail-dl1-x122e.google.com [IPv6:2607:f8b0:4864:20::122e]) by sourceware.org (Postfix) with ESMTPS id A392C4BA2E2D for ; Fri, 30 Jan 2026 12:22:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A392C4BA2E2D 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 A392C4BA2E2D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::122e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769775775; cv=none; b=FYHjMVLmd8PSIwpfEn3L13HBMi2iuo6zZSIG/5dOJwZVyCUSWeK0+stsm/6W7NKqU+ynlenKdyzaLcZsWW/MDdMl31y9sj/Cp39Y/1H4x1dDYrzRq8u8WaXW7ZWfRTcy1LfvbftoZof/X66uNMBP/VO+QtXSDEuE8v45tNiEJG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769775775; c=relaxed/simple; bh=UrCzwBTEPPLD0tbzA9GlRcdHTvtQHN0zyB8yUz86Xvk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=r8/Rai9KTqQVACIzePSoJgkpHf6lpiRcn3nPv5YtSw2XQylHW1cUZDOYIyeBmGEUwwgOzz7hSInRm33deYoVWXLz3uNiL99p52W8Zpt8BwGmt7ygUELGGHVGY0WvNTH6FsLwp6+IjZ8YhRqRVFGXjmMqZYNzot2GQ/BtjqhLVYE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A392C4BA2E2D Received: by mail-dl1-x122e.google.com with SMTP id a92af1059eb24-1249b9f5703so2920448c88.0 for ; Fri, 30 Jan 2026 04:22:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1769775774; x=1770380574; 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=8K8oA3GoxR9n6Jb1begAmQJVt0QzaBydrl4xliXiIvM=; b=WeEFGKMmpgtn2imJMR3RuUP0hPEkZ7GdxT/C2H+ZuGaPkzAlJdxzMq6fiD/KRZB32D 0RNIVsry86VzPusrvaqrlOwVafIUy8IciJZzBWJMwcIQPCcITrJhezAU421Hl1byLAlA 2n4zgvBHoUErGaxpys0AY1FKf3CU8HEuz7JcZAbmlRnWZDFYM08OGxzzkBjtk6GBkae2 099m2Bst5wmtuAQzd51e3KQu++FOmBFtrMbnv50q8WU5CcXtKn3nvmx2kaCqNSsoYMGJ gyIPgkZgpowaSj4vKLema+FGsmfOb63CLEv/ZlRtv4JrILOi1FNt3bKEAst2kUWsQdR6 FTSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769775774; x=1770380574; 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=8K8oA3GoxR9n6Jb1begAmQJVt0QzaBydrl4xliXiIvM=; b=p/rDEh1B07J5mJ6F0pGUz8HD9rXh0nQflTnclp8wnEwpgzuyfzS5DwQJ2TKV3FzH1y eyTrLgFGWawIPoayrKMnh9XZFZhViQkDv/n+2m9piJFDWcLjbfooaXL23AwQvJ8quwxu yHspNNfj3D1rAOpZPrjc+EePG8SoTpL9r2SIQjZKQATbmo8yKHoiTwsV42M9aBfy9zgs VUWQAGXXojMYt5nNB/2CTdGBb48ug83bnZXliaoFs+vsUCDgoG5zZg4gOk4zmIWyNIAy 3S90LKbATfj3K5cKfgwu0rQ+Os9soWn0s2t7hVwLlQzNyprEiSERdKDQCWeR7hhrEIgV WnjA== X-Gm-Message-State: AOJu0YzW+J5USkfSdZjUVyJnuu7+0DI1+fFjL3574S99VRaqxNuR3csK TGURQkB7kM3y/m3ZX9CpE1SH2N4g3HDH4fdwp3BtbafcrbF5hlUTEh6JtEsjJu+IDQ4gfk8sgng MJJzL X-Gm-Gg: AZuq6aK3CmIcHEJK6XRrTAvNYMk8kqmGOAdUSUeDts15I/VjPg1ENg9EsCYEY7ncRcw fCmDx47h3zfqAt0R8BV1bnL+qIXhQPgQS48+D7hLEs+hEpppHtpkHWVP39W0HzDgUG2cQJ/BWUJ RAKE0z9aMbGNHMFRZLCDywDO4CtEnNUoJT3Djr1WNT0Z3upJbw5kDfVaLdT8Wc14KclU1BQSB4i 9Bdm75yW5+8G16psdCXp1TljddQ9QldNHFyKJO8WR4d6wQbseBebjXNw9R2vBuEYxZJWE4jCooD b0SUWkasdC8petJ3+RHULpv7VcsZu7Unws6g30iRSkxowSphkvGL3Y7pZP+l59hwO8ObYs7K5qR e84BU1ll04GAFSk5dR9VMmCTNoNj4gZCfklwgg2NAOlytFvoubfMoep+fRF85v0E5kyIRYiBUNx YPr8x44uN14qnGwPk09gkCq4FBo5mizwOuMPs= X-Received: by 2002:a05:7022:6b82:b0:11a:37a7:3d2f with SMTP id a92af1059eb24-125c100d0e5mr1230904c88.37.1769775773857; Fri, 30 Jan 2026 04:22:53 -0800 (PST) Received: from ubuntu-vm.. ([187.56.133.167]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a9e0304bsm10047043c88.14.2026.01.30.04.22.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 04:22:53 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v5 3/5] Use _dl_writev on __libc_message_impl Date: Fri, 30 Jan 2026 12:21:12 +0000 Message-ID: <20260130122240.4128717-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> References: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org And change _dl_writev to return a negative errno in case of failure. This keeps the required semantics for not setting errno on failure and allows removing the Linux libc_fatal.c implementation. It also makes it simple to use the writev syscall during process startup, especially on i386, where it requires disabling vDSO. Checked on x86_64-linux-gnu and i686-linux-gnu. --- {elf => sysdeps/generic}/dl-writev.h | 18 +++++++------- sysdeps/posix/libc_fatal.c | 15 ++++++------ sysdeps/unix/sysv/linux/dl-writev.h | 12 ++++------ sysdeps/unix/sysv/linux/libc_fatal.c | 36 ---------------------------- 4 files changed, 20 insertions(+), 61 deletions(-) rename {elf => sysdeps/generic}/dl-writev.h (80%) delete mode 100644 sysdeps/unix/sysv/linux/libc_fatal.c diff --git a/elf/dl-writev.h b/sysdeps/generic/dl-writev.h similarity index 80% rename from elf/dl-writev.h rename to sysdeps/generic/dl-writev.h index a235942605..024b780bf2 100644 --- a/elf/dl-writev.h +++ b/sysdeps/generic/dl-writev.h @@ -20,37 +20,35 @@ #include #include -/* This is used from only one place: dl-misc.c:_dl_debug_vdprintf. - Hence it's in a header with the expectation it will be inlined. - - This is writev, but with a constraint added and others loosened: +/* This is writev, but with a constraint added and others loosened: 1. Under RTLD_PRIVATE_ERRNO, it must not clobber the private errno when another thread holds the dl_load_lock. - 2. It is not obliged to detect and report errors at all. - 3. It's not really obliged to deliver a single atomic write + 2. It's not really obliged to deliver a single atomic write (though it may be preferable). */ -static inline void +static inline ssize_t _dl_writev (int fd, const struct iovec *iov, size_t niov) { /* Note that if __writev is an implementation that calls malloc, this will cause linking problems building the dynamic linker. */ + ssize_t r; #if RTLD_PRIVATE_ERRNO /* We have to take this lock just to be sure we don't clobber the private errno when it's being used by another thread that cares about it. Yet we must be sure not to try calling the lock functions before the thread library is fully initialized. */ if (__glibc_unlikely (_dl_starting_up)) - __writev (fd, iov, niov); + _r = _writev (fd, iov, niov); else { __rtld_lock_lock_recursive (GL(dl_load_lock)); - __writev (fd, iov, niov); + r = __writev (fd, iov, niov); __rtld_lock_unlock_recursive (GL(dl_load_lock)); } #else - __writev (fd, iov, niov); + r = __writev (fd, iov, niov); #endif + return r == -1 ? -errno : r; } diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index 4f11315c2a..3f0e302b5e 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -16,6 +16,7 @@ License along with the GNU C Library; if not, see . */ +#include #include #include #include @@ -28,14 +29,14 @@ #include FATAL_PREPARE_INCLUDE #endif -#ifndef WRITEV_FOR_FATAL -# define WRITEV_FOR_FATAL writev_for_fatal -static bool -writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total) +static void +writev_for_fatal (int fd, const struct iovec *iov, size_t niov) { - return TEMP_FAILURE_RETRY (__writev (fd, iov, niov)) == total; + ssize_t cnt; + do + cnt = _dl_writev (fd, iov, niov); + while (cnt == -EINTR); } -#endif /* At most a substring before each conversion specification and the trailing substring (the plus one). */ @@ -108,7 +109,7 @@ __libc_message_impl (const char *vma_name, const char *fmt, ...) if (iovcnt > 0) { - WRITEV_FOR_FATAL (fd, iov, iovcnt, total); + writev_for_fatal (fd, iov, iovcnt); total = ALIGN_UP (total + sizeof (struct abort_msg_s) + 1, GLRO(dl_pagesize)); diff --git a/sysdeps/unix/sysv/linux/dl-writev.h b/sysdeps/unix/sysv/linux/dl-writev.h index 89f69f8ab1..ceb98a35e6 100644 --- a/sysdeps/unix/sysv/linux/dl-writev.h +++ b/sysdeps/unix/sysv/linux/dl-writev.h @@ -19,19 +19,15 @@ #include #include -/* This is used from only one place: dl-misc.c:_dl_debug_vdprintf. - Hence it's in a header with the expectation it will be inlined. - - This is writev, but with a constraint added and others loosened: +/* This is writev, but with a constraint added and others loosened: 1. Under RTLD_PRIVATE_ERRNO, it must not clobber the private errno when another thread holds the dl_load_lock. - 2. It is not obliged to detect and report errors at all. - 3. It's not really obliged to deliver a single atomic write + 2. It's not really obliged to deliver a single atomic write (though it may be preferable). */ -static inline void +static inline ssize_t _dl_writev (int fd, const struct iovec *iov, size_t niov) { - INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); + return INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); } diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c deleted file mode 100644 index 120cdffaf9..0000000000 --- a/sysdeps/unix/sysv/linux/libc_fatal.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Catastrophic failure reports. Linux version. - Copyright (C) 1993-2026 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - -static bool -writev_for_fatal (int fd, const struct iovec *iov, size_t niov, size_t total) -{ - ssize_t cnt; - do - cnt = INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); - while (INTERNAL_SYSCALL_ERROR_P (cnt) - && INTERNAL_SYSCALL_ERRNO (cnt) == EINTR); - return cnt == total; -} -#define WRITEV_FOR_FATAL writev_for_fatal - -#include From patchwork Fri Jan 30 12:21:13 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129278 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id EBAF74BA2E2F for ; Fri, 30 Jan 2026 12:26:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBAF74BA2E2F 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=mbCXpFM9 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x1241.google.com (mail-dl1-x1241.google.com [IPv6:2607:f8b0:4864:20::1241]) by sourceware.org (Postfix) with ESMTPS id 0E5524BA23DE for ; Fri, 30 Jan 2026 12:22:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E5524BA23DE 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 0E5524BA23DE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1241 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769775778; cv=none; b=uRAeBzgAseFlXCLUeaey2vZPtVmTGTQPn2Fkicmvo6TPgcowJxqE7JpzXunNjraGjzhNwkYnLohoFzMagqORqcIEKm8Y1/Oyj6XCu0lOfmzRfniBzlxJfFvYVVGLF8Ww497+ZBQ2iuH1a060JjHBr/vLrW4LVPpiNOWdg1j+1vk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769775778; c=relaxed/simple; bh=eyGNzHM2EVAVujw0dBaOHFg9lN1NRk6VuWcF5gR5kkU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TlAyDpdFiwR+Nc07gjuD2kRsvO6CEmuUdnJ0E/hHqEnaEhtyMbwDviKY5YCdsP7y4Wl/HKkBoKSY33iDkf9KNhcvE4hZ/DV4j8F9193I4208DKDZWThmUzx0XJuDU0CtHavQKdcjRP/sdS4C0AwkglNMHJgVkfmEhkr9q2TXrRk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E5524BA23DE Received: by mail-dl1-x1241.google.com with SMTP id a92af1059eb24-11f36012fb2so2565652c88.1 for ; Fri, 30 Jan 2026 04:22:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1769775777; x=1770380577; 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=o7W/mRqflJEzHP74Hy9tJMtgtvAMyt6tz7QZjjvezbE=; b=mbCXpFM9QdEyTUwmPO9bDELMtKw/KQ2dJE+CU9YPlTufGdMsBgi5iJc7p9hR4emnOI L2/1cS9mOSxN4D3k7F4tvxqMtz+T66v+CdMIhSEmWcvngLuofaoBbFlkS9/lNkpOrPpl S5rRIq3ATuec8pJBEwRowVOVlNCopoy1eHYB7t6wuwp3o7IpEj07kRaMunvPfTlg3wsH GymDu7odlOlz0+Zu02Ggu39UHY8nLIWOYG4FoPG0GjEwVc5BHzhx48zypc/xiKMuhSeb J7M78tKNESMAFWZp+WynwQSv2/GLN353ylft89eC/jkmiaZHtAfNXo280EtxxK6wFOiP ++Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769775777; x=1770380577; 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=o7W/mRqflJEzHP74Hy9tJMtgtvAMyt6tz7QZjjvezbE=; b=TE0CpbgpqkapSS/VL6fLy/wxSXlcc4edZUAqrY19S1L4ipxuZ+LHEMg0UGr3Xy/wJD bt4CqdHj51lGXxau8ZpamJZT0fcKQTp/aTXoY7+kb3XFWfZ0E/e2tcA/P57picikNii4 AW8zUVWiRanV9j+00iZpUTFjE/95+Cxeri5yHuDyUMAWG2Bg1+pzyOVAwmHFcC2jWQ+6 dilJD7bAe830UHGvhArGGvnBcj8IBCB+NfO2KX8MtZSYxum5YxWEOuMf6veskaioxW6+ Oimg9IZvUwQJBJAh/b9B7TAXWbbi2lnAM6ux+OE8i912Di4deZgTZ9FEUwtQTOzM7UPE Ryqg== X-Gm-Message-State: AOJu0YwL0UcENqqkbwh+DsQeczOaa2hjK63GUBp0ubFf6kln4OmKb0eb Rj9vIH1QcYZQ1Tr7fa2gzSs0aLWBg9l43eQd92LwyTdqfPM9ZA91Ay3h9Fykikp8Xglhmq1udfq g3okWDnc= X-Gm-Gg: AZuq6aIeCs1rNa5zpVzYIEAdw4qiOVT5pogvAdivSET5rKDb2MURfGpAmTjWI7o9pig itlzRJ9Jz/1QRCtK2nFnUFGjZG+h0hgqWHUR7iJP3hEdeTzFZymKG0fMziTWjLDISQwA5hcHYpP v6dj7Plv/pLcFe7Ir8Zo8kCOGqscXMKzrApgT+XRgmQIOQP3kJWrlWBuI0nHgOwS8dl2wUgKIUi IeJ/pbMpOAT6fpg/SafGa5lEHEjXX+f/GzRjaTQ7HHUMVn6eRG2P4iCoImlBdqtfiUous8sF0Mj YHtz3exNZghAAxKO7RSrwWWxVfMFW4efUM6iQgjYQVIWvWBra0Q/eu0VJGv9FXSxMgNyMBNMEfL nWk6LT+T9TSFTFx8xnwN7OLaEnS+0SMUG/rC6f8JSz8YtQGG65N6y0IMT4sOQl9NGYe9eZxbJfM TAhPBBTxmE3AOJR73VU/jMEfEIFIapYXbFRGY= X-Received: by 2002:a05:7022:628b:b0:119:e56b:91d1 with SMTP id a92af1059eb24-125c0f7df73mr1109053c88.2.1769775776114; Fri, 30 Jan 2026 04:22:56 -0800 (PST) Received: from ubuntu-vm.. ([187.56.133.167]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a9e0304bsm10047043c88.14.2026.01.30.04.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 04:22:55 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v5 4/5] Fix assert during static startup Date: Fri, 30 Jan 2026 12:21:13 +0000 Message-ID: <20260130122240.4128717-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> References: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 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_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The BZ#33326 testcase triggers an assertion during process startup, which results in a segmentation fault instead of an error message and process termination with a SIGABRT. The assert issues __libc_message_impl, which in turn might call string functions depending on the ABI (strchrnul, strlen, memcpy/mempcpy), system calls (writev and mmap), and finally the abort call. Since each function may be called during process startup, before self-relocation and/or the thread pointer being set up, the functions should be built without stack protection. The dl-symbol-redir-ifunc.h is also expanded to cover strlen/memcpy/mempcpy/strchrnul on multiple architectures that implement ifunc. On i386, syscalls should not use the vDSO ("call *%gs:SYSINFO_OFFSET"), so a raise_direct.c and mmap call is added that disables I386_USE_SYSENTER. 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 | 16 ++++++++ elf/tst-assert-startup-static.c | 35 +++++++++++++++++ libio/Makefile | 5 +++ stdlib/Makefile | 5 +++ string/Makefile | 2 + .../aarch64/multiarch/dl-symbol-redir-ifunc.h | 2 + sysdeps/aarch64/multiarch/memcpy_generic.S | 4 ++ sysdeps/aarch64/multiarch/strlen_generic.S | 4 ++ sysdeps/generic/dl-mmap.h | 34 +++++++++++++++++ .../lp64/multiarch/dl-symbol-redir-ifunc.h | 3 ++ 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/dl-mmap.h | 34 +++++++++++++++++ sysdeps/unix/sysv/linux/i386/dl-mmap.h | 38 +++++++++++++++++++ sysdeps/unix/sysv/linux/i386/raise_direct.c | 26 +++++++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 7 ++++ .../riscv/multiarch/dl-symbol-redir-ifunc.h | 26 +++++++++++++ .../x86_64/multiarch/dl-symbol-redir-ifunc.h | 33 ++++++++++++++++ 28 files changed, 376 insertions(+), 3 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/dl-mmap.h create mode 100644 sysdeps/unix/sysv/linux/i386/dl-mmap.h create mode 100644 sysdeps/unix/sysv/linux/i386/raise_direct.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/dl-symbol-redir-ifunc.h diff --git a/assert/Makefile b/assert/Makefile index f6f5eec1af..bb9e473963 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 01cc51636e..0fb27132e5 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -282,6 +282,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 \ @@ -293,6 +294,10 @@ tests-static-internal := \ tst-tunables-enable_secure \ # tests-static-internal +tests-special += \ + $(objpfx)tst-assert-startup-static.out \ + # tests-special + CRT-tst-tls1-static-non-pie := $(csu-objpfx)crt1.o tst-tls1-static-non-pie-no-pie = yes @@ -3534,3 +3539,14 @@ $(objpfx)tst-origin.out: tst-origin.sh $(objpfx)tst-origin $(evaluate-test) $(objpfx)tst-dlopen-sgid.out: $(objpfx)tst-dlopen-sgid-mod.so + +CFLAGS-tst-assert-startup-static.c += $(no-stack-protector) +LDFLAGS-tst-assert-startup-static = -Wl,-z,muldefs + +$(objpfx)tst-assert-startup-static.out: $(objpfx)tst-assert-startup-static + $(test-program-cmd-before-env) \ + $(run-program-env) \ + $< > $@ 2>&1; echo "status: $$?" >> $@; \ + grep -q 'Fatal glibc error: tst-assert-startup-static' $@ \ + && grep -q '^status: 134$$' $@; \ + $(evaluate-test) diff --git a/elf/tst-assert-startup-static.c b/elf/tst-assert-startup-static.c new file mode 100644 index 0000000000..5b0dbdea32 --- /dev/null +++ b/elf/tst-assert-startup-static.c @@ -0,0 +1,35 @@ +/* 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) +{ + __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 4f4dd9f275..a6e1e434ff 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -181,6 +181,11 @@ endif CPPFLAGS += $(libio-mtsafe) +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-libc_fatal.o = $(no-stack-protector) +CFLAGS-libc_fatal.op = $(no-stack-protector) + # Support for exception handling. CFLAGS-fileops.c += -fexceptions CFLAGS-fputc.c += -fexceptions diff --git a/stdlib/Makefile b/stdlib/Makefile index 04596b53b1..8a39121777 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -528,6 +528,11 @@ generated += \ tst-putenvmod.so \ # generated +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-abort.o = $(no-stack-protector) +CFLAGS-abort.op = $(no-stack-protector) + CFLAGS-bsearch.c += $(uses-callbacks) CFLAGS-qsort.c += $(uses-callbacks) CFLAGS-system.c += -fexceptions diff --git a/string/Makefile b/string/Makefile index c4423c0437..969726cccb 100644 --- a/string/Makefile +++ b/string/Makefile @@ -286,6 +286,8 @@ CFLAGS-wordcopy.c += $(no-stack-protector) # Called during static initialization 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 647bdd66dd..a686fd1f92 100644 --- a/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h @@ -19,6 +19,8 @@ #ifndef _DL_IFUNC_GENERIC_H #define _DL_IFUNC_GENERIC_H +asm ("memcpy = __memcpy_generic"); asm ("memset = __memset_generic"); +asm ("strlen = __strlen_generic"); #endif diff --git a/sysdeps/aarch64/multiarch/memcpy_generic.S b/sysdeps/aarch64/multiarch/memcpy_generic.S index c6d09081f4..d622268305 100644 --- a/sysdeps/aarch64/multiarch/memcpy_generic.S +++ b/sysdeps/aarch64/multiarch/memcpy_generic.S @@ -42,3 +42,7 @@ #endif #include "../memcpy.S" + +#if IS_IN (rtld) +strong_alias (memcpy, __memcpy_generic) +#endif diff --git a/sysdeps/aarch64/multiarch/strlen_generic.S b/sysdeps/aarch64/multiarch/strlen_generic.S index cb9d5759ac..a362328142 100644 --- a/sysdeps/aarch64/multiarch/strlen_generic.S +++ b/sysdeps/aarch64/multiarch/strlen_generic.S @@ -40,3 +40,7 @@ #endif #include "../strlen.S" + +#if IS_IN (rtld) +strong_alias (strlen, __strlen_generic) +#endif diff --git a/sysdeps/generic/dl-mmap.h b/sysdeps/generic/dl-mmap.h new file mode 100644 index 0000000000..f786be0930 --- /dev/null +++ b/sysdeps/generic/dl-mmap.h @@ -0,0 +1,34 @@ +/* mmap wrapper for dynamic loader. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _DL_MMAP_H +#define _DL_MMAP_H + +#include + +/* This mmap call is used to allocate some memory to backup assert() messages + before TLS setup is done (which setup the thread pointer used by some ABIs + to issues syscalls). */ + +static inline void * +_dl_mmap (void *addr, size_t len, int prot, int flags) +{ + return __mmap (addr, len, prot, flags, -1, 0); +} + +#endif diff --git a/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h index 9fdd039da0..43f50f8bcc 100644 --- a/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/loongarch/lp64/multiarch/dl-symbol-redir-ifunc.h @@ -20,8 +20,11 @@ #define _DL_IFUNC_GENERIC_H #ifndef SHARED +asm ("memcpy = __memcpy_aligned"); asm ("memset = __memset_aligned"); asm ("memcmp = __memcmp_aligned"); +asm ("__strchrnul = __strchrnul_aligned"); +asm ("strlen = __strlen_aligned"); #endif #endif diff --git a/sysdeps/posix/libc_fatal.c b/sysdeps/posix/libc_fatal.c index 3f0e302b5e..1ff20d4feb 100644 --- a/sysdeps/posix/libc_fatal.c +++ b/sysdeps/posix/libc_fatal.c @@ -16,7 +16,12 @@ License along with the GNU C Library; if not, see . */ +/* Mark symbols hidden in static PIE for early self relocation to work. */ +#if BUILD_PIE_DEFAULT +# pragma GCC visibility push(hidden) +#endif #include +#include #include #include #include @@ -24,6 +29,7 @@ #include #include #include +#include #ifdef FATAL_PREPARE_INCLUDE #include FATAL_PREPARE_INCLUDE @@ -113,9 +119,9 @@ __libc_message_impl (const char *vma_name, const char *fmt, ...) total = ALIGN_UP (total + sizeof (struct abort_msg_s) + 1, GLRO(dl_pagesize)); - struct abort_msg_s *buf = __mmap (NULL, total, - PROT_READ | PROT_WRITE, - MAP_ANON | MAP_PRIVATE, -1, 0); + struct abort_msg_s *buf = _dl_mmap (NULL, total, + PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE); if (__glibc_likely (buf != MAP_FAILED)) { buf->size = total; diff --git a/sysdeps/powerpc/powerpc32/power4/multiarch/Makefile b/sysdeps/powerpc/powerpc32/power4/multiarch/Makefile index 3a49b855ca..60ba2e50d2 100644 --- a/sysdeps/powerpc/powerpc32/power4/multiarch/Makefile +++ b/sysdeps/powerpc/powerpc32/power4/multiarch/Makefile @@ -11,4 +11,9 @@ sysdep_routines += memcpy-power7 memcpy-a2 memcpy-power6 memcpy-cell \ strchr-power7 strchr-ppc32 \ wordcopy-power7 wordcopy-ppc32 \ memmove-power7 memmove-ppc + +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-strchrnul-ppc32.o = $(no-stack-protector) +CFLAGS-strchrnul-ppc32.op = $(no-stack-protector) endif diff --git a/sysdeps/powerpc/powerpc64/be/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/powerpc/powerpc64/be/multiarch/dl-symbol-redir-ifunc.h new file mode 100644 index 0000000000..560f57366b --- /dev/null +++ b/sysdeps/powerpc/powerpc64/be/multiarch/dl-symbol-redir-ifunc.h @@ -0,0 +1,27 @@ +/* Symbol rediretion for loader/static initialization code. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _DL_IFUNC_GENERIC_H +#define _DL_IFUNC_GENERIC_H + +#ifndef SHARED +asm ("__mempcpy = __mempcpy_ppc"); +asm ("__strchrnul = __strchrnul_ppc"); +#endif + +#endif diff --git a/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h index 4680092cd8..03f6f12032 100644 --- a/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/powerpc/powerpc64/le/multiarch/dl-symbol-redir-ifunc.h @@ -21,5 +21,6 @@ asm ("memset = __memset_power8"); asm ("__mempcpy = __mempcpy_power7"); +asm ("__strchrnul = __strchrnul_power8"); #endif diff --git a/sysdeps/powerpc/powerpc64/multiarch/Makefile b/sysdeps/powerpc/powerpc64/multiarch/Makefile index c9178223a8..0437a05a89 100644 --- a/sysdeps/powerpc/powerpc64/multiarch/Makefile +++ b/sysdeps/powerpc/powerpc64/multiarch/Makefile @@ -40,3 +40,4 @@ endif # Called during static initialization CFLAGS-strncmp-ppc64.c += $(no-stack-protector) +CFLAGS-strchrnul-ppc64.c += $(no-stack-protector) diff --git a/sysdeps/s390/Makefile b/sysdeps/s390/Makefile index 985b4f25ee..078c0d165d 100644 --- a/sysdeps/s390/Makefile +++ b/sysdeps/s390/Makefile @@ -104,6 +104,11 @@ routines_no_fortify += \ # routines_no_fortify endif +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-strchrnul-c.o = $(no-stack-protector) +CFLAGS-strchrnul-c.op = $(no-stack-protector) + ifeq ($(subdir),wcsmbs) sysdep_routines += wcslen wcslen-vx wcslen-c \ wcsnlen wcsnlen-vx wcsnlen-c \ diff --git a/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h index a128cd05bd..3721f3d95b 100644 --- a/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h @@ -21,11 +21,15 @@ #include #include +#include #define IFUNC_SYMBOL_STR1(s) #s #define IFUNC_SYMBOL_STR(s) IFUNC_SYMBOL_STR1(s) +#ifndef SHARED asm ("memset = " IFUNC_SYMBOL_STR(MEMSET_DEFAULT)); asm ("memcmp = " IFUNC_SYMBOL_STR(MEMCMP_DEFAULT)); +asm ("__strchrnul = " IFUNC_SYMBOL_STR(STRCHRNUL_DEFAULT)); +#endif #endif diff --git a/sysdeps/s390/string-bitops.h b/sysdeps/s390/string-bitops.h new file mode 100644 index 0000000000..286d8975e5 --- /dev/null +++ b/sysdeps/s390/string-bitops.h @@ -0,0 +1,27 @@ +/* Zero byte detection, define whether to use stdbit.h + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* s390x support static-pie and the libgcc implementation for + __builtin_clzl/__builtin_ctzl might access extern data that is not marked + as hidden, which creates additiona GOT access that is used before + self-relocation. */ +#if __ARCH__ > 6 +# define HAVE_BITOPTS_WORKING 1 +#else +# define HAVE_BITOPTS_WORKING 0 +#endif diff --git a/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h index ffe1eee87d..1a76efd542 100644 --- a/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h @@ -19,6 +19,9 @@ #ifndef _DL_IFUNC_GENERIC_H #define _DL_IFUNC_GENERIC_H +#ifndef SHARED asm ("memset = __memset_ultra1"); +asm ("memcpy = __memcpy_ultra1"); +#endif #endif diff --git a/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h index ffe1eee87d..1a76efd542 100644 --- a/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/sparc/sparc64/multiarch/dl-symbol-redir-ifunc.h @@ -19,6 +19,9 @@ #ifndef _DL_IFUNC_GENERIC_H #define _DL_IFUNC_GENERIC_H +#ifndef SHARED asm ("memset = __memset_ultra1"); +asm ("memcpy = __memcpy_ultra1"); +#endif #endif diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 0b86be0d9a..6bc7d7ba47 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 @@ -458,6 +463,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/dl-mmap.h b/sysdeps/unix/sysv/linux/dl-mmap.h new file mode 100644 index 0000000000..f786be0930 --- /dev/null +++ b/sysdeps/unix/sysv/linux/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/unix/sysv/linux/i386/dl-mmap.h b/sysdeps/unix/sysv/linux/i386/dl-mmap.h new file mode 100644 index 0000000000..944f7deb27 --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/dl-mmap.h @@ -0,0 +1,38 @@ +/* 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 +#include + +/* 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 + +static inline void * +_dl_mmap (void *addr, size_t len, int prot, int flags) +{ + return (void *) MMAP_CALL (mmap2, addr, len, prot, flags, -1, 0); +} + +#endif diff --git a/sysdeps/unix/sysv/linux/i386/raise_direct.c b/sysdeps/unix/sysv/linux/i386/raise_direct.c new file mode 100644 index 0000000000..982694eb44 --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/raise_direct.c @@ -0,0 +1,26 @@ +/* Send a signal to a specific pthread. Stub 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 ssert()) 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 1d26966ded..71074425d4 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -8,5 +8,12 @@ sysdep_routines += \ memset-vector \ # sysdep_routines +# Called during static library initialization, so turn stack-protection +# off for non-shared builds. +CFLAGS-memset-generic.o = $(no-stack-protector) +CFLAGS-memset-generic.op = $(no-stack-protector) +CFLAGS-memcpy-generic.o = $(no-stack-protector) +CFLAGS-memcpy-generic.op = $(no-stack-protector) + CFLAGS-memcpy_noalignment.c += -mno-strict-align endif diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/unix/sysv/linux/riscv/multiarch/dl-symbol-redir-ifunc.h new file mode 100644 index 0000000000..4e18eb960f --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/dl-symbol-redir-ifunc.h @@ -0,0 +1,26 @@ +/* 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 ("memcpy = __memcpy_generic"); +#endif + +#endif diff --git a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h index 04b6c1e6a3..28a63837ec 100644 --- a/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h +++ b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h @@ -44,6 +44,39 @@ asm ("memset = " HAVE_MEMSET_IFUNC_GENERIC); asm ("memcmp = " HAVE_MEMCMP_IFUNC_GENERIC); + +#if MINIMUM_X86_ISA_LEVEL >= 4 +# define HAVE_MEMPCPY_IFUNC_GENERIC "__mempcpy_evex_unaligned" +#elif MINIMUM_X86_ISA_LEVEL == 3 +# define HAVE_MEMPCPY_IFUNC_GENERIC "__mempcpy_avx_unaligned" +#else +# define HAVE_MEMPCPY_IFUNC_GENERIC "__mempcpy_sse2_unaligned" +#endif + +asm ("__mempcpy = " HAVE_MEMPCPY_IFUNC_GENERIC); + + +#if MINIMUM_X86_ISA_LEVEL >= 4 +# define HAVE_STRCHRNUL_IFUNC_GENERIC "__strchrnul_evex" +#elif MINIMUM_X86_ISA_LEVEL == 3 +# define HAVE_STRCHRNUL_IFUNC_GENERIC "__strchrnul_avx2" +#else +# define HAVE_STRCHRNUL_IFUNC_GENERIC "__strchrnul_sse2" +#endif + +asm ("__strchrnul = " HAVE_STRCHRNUL_IFUNC_GENERIC); + + +#if MINIMUM_X86_ISA_LEVEL >= 4 +# define HAVE_STRLEN_IFUNC_GENERIC "__strlen_evex" +#elif MINIMUM_X86_ISA_LEVEL == 3 +# define HAVE_STRLEN_IFUNC_GENERIC "__strlen_avx2" +#else +# define HAVE_STRLEN_IFUNC_GENERIC "__strlen_sse2" +#endif + +asm ("strlen = " HAVE_STRLEN_IFUNC_GENERIC); + #endif /* SHARED */ #endif From patchwork Fri Jan 30 12:21:14 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 129279 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 3FE484BA2E2B for ; Fri, 30 Jan 2026 12:26:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3FE484BA2E2B 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=lPu/xeSA 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 99D074BB3BC8 for ; Fri, 30 Jan 2026 12:22:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 99D074BB3BC8 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 99D074BB3BC8 Authentication-Results: server2.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=1769775779; cv=none; b=jn59AOXW9+K9zvWCEd6rkhyUl+uWXOuXfqQy7Sqis9vgyFAt/63KKMu88TtimbAwqSJUHLWiOjL7l1UptQp9AI/U0IN7YL1Gz7ZamB0A4EyK0R9ZD3wwxdy204StiERoIrAFUvYLcoG0Of3QdTyn0VHT9GC/hjebAT6Qnd/ti/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1769775779; c=relaxed/simple; bh=SblWQ9wBUEEgpzZYcIIH1KcUUycz1XJ+ibnfpd8oBEo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=mchKQpUHi+bvY77puNPzXInpLsrhFIr6wjBwa6T/LvkQfjaJ7e0L1iZposwblZQSEdRB2m5+MmjKUHJKgQ6lFsr0tBK0mS43pKuh8h57zkB1ld14woAeoakA8RN6LR745WUi0DbXIwZt5oB9ZRMDPEeGAv6JUt8yh50G2ztrCIs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99D074BB3BC8 Received: by mail-dl1-x1234.google.com with SMTP id a92af1059eb24-12460a7caa2so3062200c88.1 for ; Fri, 30 Jan 2026 04:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1769775778; x=1770380578; 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=hkbfkaquc47MWZtYoE/HaAKPnhd5e1zPgR/25TPZspA=; b=lPu/xeSAP0G3YS0Kk5HR5VtURAnS+Z+9kH792sm3My7AolSKZG2hSR2DKW02tOd+kU qBvAl38rlHI+ArdmSf41+4kxkAP31oBdkvX3kGZ03kEUcQ4WLlqw7DkmLdSMfkY/n8sq y2G2gi9/TIyNCtr7ZEO2EucAD5b4mYj87UkKH3ibj2ltP0Yk/mTuqhxzRVlZnEKG6u+H yUxggJIZs74yapLXi0MEYHFEbfZWAeEO+DcG9i1v+t2zeyv4hkkka64e5z2L1EVr5T/b C+Cc2qxh4eCok/kEeapsEERydXMrIxRicGtv0bfkQu+4e+Lc19bdRdaXrYmnIhFjepUU kt/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769775778; x=1770380578; 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=hkbfkaquc47MWZtYoE/HaAKPnhd5e1zPgR/25TPZspA=; b=qim0fXAmVwiYVllxAWtDAdO/tYOjM7kRDzDgBsjfNpsCdF/3EIvHlhtcUYHLYW5ezQ lw9D3iwFi9F3DP4CkwZEZFVr71YQBUs37RvvtqBf7peWNJKo5y9HEe7bkirtooF9q65m tDReqOJP8h04CuAb/XXpPh7zPCdL+nTic3Wc3vZjsswRL6LQ8lsWwdPpmG/rVEaoti0X K83ZNSLTae8o3732JlQrf/Xm6h2b74OERyzOFFFGevxYK8w5zIkAo3AuQWS6z98rjeQs Cgqv7biKHSQUW/ww44EV+bDzUbIyAYfzsqF01xubk6g3T+P2og5Bt+sfCvbOoDknZyX7 ExTg== X-Gm-Message-State: AOJu0YxSRiuyJ8frIUa4q12EzC2ubmYZGZxK7fNK4hUKn0Ry2MkBLPkX g+S4MpOZF9liKgaKhGg84h8ae/Ytv9acdW1Hk51FXD+mBjN5pKXdloEowQblVuuMZN5aaaxAQT1 5wRI3 X-Gm-Gg: AZuq6aJV43+808VGZ5ndP46XHKoCuXwEqtOXa+DBUI1qyBY+iWG3E5mBP8t5/PDOouo UBbxukXnkUxTbNqm7koFqpqUz2kM4gBQ48mrSPAS4B0ka4S1cTwrcRa3kCNeT8DP5DSaJS4hYba kXMARyglkKERw8dzp7s4yjywhqK3fFxhuDmffZY5wHPkqSKEA8hqxtIiGeN0H3giDbly26eeAqm 9p6GNmlOYqZYK0phbg5SUfqcIyuuPukZe9yQNPEi3o9ZlUlhsusvLKac8Xqjhr2OU2/9mddJW6K GGwrjBI1KUjoVleFJE20yg1hnyG5XPi43HLim6IbJn9HQ7bOLBKXtSvDX34OYuCBzK07vdV4vBb 7e5YyMhAXguM4RNB0M6NTwUtrgoHcqT2dsMuiL8Wl/l5j6dSu84vhzNFjoT7sGYgS8n8F+gbcCh agGjVjSFBxkg3gWEDhTNaQ84Ls X-Received: by 2002:a05:7022:2214:b0:124:9fd8:4ba2 with SMTP id a92af1059eb24-125c0f8c4d0mr1347559c88.9.1769775778055; Fri, 30 Jan 2026 04:22:58 -0800 (PST) Received: from ubuntu-vm.. ([187.56.133.167]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-124a9e0304bsm10047043c88.14.2026.01.30.04.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Jan 2026 04:22:57 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH v5 5/5] elf: Allow RPATH/RUNPATH for static-pie Date: Fri, 30 Jan 2026 12:21:14 +0000 Message-ID: <20260130122240.4128717-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> References: <20260130122240.4128717-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The 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. --- 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 0fb27132e5..7956849608 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1201,7 +1201,11 @@ tests += \ # tests tests-static += \ tst-pie-address-static \ + tst-pie-rpath-static \ # tests-static +modules-names += \ + tst-pie-rpath-mod \ + # modules-names ifeq (yes,$(aligned-65536)) tests += tst-pie-bss-static tests-static += tst-pie-bss-static @@ -3550,3 +3554,10 @@ $(objpfx)tst-assert-startup-static.out: $(objpfx)tst-assert-startup-static grep -q 'Fatal glibc error: tst-assert-startup-static' $@ \ && grep -q '^status: 134$$' $@; \ $(evaluate-test) + +LDFLAGS-tst-pie-rpath-static += -Wl,-rpath,\$$ORIGIN/tst-pie-rpath-static-subdir +CFLAGS-tst-pie-rpath-static.c += -DPFX=\"$(objpfx)\" +ifeq (no,$(build-hardcoded-path-in-tests)) +LDFLAGS-tst-pie-rpath-mod.so += -Wl,-rpath,$(rpath-link) +endif +$(objpfx)tst-pie-rpath-static.out: $(objpfx)tst-pie-rpath-mod.so diff --git a/elf/dl-load.c b/elf/dl-load.c index 7355eef8e7..c5ea40fa4a 100644 --- a/elf/dl-load.c +++ b/elf/dl-load.c @@ -1269,7 +1269,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd, if (l->l_ld != NULL) l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr); - elf_get_dynamic_info (l, false, false); + elf_get_dynamic_info (l, false); /* Make sure we are not dlopen'ing an object that has the DF_1_NOOPEN flag set, or a PIE object. */ diff --git a/elf/dl-reloc-static-pie.c b/elf/dl-reloc-static-pie.c index bdff2b5ee2..22acd9bb4f 100644 --- a/elf/dl-reloc-static-pie.c +++ b/elf/dl-reloc-static-pie.c @@ -69,7 +69,7 @@ _dl_relocate_static_pie (void) /* Read our own dynamic section and fill in the info array. */ main_map->l_ld = ((void *) l_addr + elf_machine_dynamic ()); - elf_get_dynamic_info (main_map, false, true); + elf_get_dynamic_info (main_map, false); # ifdef ELF_MACHINE_BEFORE_RTLD_RELOC ELF_MACHINE_BEFORE_RTLD_RELOC (main_map, main_map->l_info); diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h index 46faa34acf..9591d00d59 100644 --- a/elf/get-dynamic-info.h +++ b/elf/get-dynamic-info.h @@ -26,8 +26,7 @@ #include static inline void __attribute__ ((unused, always_inline)) -elf_get_dynamic_info (struct link_map *l, bool bootstrap, - bool static_pie_bootstrap) +elf_get_dynamic_info (struct link_map *l, bool bootstrap) { #if __ELF_NATIVE_CLASS == 32 typedef Elf32_Word d_tag_utype; @@ -128,7 +127,7 @@ elf_get_dynamic_info (struct link_map *l, bool bootstrap, #endif if (info[DT_RELR] != NULL) assert (info[DT_RELRENT]->d_un.d_val == sizeof (ElfW(Relr))); - if (bootstrap || static_pie_bootstrap) + if (bootstrap) { assert (info[DT_RUNPATH] == NULL); assert (info[DT_RPATH] == NULL); diff --git a/elf/rtld.c b/elf/rtld.c index 29e7a4ddfa..0299d8bc64 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; @@ -1701,7 +1701,7 @@ dl_main (const ElfW(Phdr) *phdr, if (! rtld_is_main) { /* Extract the contents of the dynamic section for easy access. */ - elf_get_dynamic_info (main_map, false, false); + elf_get_dynamic_info (main_map, false); /* If the main map is libc.so, update the base namespace to refer to this map. If libc.so is loaded later, this happens diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h index 0dba7072d5..58b7712046 100644 --- a/elf/setup-vdso.h +++ b/elf/setup-vdso.h @@ -64,7 +64,7 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)), l->l_addr = l->l_map_start - l->l_addr; l->l_map_end += l->l_addr; l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr); - elf_get_dynamic_info (l, false, false); + elf_get_dynamic_info (l, false); _dl_setup_hash (l); l->l_relocated = 1; diff --git a/elf/tst-pie-rpath-mod.c b/elf/tst-pie-rpath-mod.c new file mode 100644 index 0000000000..719eb41e09 --- /dev/null +++ b/elf/tst-pie-rpath-mod.c @@ -0,0 +1,19 @@ +/* Check if RPATH/RUNPATH is allowed for static-pie. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +int foo (void) { return 42; } diff --git a/elf/tst-pie-rpath-static.c b/elf/tst-pie-rpath-static.c new file mode 100644 index 0000000000..02fb05d2e6 --- /dev/null +++ b/elf/tst-pie-rpath-static.c @@ -0,0 +1,52 @@ +/* Check if RPATH/RUNPATH is allowed for static-pie. + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include + +#define LIBNAME "tst-pie-rpath-mod.so" +#define TESTSUBDIR PFX "tst-pie-rpath-static-subdir" +#define LIBPATH TESTSUBDIR "/" LIBNAME + +static void +do_prepare (int argc, char **argv) +{ + xmkdir (TESTSUBDIR, 0777); + add_temp_file (TESTSUBDIR); + + support_copy_file (PFX "/" LIBNAME, LIBPATH); + add_temp_file (LIBPATH); +} +#define PREPARE do_prepare + +static int +do_test (void) +{ + void *h = xdlopen (LIBNAME, RTLD_NOW); + int (*foo)(void) = xdlsym (h, "foo"); + TEST_COMPARE (foo (), 42); + xdlclose (h); + + return 0; +} + +#include