From patchwork Fri Aug 29 19:53:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 119182 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A0DD73858286 for ; Fri, 29 Aug 2025 19:56:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A0DD73858286 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=SmisvYkS X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by sourceware.org (Postfix) with ESMTPS id 68C223858415 for ; Fri, 29 Aug 2025 19:54:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68C223858415 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 68C223858415 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1033 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497250; cv=none; b=Vf0QADec3OZ5t8g+gCmfJrMBDse8CrnrW14ZMLRucEN8VsG53CrlFM3ZXNNy2sFN1kZToiiSF1mm9qlNe0xF+EhRdKgs0bZG1kBTKUXEK12CBQzjgdzzOijK4Vta0Y17lg2rWZ9G0nH/yLGkV017naZGQvAoDmSYan4xXqOK7AM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497250; c=relaxed/simple; bh=BejZCw4T2izmsBcjrOazQbxe9GHCWQ8Weuv6tqoyCWw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=HvavAk54sFaaAJ2onGtgCJb2Kj7QMWdcUturRTJo6A3WJpEPsN3OdbaWlMYYCaS7Kxqo+I6S8w/Zm/4xng0NvrV3V89D/jnIfKDZz+mu8jv0/xoJ8q8x2qy0JyMVUrmwa9KJ5QlhAZmEmQpFchSyj0l0RX3hoV8nbE5A4zsdbwk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68C223858415 Received: by mail-pj1-x1033.google.com with SMTP id 98e67ed59e1d1-327e5b65e2cso975346a91.2 for ; Fri, 29 Aug 2025 12:54:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756497249; x=1757102049; 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=pmDPdCFnWL6i/l+uJgYaywQMiIAkO5I1riT5VMOS6mc=; b=SmisvYkS/G4O30ZBhm335eKcq6dZbwQf1/HiVgamvULgZHrs9GkWi8KE8+VIcQPbNf JPZY0urFnXeSOf1ZkUyFZf7W5zfop7zAfB80Gg3DYE6E4e8IjZ83bhmrf5YCruKKl3ZR IWGv2CiynKY14vzGqkBjWWUt0sp9gcws2BoOhn8L2aX5RXbdRrXYDGf9YipG2MPm8Jp0 Lqgwksxvd2FEwGdiAOA+hwDsJY6ILC6Kg0UkwV3FddAaNEj3SNRq/lD/Bm/g1h3xPF65 YFMkl1L/HqGzjtHU6h5wlhR010VAKQ8NRIz7cU1cIrL9+9y1ZAGJ3mFQkcMEkDsULJEE p7Pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756497249; x=1757102049; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pmDPdCFnWL6i/l+uJgYaywQMiIAkO5I1riT5VMOS6mc=; b=syceIPt6g0q+fThRwTIohE+hWXqVhytXIJ+CGYhlhMuaaJK6z9dFnW+lnllopwAcDE 2CuTSSsukjHtu6APiCPS2TiT4qE524RkVV+X46Z/QOorzNugRoKX7CZeASSzKNYsXjb0 VQripOjE/bQUm5TQQuXt73ZSJPTskcF1tme9cj83F2YqvvAY5CB8CKuTt7qtNnbo+RRe J+DIy2e/a8ijJFfHyUadQZeOGUrw/2OerJsFhagVNHjxbr49IXkNBPGvcmkaJCTBGPyK xMtMSVEp+zuhs015y1dKpvCYswQSD8JvmVhqNx0nYaOrDqJbJeZotwIlSn7cGR7u5V0m rPQg== X-Gm-Message-State: AOJu0YwSik7ToB4ommdxblsQOS3zoWrXix2f32lFaBhfww2FijHmmolY +1yOxS5/gqhJASBVqsFymXjA31vjhLO83fsStK72Zp8iA5RNDABfRPCZnfpo4g0Ie/xPzPElUCt /Noe1 X-Gm-Gg: ASbGncuaaYD63XhoPLLisjLYwEiT5yWrglcXRRINHgAKm6JnX/hmjFaBfllkBmkAFxQ 5f43Jq90wP8ODQFhE5JTzBwnQL69nJrEB498+FrmltNYM1i9QAua93xJvPlpW6UKAs47BKpbo26 /ZfCxbPu5q30tQGQHDSnHNrp+bVLcB1fGJUAOEE8ZWub2W7FIrHkOJeLZKgAHzlWmuzRR/3YtXZ u4EVNM+XKv3lgSIpIEgwk9cO9x46UDWLIbPN0k4onWE2SxdIdZN9ouHiwLCGzu7rouW0gPwZB28 WofrC91LM4G1gIjUK32NK5QnoVXzkIRBTR1raHXNyXHXug7vLYvmPBRyGmC69lScv8gihPXpPdm AGCzSw2MMIXWx30TzwcBkKUwLR40V3IlMn6as X-Google-Smtp-Source: AGHT+IEMkIDUt8exqxjQToIURXSh0kjBe8JsFIODeL57erP/PhFxV9wdJN/q3YIlWo/RMboWJXyqLA== X-Received: by 2002:a17:90b:258c:b0:325:11d1:1fb with SMTP id 98e67ed59e1d1-32515ee12ffmr38778449a91.6.1756497249080; Fri, 29 Aug 2025 12:54:09 -0700 (PDT) Received: from ubuntu-vm.. ([177.103.118.15]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b4cd3669d76sm2894572a12.49.2025.08.29.12.54.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 12:54:08 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Valery Ushakov Subject: [PATCH 1/5] string: Add fallback implementation for ctz/clz Date: Fri, 29 Aug 2025 16:53:21 -0300 Message-ID: <20250829195401.953674-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250829195401.953674-1-adhemerval.zanella@linaro.org> References: <20250829195401.953674-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 algorithm is based on De Bruijn sequence, and it might be used if the ABI does not want to use libgcc fallback implementation (for instance on statup code where libgcc might be compiled with some options not support at the time, like stack protector). It is disable by default, so no target is affected. --- sysdeps/generic/math-use-builtins-bitops.h | 2 + sysdeps/generic/string-fzi.h | 73 ++++++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 sysdeps/generic/math-use-builtins-bitops.h diff --git a/sysdeps/generic/math-use-builtins-bitops.h b/sysdeps/generic/math-use-builtins-bitops.h new file mode 100644 index 0000000000..203f1bb70b --- /dev/null +++ b/sysdeps/generic/math-use-builtins-bitops.h @@ -0,0 +1,2 @@ +#define USE_CLZ_BUILTIN 1 +#define USE_CTZ_BUILTIN 1 diff --git a/sysdeps/generic/string-fzi.h b/sysdeps/generic/string-fzi.h index 3c1028d1ec..beb7204fb9 100644 --- a/sysdeps/generic/string-fzi.h +++ b/sysdeps/generic/string-fzi.h @@ -22,23 +22,84 @@ #include #include #include +#include static __always_inline int -clz (find_t c) +ctz (find_t c) { +#if USE_CTZ_BUILTIN if (sizeof (find_t) == sizeof (unsigned long)) - return __builtin_clzl (c); + return __builtin_ctzl (c); else - return __builtin_clzll (c); + return __builtin_ctzll (c); +#else + if (sizeof (find_t) < 8) + { + static const char debruijn32[] + = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, + 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 }; + return debruijn32[(c & -c) * 0x076be629 >> 27]; + } + else + { + static const char debruijn64[] + = { 0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, + 62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, + 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, + 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 }; + return debruijn64[(c & -c) * 0x022fdd63cc95386dull >> 58]; + } +#endif } static __always_inline int -ctz (find_t c) +clz (find_t c) { +#if USE_CTZ_BUILTIN if (sizeof (find_t) == sizeof (unsigned long)) - return __builtin_ctzl (c); + return __builtin_clzl (c); else - return __builtin_ctzll (c); + return __builtin_clzll (c); +#else + if (sizeof (find_t) < 8) + { + c >>= 1; + c |= c >> 1; + c |= c >> 2; + c |= c >> 4; + c |= c >> 8; + c |= c >> 16; + c++; + return 31 - ctz (c); + } + else + { + unsigned long long int c0 = c; + find_t y; + find_t r; + if (c0 >> 32) + y = c0 >> 32, r = 0; + else + y = c0, r = 32; + if (y >> 16) + y >>= 16; + else + r |= 16; + if (y >> 8) + y >>= 8; + else + r |= 8; + if (y >> 4) + y >>= 4; + else + r |= 4; + if (y >> 2) + y >>= 2; + else + r |= 2; + return r | !(y >> 1); + } +#endif } /* A subroutine for the index_zero functions. Given a test word C, return From patchwork Fri Aug 29 19:53:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 119184 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8065A3858409 for ; Fri, 29 Aug 2025 19:59:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8065A3858409 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=sb8mgZ8m X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 7C75C385840D for ; Fri, 29 Aug 2025 19:54:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7C75C385840D 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 7C75C385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497252; cv=none; b=Fb+t/MXiEozEU+/pGB+2zy6T9Uglhd1JaC4fR2ADeh7ahvrgdISzuM+DxBljk7ThB106i6kAse/aGVpkf5wJQUeBJ1S1qXK31r/OmYVuXqJe8oM7TBYvr89/aud0S/nrAkmUoZXZq1gj/ucKPciHefwBrLBCitH+treJKJN7wXw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497252; c=relaxed/simple; bh=IGDmPDMMnrnM+JHI89xgPsXgOuFEHidLWPaHPZQqN+M=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uqyT+lLDxENH9nwby6kfbnWRhEL4i/dT1U2NMM+ORKm5EW03++k3wztcq3j26p/vlTYNhQO2lIPm7ELQuKQSx5Qii1VyEx9Svyba06eTvl8vZVvRPe8pL0xPWLCasOom09kVJRwng1SaPeUxjPOL5pM3Wou1b6klx/XUZW1pjgM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C75C385840D Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7722d6cc437so1008221b3a.0 for ; Fri, 29 Aug 2025 12:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756497251; x=1757102051; 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=jSO4+fHAICgyEzwdDh6VcZFh42NmrUZpm3/HcMBsk4k=; b=sb8mgZ8meBYouePoa0qe0TSxMgiasFpROkz5TUZO/61wBugUbzxFAt/iIQqVvqGDqw NvqUOXXIufVIYG7NbHUOdzKz13drd8xHFm50A7jIP8jEdp2bMCdL+H1SeumirRAff0pF REvqJDOQ7Zu8p2yIDHEJXILbbd4p0rRUkkgS3uJ3c2hIa3yJEVoYWdFp7J2mKxSv0rFw zW84XroSmcWU0pcigz4m8ekvDDwU/xTDdLeBqdR6fNBwp4YpJLcC94rRsHdYiQUX+W4/ 8xYJSRnV+0xvQOn1YalaFKVh8pUa+aA8zj+DEO6oKFcYZECkm0wDgM6bm/iMo0YLV+2m J8rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756497251; x=1757102051; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jSO4+fHAICgyEzwdDh6VcZFh42NmrUZpm3/HcMBsk4k=; b=H4FoJ6DhGLBCtmg3rA9FkF+2IrnbXbU9vTFEtMOmih1JU8XK5Emdqi7RdHhH1/A5tn gOQMRR+2sbkC6W/UhW+UZtzL8sfQk/oo11NQP8pu2RByBnHAmwd4kB9T8Zy9PDCu4hIR +wVUpjibIPLHigVEts96pFYD/BgXTZXEwy3xopSa3oum8/9XmlbjpVG49HjgJUGt9B39 HypjQlK1TrOFzsOZ0a066ekEIBQ7ilLh2vLjyvDzoWb3mRZ8gxsUBHHi3HHu8IVfJ7T7 OTd6mFZSKGaQlP4btxFFxaTjtqIzNvCRiRHZt8JMT2qeikO1v5rjOlpmooEJQs8bJZMj vREg== X-Gm-Message-State: AOJu0YxEdsQ7ywHRGrsu9vd/E5EhnJ057XlonhfqYxk3kzYK9cgZ/f9Q zfCj3DwzvztsYlPDuyt0/pWjoDU7Qclk3l3w3b9gku2M56alp+RdC4uS+xtb9agy3sOemmRCuvL c/EUc X-Gm-Gg: ASbGncv+ksZJa4ojehi6hR6hNFnqf1wSItB78PXevpgreImflG2qmuoWcK1K9xx7gDy iTx5jwOVXibglSCEEOho125qm8RIPNTYZtt8E4eqRHD9Zfcp+xUAmIibJ626PTM28fqZ5i9P1VU eFNxmo6rrrl08TzM4mD5DOua4Hvqgf+0uIL38HBNRYeaCnIWpVzEpZe2olINsg9YnbnOTeBpoOc jGdNZUjPoIs6IokGOyXD6RjHjSghbaGnrcEmYZzLdRBh2FzFMjsvSwXYASI1nuOe9xBA8kpca3E g5NIpQ0T1hjZGvq0vPo9WBp/WAwecHhg6UAyJSfN9MPspBU/+TcLyKWNT1zNUbisGNTxAG9jvyA MbFHvCyWZYX3vI35wqlGNlPo9S0E/wtbHjAUaE0ncT2fjh7s= X-Google-Smtp-Source: AGHT+IE1vq+Oi9Wo1wvw4X4Ts7/q2cNt3VSbOosRnOAiwiyl6VH4Y6gRkcPGHfpwUS9BdjvvCS7EYA== X-Received: by 2002:a05:6a20:7490:b0:243:be3f:9b9c with SMTP id adf61e73a8af0-243d50934a5mr583916637.7.1756497251187; Fri, 29 Aug 2025 12:54:11 -0700 (PDT) Received: from ubuntu-vm.. ([177.103.118.15]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b4cd3669d76sm2894572a12.49.2025.08.29.12.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 12:54:10 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Valery Ushakov Subject: [PATCH 2/5] nptl: Add __pthread_kill_self Date: Fri, 29 Aug 2025 16:53:22 -0300 Message-ID: <20250829195401.953674-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250829195401.953674-1-adhemerval.zanella@linaro.org> References: <20250829195401.953674-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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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/pthread.h | 1 + nptl/Makefile | 1 + nptl/pthread_kill.c | 15 +-------------- nptl/pthread_kill_self.c | 39 +++++++++++++++++++++++++++++++++++++++ sysdeps/posix/raise.c | 2 +- 5 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 nptl/pthread_kill_self.c diff --git a/include/pthread.h b/include/pthread.h index 819bf3f235..103c5c433b 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -21,6 +21,7 @@ libc_hidden_proto (__pthread_barrier_wait) extern void __pthread_initialize (void) __attribute__ ((weak)); extern int __pthread_kill (pthread_t threadid, int signo); +extern int __pthread_kill_self (int signo) attribute_hidden; extern pthread_t __pthread_self (void); diff --git a/nptl/Makefile b/nptl/Makefile index e6481d5694..8b18ca98a9 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -131,6 +131,7 @@ routines = \ pthread_keys \ pthread_kill \ pthread_kill_other_threads \ + pthread_kill_self \ pthread_mutex_cond_lock \ pthread_mutex_conf \ pthread_mutex_consistent \ diff --git a/nptl/pthread_kill.c b/nptl/pthread_kill.c index 3938e3f8cd..3bc7f8a5a8 100644 --- a/nptl/pthread_kill.c +++ b/nptl/pthread_kill.c @@ -29,20 +29,7 @@ __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; - } + return __pthread_kill_self (signo); /* Block all signals, as required by pd->exit_lock. */ internal_sigset_t old_mask; diff --git a/nptl/pthread_kill_self.c b/nptl/pthread_kill_self.c new file mode 100644 index 0000000000..bc9fa60619 --- /dev/null +++ b/nptl/pthread_kill_self.c @@ -0,0 +1,39 @@ +/* Internal function to send a signal to itself. + Copyright (C) 2025 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 +__pthread_kill_self (int signo) +{ + /* 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); + pid_t pid = INTERNAL_SYSCALL_CALL (getpid); + int ret = INTERNAL_SYSCALL_CALL (tgkill, pid, tid, signo); + return INTERNAL_SYSCALL_ERROR_P (ret) ? INTERNAL_SYSCALL_ERRNO (ret) : 0; +} diff --git a/sysdeps/posix/raise.c b/sysdeps/posix/raise.c index da3f11ccf2..3b426d5708 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 = __pthread_kill_self (sig); if (ret != 0) { __set_errno (ret); From patchwork Fri Aug 29 19:53:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 119183 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ACCB83858410 for ; Fri, 29 Aug 2025 19:56:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ACCB83858410 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=y0oTpm+q X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id D28843857BA3 for ; Fri, 29 Aug 2025 19:54:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D28843857BA3 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 D28843857BA3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497255; cv=none; b=dmpQ/YMiLcvReHL7Em5isNiRasyHUnUywSo3wbzqC0Ko0/u0OePo8U9WlG4wjqngI5MhSLwJ3hF8PtT+XAVGapVOJ54VlcA8Rsk8BJrmBbG74qF3rdHf47FwwqFOcJHcDY9awKMQfXwF3CAsS3gQpVdQsl/jfa04F7kiJ12wshw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497255; c=relaxed/simple; bh=5t/ommEHm/2ZVimYb7f6d7B3xp7rtN1Gr8mcIYy2btM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Nmng8I0EwzpOL3SJCjntRHq4NUXyxnwX2XKkqLdMgxtb7fgFMKQU0L9nh9Da8k5Wz9z55AyLtoazUaNYCKnC4DySrSbiSWX+oiw2jcNFh2WbF5S9CyRu/1MDowbVE0LAeALwsr2syD0Y45DUuh0oiUIYpO6z77idXUfVvqZI8yE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D28843857BA3 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-7722c8d2694so942364b3a.3 for ; Fri, 29 Aug 2025 12:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756497253; x=1757102053; 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=TuHErDX0CGnl2V1wJnoX/NQtUrpQ9FfOQpp+XYlEUS0=; b=y0oTpm+q51+g0ZTsIvklEftq+RRta/2JZ3p0psN3Y41uEK3CQtFURCtmv6jM/yjZDo Ls/OYpBn/7FAeRFws/MygRVTf6FHoEX0tkODpgOQr5tMqj1h8K/OrNrzo59E9aAuij8P t4EN/WIRfxMHbo+QCL8xCyTsxMpzaoNRf+FDiV71C5RgnaXNOVbGtP4mQ4mgBP9egcZQ mk2kmTtnCxfRuvjOq4R0HW03YgevJrlUidQbPB5jY78STeahZhfUWzEu4vzN8P0c74jf JisYx2TcQT2aNi/1GClctc/UW020CEy013JuIbDD9tp1XQznC24eo/QOZ4r9AJ978GPO x6PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756497253; x=1757102053; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TuHErDX0CGnl2V1wJnoX/NQtUrpQ9FfOQpp+XYlEUS0=; b=VM/i7hnw7WrY51aeNhTpQQWubgX9PRVSSx4WkxiCDpXrv8fE5bBKPLINZzVOd5/P1c t2oJxN55J3S6tosyK06OTaMkqHkkLWs5dInrMw6sLB87M/FATCiQ62jTU6pNPnJWscKq 2R8G7p3BlzEFV1IOLzjg0kLqMXI5CDdDUFTRGRMsGWOmqT2MCdJkmcHGpmTl3OYBZqrP jljLLnP8y0SPB1Hqb0RjFT4ggkR9EL6eV1xECpWNkDsDmkmFEscZPdHuYUF9JbX904Df 2JHASuGhit8viV5/2MS9CEVmPTlT1LR7VFK27nkCQtdL58iTCQz6qFECukRlZpLowYol QkMg== X-Gm-Message-State: AOJu0Yzv8rQvt2CGQgtmJNquuTnPV3Ugl9NEWpH40f6i13j1SWWUZOed Nxg++uhlgcZeMue9LVR8LB53FVnfja5MTTb7Pk7wmM6DjDThOVVkkKLrKsoOV5SS8JikJw5AffA YV/SD X-Gm-Gg: ASbGnctDikHtJpzfGP71zWCA/7DMj1V+jU6TNrUGRoHs+wdEekmYKnmNZ94ugFCcyIc 6FxPW3p9quhw0g9w34tH7AR4CpyqfnHu00EW0NvXHsv7gTRZcm4YmHWSZw36GyXdJxKsIFkQ94w Yb4oxju9I2IClauZE3r+90lSCj12oUeEPzImal34RokUEkV2ondeHMm4Un2iRzMJA8tpMBTsEcu L5MMlP/kjPW667uGuuPL3nkNRuZkHlBU3GlItF7T/FKdlucy3hXUG7eYil7cqkNLDbEk+YjaTJZ SX4I6Iefz7ulyvVqfziIwPNI2pQpIteIob5YrOU9D+pHf1TtUNA0f01Wi/Y/BtBEVB9i8W0xi6o SaurqBpvILeJlDLu0Kd7Qg4fQgs2fxZBjzxvRDlzidCQTEkY= X-Google-Smtp-Source: AGHT+IG+WzQ+oS2of5LnbLoiO8MAFuljdiihJCqy0nn/E3NvouqojXXkqZLdkNyq7Ak5/9YrCqCYAw== X-Received: by 2002:a05:6a20:7d8a:b0:222:c961:af1d with SMTP id adf61e73a8af0-24340b01e14mr41408447637.8.1756497253233; Fri, 29 Aug 2025 12:54:13 -0700 (PDT) Received: from ubuntu-vm.. ([177.103.118.15]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b4cd3669d76sm2894572a12.49.2025.08.29.12.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 12:54:12 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Valery Ushakov Subject: [PATCH 3/5] Use _dl_writev on __libc_message_impl Date: Fri, 29 Aug 2025 16:53:23 -0300 Message-ID: <20250829195401.953674-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250829195401.953674-1-adhemerval.zanella@linaro.org> References: <20250829195401.953674-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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 an negative errno in case of failure. This keeps the required semantic on not setting errno in case of failure and allow remove the Linux libc_fatal.c implementation. It also makes is simple to use writev syscall during process startup, specially on i386 where it requires to disable the vDSO usage. --- {elf => sysdeps/generic}/dl-writev.h | 18 +++++++------- sysdeps/posix/libc_fatal.c | 15 ++++++------ sysdeps/unix/sysv/linux/dl-writev.h | 13 ++++------ sysdeps/unix/sysv/linux/libc_fatal.c | 36 ---------------------------- 4 files changed, 21 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 cf22367a82..37f2c24cbe 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 6f75197e96..c36bd39c13 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 *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 f3fa5c777b..0abe28202f 100644 --- a/sysdeps/unix/sysv/linux/dl-writev.h +++ b/sysdeps/unix/sysv/linux/dl-writev.h @@ -19,19 +19,16 @@ #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); + int r = INTERNAL_SYSCALL_CALL (writev, fd, iov, niov); + return INTERNAL_SYSCALL_ERROR_P (r) ? -INTERNAL_SYSCALL_ERRNO (r) : r; } diff --git a/sysdeps/unix/sysv/linux/libc_fatal.c b/sysdeps/unix/sysv/linux/libc_fatal.c deleted file mode 100644 index 72d7328a20..0000000000 --- a/sysdeps/unix/sysv/linux/libc_fatal.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Catastrophic failure reports. Linux version. - Copyright (C) 1993-2025 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 Aug 29 19:53:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 119186 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 762653858409 for ; Fri, 29 Aug 2025 20:01:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 762653858409 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=pfCd2UtS X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by sourceware.org (Postfix) with ESMTPS id 1A4033844069 for ; Fri, 29 Aug 2025 19:54:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A4033844069 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 1A4033844069 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::431 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497257; cv=none; b=MgesWxE1vXBabXjxq5Q+EtcYfcuM9394bL1uq+zpOqZmeLBdWzvt4W5jk3SMpinmm8otPO+pAIeTjpFbgzLmdX0Fl5/fUSlStM5pwYRbhDYKV8UrKgvJ6EsaqLfxK4dla1oR9f8uAIBPkB8P5ii41aBp1x/038rPcTFJ695Cp44= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497257; c=relaxed/simple; bh=DFDMUS+9df83cT6r9h4xBrXecX0hHH0W5lRPb3x9iZI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pEPDZlX9j31jUulEQc71Wc4Bo0g3KNPkqim9Iv3fsAgljdCs9wo80H8ltFS4a43U7NfLKujrh+R7AIsydn1qFm9kirp8q7jt1VYaqD/nbEhVX8aE7fTOLpmFG7sQrtW0ZHO4mVCrCXKnioq9ipzmmJBi0QWil0LRAy4so8+n3gg= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A4033844069 Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-772301f8a4cso1114108b3a.3 for ; Fri, 29 Aug 2025 12:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756497256; x=1757102056; 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=NOn+4w5d7m7sAqyIZinRx0SuGRDSgk339lEpESB5cQo=; b=pfCd2UtSdKpgVwVUwYmjy0Iv062ngSFFMXonii4bCeSO0Rv/5TYl7U0VRUl/4Rww/Z z6FmcgoKvs3ySC3mDGaWfGzu5X+2mnd1G7TyH4gOUUocIP5JhEOMnG/R/Z6gsyGIUTl2 h2bZEHm8Y9G+p8I7jhz4QF96eOg2QZeDDr91+zvOwR2GjBhuL1DAXR1mvylRQMjVR3b+ ///74MfpY3CRg/BXcPrdOTCs0gLOPTzXqHI4NE4iHcBMHNs+3Kz4HKfmcLxZ6XjMhJF/ jQ/tOEy8LABmkyB2DRJ7aa9HvxN885ObkiJXYYsOs35yx3KnGZN414HUPTFzUHyDR8OD PzfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756497256; x=1757102056; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NOn+4w5d7m7sAqyIZinRx0SuGRDSgk339lEpESB5cQo=; b=TzSGMnynMldLCHvLkGxiDIJCD5ICY1brvCufX8gQr9Ag60AiOSluZOCP4vAcAEpIIO nAQT58nLOSqENDAXOi+Na32tgiTvQruR+H1xsjw/bxlEgaO4UG1IrclRs17kBHQoZyzW k2yH7N3lrb9C1RxGe68oDOAWh4zeMx/NPPO1WBe4v2gPnqSms5VaxdH2aHSRMTkQie5e /FtOqGCdo8+7PoPTYdA/50I3d0v0zwNFZbEoWxE8oAPbdAS0ClGqq7Rmju/uM2syH+5b +1mfB6pWL0tnqOiMA8GG6ggphNUWVHfYl7I1p/7uZ+Oa1QZchL8DdZIey6hNho44DlHA xapQ== X-Gm-Message-State: AOJu0Yz0wgApzqcvrCvO/d0N34nPDBGNB1gJOGNN2GxXi2b0F0FF4GTh seqP8ea+RxnmSQrs5xChybypdWMZBgFTa/Kuj70+XOmt5Ef+RB0Pr4SNougeqpQ7qpoWNwhQa7h GLB/X X-Gm-Gg: ASbGncuDh4cUQRl+5UD4/OPlxpBIuIJ/7MthKv7VaEHXyJ4hhjOl/L/H5PzMdmVQBg4 mGtYHjWJEYudpSqvsuCx/W8t5ZEgJfK4fsOKeUxLcMgwI5juYQ4XWzcBHejwSh8NAZgqifiQHaW qojKX5sDdfH4Ue9XTqDJVqmE78wqsgHUI9xLMzP0LnH+3eTkNIz7XzgvZ9Q5XGZ3EdIlFOuCQ0V x7QgWa729SK0fz9EXbAIwzUorgUnygsn0omPBdPN1+v0sNFyD31vh68D4uO3mKgdKnfW+c1C0BH UX3Y4etMA8LttNjUr08/ZcWFlzuXjw2rhNcfv0VlVjLZMvVt4dybTz5fSIUJ9/z3QNH/PUgkQlC DHfUHcwoogp8IpjEMyPwuINnRZFgAu0JpSRPx X-Google-Smtp-Source: AGHT+IGPKX52clw8HkIm49E/BscO3OtxheURW4+zTRLhEMWEtKxC++BJ3JrblvTlJ7oHmCsK8TIxrg== X-Received: by 2002:a05:6a20:430d:b0:243:b565:8c2 with SMTP id adf61e73a8af0-243b5650ad2mr11552428637.36.1756497255537; Fri, 29 Aug 2025 12:54:15 -0700 (PDT) Received: from ubuntu-vm.. ([177.103.118.15]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b4cd3669d76sm2894572a12.49.2025.08.29.12.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 12:54:15 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Valery Ushakov Subject: [PATCH 4/5] Fix assert during static startup Date: Fri, 29 Aug 2025 16:53:24 -0300 Message-ID: <20250829195401.953674-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250829195401.953674-1-adhemerval.zanella@linaro.org> References: <20250829195401.953674-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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 pthread_kill_self.c and mmap call is added that disables I386_USE_SYSENTER. On s390x, the generic strchrnul uses the C generic version (string/strchrnul.c), which in turn uses the ctz/clz macros that issue the libgcc, and it might be incompatible to be called during process initialization (due to the stack protector being used). A ath-use-builtins-bitops.h is provided to inline both clz/ctz. Creating a test case is challenging. For static-pie, the assert is only called for ill-formatted 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, and powerpc. --- assert/Makefile | 5 +++ elf/Makefile | 16 ++++++++ elf/tst-assert-startup-static.c | 35 +++++++++++++++++ libio/Makefile | 5 +++ nptl/Makefile | 5 +++ signal/Makefile | 5 +++ stdlib/Makefile | 5 +++ string/Makefile | 1 + .../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 ++++-- .../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 +++ sysdeps/s390/fpu/math-use-builtins-bitops.h | 7 ++++ .../s390/multiarch/dl-symbol-redir-ifunc.h | 4 ++ .../sparcv9/multiarch/dl-symbol-redir-ifunc.h | 3 ++ .../sparc64/multiarch/dl-symbol-redir-ifunc.h | 3 ++ sysdeps/unix/sysv/linux/Makefile | 5 +++ sysdeps/unix/sysv/linux/dl-mmap.h | 34 +++++++++++++++++ sysdeps/unix/sysv/linux/i386/dl-mmap.h | 38 +++++++++++++++++++ .../unix/sysv/linux/i386/pthread_kill_self.c | 26 +++++++++++++ .../x86_64/multiarch/dl-symbol-redir-ifunc.h | 33 ++++++++++++++++ 27 files changed, 320 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/fpu/math-use-builtins-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/pthread_kill_self.c diff --git a/assert/Makefile b/assert/Makefile index 8d106d8752..a77362e685 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 5a676f858d..07504e1f74 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 @@ -3519,3 +3524,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..66f6ccfd4c --- /dev/null +++ b/elf/tst-assert-startup-static.c @@ -0,0 +1,35 @@ +/* Check if assert work during program startup. + Copyright (C) 2025 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 6ce669e103..01b2958112 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -180,6 +180,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/nptl/Makefile b/nptl/Makefile index 8b18ca98a9..9d6b9b9ced 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -614,6 +614,11 @@ endif # function frequently to get a thread-specific handle. CFLAGS-pthread_self.os += -fomit-frame-pointer +# It is also called during static library initialization (during abort()/assert()), +# so turn stack-protection off for non-shared builds. +CFLAGS-pthread_kill_self.o = $(no-stack-protector) +CFLAGS-pthread_kill_self.op = $(no-stack-protector) + # Run the cancellation and cleanup tests also for the modern, exception-based # implementation. For this we have to pass the -fexceptions parameter. CFLAGS-tst-cancelx7.c += -fexceptions diff --git a/signal/Makefile b/signal/Makefile index 8c7961c5f0..409c9c8532 100644 --- a/signal/Makefile +++ b/signal/Makefile @@ -65,6 +65,11 @@ tests := \ include ../Rules +# 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.c += -fasynchronous-unwind-tables CFLAGS-sigpause.c += -fexceptions CFLAGS-sigsuspend.c += -fexceptions -fasynchronous-unwind-tables diff --git a/stdlib/Makefile b/stdlib/Makefile index 25f777e1a5..f867f0ce80 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -518,6 +518,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 c83b195e2e..1f3cc2a6e0 100644 --- a/string/Makefile +++ b/string/Makefile @@ -278,6 +278,7 @@ CFLAGS-wordcopy.c += $(no-stack-protector) # Called during static initialization CFLAGS-strncmp.c += $(no-stack-protector) CFLAGS-memset.c += $(no-stack-protector) +CFLAGS-strchrnul.c += $(no-stack-protector) CFLAGS-argz-next.c += $(config-cflags-wno-ignored-attributes) CFLAGS-basename.c += $(config-cflags-wno-ignored-attributes) diff --git a/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/aarch64/multiarch/dl-symbol-redir-ifunc.h index 63ac28f50f..4646d6a137 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 f044ebcdec..1d783199bc 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 270586c451..effb98085b 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..bed3523422 --- /dev/null +++ b/sysdeps/generic/dl-mmap.h @@ -0,0 +1,34 @@ +/* mmap wrapper for dynamic loader. + Copyright (C) 2025 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 9b43cdda69..bc00b411b1 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 c36bd39c13..875bf9ecf9 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 *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/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..9a30f21ecd --- /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) 2025 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 93276e1578..b1d237eadc 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 e321ce54e0..6408176ebc 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/fpu/math-use-builtins-bitops.h b/sysdeps/s390/fpu/math-use-builtins-bitops.h new file mode 100644 index 0000000000..e2c9f76f03 --- /dev/null +++ b/sysdeps/s390/fpu/math-use-builtins-bitops.h @@ -0,0 +1,7 @@ +#if __ARCH__ > 6 +# define USE_CLZ_BUILTIN 1 +# define USE_CTZ_BUILTIN 1 +#else +# define USE_CLZ_BUILTIN 0 +# define USE_CTZ_BUILTIN 0 +#endif diff --git a/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/s390/multiarch/dl-symbol-redir-ifunc.h index c34907c20c..e921ca6e6b 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/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/sparc/sparc32/sparcv9/multiarch/dl-symbol-redir-ifunc.h index 12ff2a03fa..9cd78de2bf 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 12ff2a03fa..9cd78de2bf 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 2c5bf42236..bb74b4aca8 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 diff --git a/sysdeps/unix/sysv/linux/dl-mmap.h b/sysdeps/unix/sysv/linux/dl-mmap.h new file mode 100644 index 0000000000..bed3523422 --- /dev/null +++ b/sysdeps/unix/sysv/linux/dl-mmap.h @@ -0,0 +1,34 @@ +/* mmap wrapper for dynamic loader. + Copyright (C) 2025 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..b036f32864 --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/dl-mmap.h @@ -0,0 +1,38 @@ +/* mmap wrapper for dynamic loader. + Copyright (C) 2025 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/pthread_kill_self.c b/sysdeps/unix/sysv/linux/i386/pthread_kill_self.c new file mode 100644 index 0000000000..b3e11ba568 --- /dev/null +++ b/sysdeps/unix/sysv/linux/i386/pthread_kill_self.c @@ -0,0 +1,26 @@ +/* Send a signal to a specific pthread. Stub version. + Copyright (C) 2014-2025 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/x86_64/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/x86_64/multiarch/dl-symbol-redir-ifunc.h index 163b25d096..a31f91c329 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_avx2_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 Aug 29 19:53:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 119185 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A556D38438AC for ; Fri, 29 Aug 2025 20:00:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A556D38438AC 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=KUuZF9ZE X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id 0A4D13858287 for ; Fri, 29 Aug 2025 19:54:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A4D13858287 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 0A4D13858287 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497259; cv=none; b=CLtWSZs9Gw5iXWquYdfp+0SjoODoMXEUPZR212QQQIZ0rjPc6KDfsCJL7G8OfDapaCvzwZSPeq+GYkKNnzIdUeMK8YGzvhbOQ+sv4M0IItO4ste4sy78/oSW/I6e3R7W5S5yAUUE/2cwWcl0dwwVk53LIg4d007xsP+1Tdk2Snk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756497259; c=relaxed/simple; bh=gtFDlWOxCw9l4q72ze66y7sDkpAIQ8FDjm2bZcir+vU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=rLXvfXb3yQE0/Lnz3W/qQ4YRaBKqIzww13gbMg7fjWuLvP8ameo8teJotnI7LtAAsOayaj3wSqBPYoUL76IHKZv3lJ2yNHqC63m64rfpOJyVoDhcenZ1kN/uI4R7KSX1T/ObyqZlCTKcuJVqSJ2gM6HYcwnV3tRZk3Iafjbxs3Y= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A4D13858287 Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-7721b8214d4so2227849b3a.2 for ; Fri, 29 Aug 2025 12:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1756497258; x=1757102058; 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=pCHQG3e/UO0WmVzuTIS8jNLXiHi/BlyMYvwylC/cLFY=; b=KUuZF9ZEvU5O5JRSnOIyPUZTVb+x9UJynU/p89TH7pzFJeD0joFiTtvWLrhYwsWhB4 VEzSQVVBl8AF58o3AS7LcwnayJ8kTZuiFeR+6FjzgGXuIQwLxwgezal2fv10SSb6Ksiu BhT5pLQR7pclR+BoKRCRT+t5L8euXlQMRBnkngyT5COu26nnKKMcwYwQ4mGKVnwloM+H mnvfA/ZP+PFZ3kXvC6lv7ikoxo9a8az3KslVkyccA094LB+qvq/oEv3SxGa6Wi231h1y HHaKvZuFhea+nJTQBowU/8Yh/oeLicz6mSBt5WmM0kgzs8KzWlc1Yh3QjfmANwDKyzqb 4J7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756497258; x=1757102058; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pCHQG3e/UO0WmVzuTIS8jNLXiHi/BlyMYvwylC/cLFY=; b=BDQlSKh6GvsxQG27h0mqOGBcT1h+jrFou4soOZXmHtbTVO7dKWENu6Zc8VSAtAwpbo EXzv9hDc/vO5TPgasj7I9zGx5SmL1vN9FZv/RkTQKsiZvqvcK9sDNGuAGMNM7++De7lr dFmvxLNB2r5CLJHsYfCCF7jNp1dsuqYPWJjlXqQcDhmRFLm169Pisf6pY32XOWTcxz8V XbgQqFWYwDUS9pYRyhmx+KCE3GyBVTapJ9KsF5kUFLyRLrQRQs786R3iMO2A4zBIGVCD Oluz4jORkoEYL3uTJhuwTuuKwxTHHZuXRQgsletV8IaCYbOLTIRO8ELQSMe12yrqmjHn 6Y+w== X-Gm-Message-State: AOJu0YyF71Kf8OEUtq6tiuAlnct3u+FfaVHtL/DDi0GLIhZrSwYXjplR 7+y8GOsrcZNz3Wu29rww+ww0wHcG7dTsR6WieIJaO91NMtrhZoxlVtt1YdlpnlZGaufIkScxow/ 8B5UU X-Gm-Gg: ASbGncsdbVbc8Vd9Iy2Ai7+5UUrvYacDeH4a/GWQc/IcXZavxTSBGKWW0hAubbDXdLi 5PYplcE63RKxsW9imTyPWoyUB9dfdx8Uxm0F9JkdBrQEm0L2LzZqALTdfMc8AICVP7cdrHixfOA Fzu1UvaO0ZofYzgGe7pClv/p2ADFAZdShFowyBd1qx64G/tTSI94ygwIep2Rgnb4w4TETDrz/QG DhPO99ZI8+S7mKXnhGRBLjrSxLJd8wCevL/hS746DK8XMeaoROU4IbqWAjrpxfo772RsKY5WIgs VNrfxo2UNlWCdyec9BHOEnx1fT2sJ2oOC4c9qhm7MO8TqadVdslcvINjUahVE0qBfyWZS9lH7gp sxwmcUS7n8ZTErWu3HPum+ck3qDW+sAm7A8Lms4SvhzD5ug8= X-Google-Smtp-Source: AGHT+IHgUfoMxjpvte0030CJIgZ3L6FPa1AVbpwDKBDAaeUWUYKjKdjdSbR2g78APLQfUn0v2/vzsA== X-Received: by 2002:a05:6a20:7d8b:b0:23d:45b2:8e21 with SMTP id adf61e73a8af0-24340cd294emr42095369637.37.1756497257628; Fri, 29 Aug 2025 12:54:17 -0700 (PDT) Received: from ubuntu-vm.. ([177.103.118.15]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-b4cd3669d76sm2894572a12.49.2025.08.29.12.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 12:54:17 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Valery Ushakov Subject: [PATCH 5/5] elf: Allow RPATH/RUNPATH for static-pie (BZ 33326) Date: Fri, 29 Aug 2025 16:53:25 -0300 Message-ID: <20250829195401.953674-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250829195401.953674-1-adhemerval.zanella@linaro.org> References: <20250829195401.953674-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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 where RPATH/RUNPATH should not be present in the bootstrap. The presence of RPATH/RUNPATH on the loader suggests some toolchain misconfiguration; however, it's strictly not an issue for static-pie. Although static binaries do not support rpath (since they lack dynamic sections), adding static-pie support only affects the dlopen function. If/when static dlopen support is removed, this will become a no-op. This also allows simplifying a bit of elf_get_dynamic_info, and it is one less unexpected behavior (where dynamic and static binaries support and behave differently). Checked on aarch64-linux-gnu and x86_64-linux-gnu. --- elf/Makefile | 8 ++++++ 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 | 53 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 87 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 07504e1f74..eb7f3f016b 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 @@ -3535,3 +3539,7 @@ $(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)\" +$(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 891b44966c..abe05e48fb 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 758bf9893e..f19ab7e5cd 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 d3d830e86c..2d9cd41641 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 753ce6690b..1a6b986c3b 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -548,7 +548,7 @@ _dl_start (void *arg) /* Read our own dynamic section and fill in the info array. */ bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic (); bootstrap_map.l_ld_readonly = DL_RO_DYN_SECTION; - elf_get_dynamic_info (&bootstrap_map, true, false); + elf_get_dynamic_info (&bootstrap_map, true); #if NO_TLS_OFFSET != 0 bootstrap_map.l_tls_offset = NO_TLS_OFFSET; @@ -1702,7 +1702,7 @@ dl_main (const ElfW(Phdr) *phdr, if (! rtld_is_main) { /* Extract the contents of the dynamic section for easy access. */ - elf_get_dynamic_info (main_map, false, false); + elf_get_dynamic_info (main_map, false); /* If the main map is libc.so, update the base namespace to refer to this map. If libc.so is loaded later, this happens diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h index 935d9e3baf..420ce70d15 100644 --- a/elf/setup-vdso.h +++ b/elf/setup-vdso.h @@ -60,7 +60,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..40e3b78d6a --- /dev/null +++ b/elf/tst-pie-rpath-mod.c @@ -0,0 +1,19 @@ +/* Check if RPATH/RUNPATH is allowed for static-pie. + Copyright (C) 2025 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..e02ca47364 --- /dev/null +++ b/elf/tst-pie-rpath-static.c @@ -0,0 +1,53 @@ +/* Check if RPATH/RUNPATH is allowed for static-pie. + Copyright (C) 2025 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 + +#define LIBNAME "tst-pie-rpath-mod.so" +#define TESTSUBDIR PFX "tst-pie-rpath-static-subdir" +#define LIBPATH TESTSUBDIR "/" LIBNAME + +static void +cleanup (void) +{ + xunlink (LIBPATH); + rmdir (TESTSUBDIR); +} + +static int +do_test (void) +{ + atexit (cleanup); + + xmkdir (TESTSUBDIR, 0777); + + support_copy_file (PFX "/" LIBNAME, LIBPATH); + + void *h = xdlopen (LIBNAME, RTLD_NOW); + int (*foo)(void) = xdlsym (h, "foo"); + TEST_COMPARE (foo (), 42); + xdlclose (h); + + return 0; +} + +#include