From patchwork Tue May 26 14:00:45 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 135738 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7A8D14BA2E39 for ; Tue, 26 May 2026 14:04:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7A8D14BA2E39 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=n0HqAzVU X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ua1-x92c.google.com (mail-ua1-x92c.google.com [IPv6:2607:f8b0:4864:20::92c]) by sourceware.org (Postfix) with ESMTPS id E2F044BA2E39 for ; Tue, 26 May 2026 14:02:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2F044BA2E39 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 E2F044BA2E39 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::92c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779804179; cv=none; b=ABfMRlCQKK2AglxQ0PujIBmGQKadBGDZ/bO4fzShTzaEASFzR3X/r6Z3sEYzsB2w5I/wUWQdusYeDjXMq+M0m79XBLq2djT+D3+fWtQHY2uL9PQm9IWsn1SiVLjEFoi17rcY3fmLcNa59pR2FUuGarUZoMZQctPRDz41EWAkOts= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779804179; c=relaxed/simple; bh=wMzPlCTBLsJvglkforYSJ+SftmdzncsHb1mqf4dTDtE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K3BoqwfQ5+B6QwlyUY0fV8DimJy/rw29nFbNvyZt1PaLz8HOO9itc5WsNFZdARxFrTuaEDNNt1wPeEv0tUDExzF3v740XJWuwHz1yq7idd0a7nuQQ5O1raQKsp6mHZJO/tVwBRjMe/Uzrw+BkNiy2bjjwATgykmRl4slyDWBHAs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=n0HqAzVU DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E2F044BA2E39 Received: by mail-ua1-x92c.google.com with SMTP id a1e0cc1a2514c-95ce7b777ccso6188664241.1 for ; Tue, 26 May 2026 07:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779804178; x=1780408978; 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=2mKnSqi9DV7nXzJCGQj5dTzS2XZTSJWR/4MTMhF4dhI=; b=n0HqAzVUQrcijgM9CWwh5Q7FR7nubl2jaHISgI54clkAADWRIn7bA2CTMN11+EFJlZ B0yt7Gmg6/pHWfRel0EBcu7Df83oGafQNFw26K3HneHW4EhoU0rC32dMlg6XNzf9025A xRQKxfvwqX49Q7DnNB0BKU4BncjcgHXgzpwz1HqXHDntjpZju5YphNokw4pwC+CouLC3 xkOyAkt7z139d9QCezFaUviPaxiAJLHqANnjixR3yYxHD0vjQVoC2tZOV5UZEZcv4LSB 7Iw5e/BbubDGG2s4sv56KOANMjvjgusiGeyRsNvv2WDUGMUoXGYmHF11+Dkl/R6esNXz sz6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779804178; x=1780408978; 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=2mKnSqi9DV7nXzJCGQj5dTzS2XZTSJWR/4MTMhF4dhI=; b=YznobyeBm9bORKIABWkBG1wXVi8ar9fyjSenScUkejmwMI2bpzBNAeIInCwqRGbAaM GRUkwxE61LkgynmaGiQTGHJNthWnvMhT44Hg/jUco8tBdNJtmEPk02tsgyuLI0LewF2k jJk7ZeTK0pVYkWCh8b7EzEMiiq2cv67T2QAjFCBm2Xd8VXq7RR9dhVS8MP7/vOtCDoXR lzP2uHeL6swCusOaRe8/ofDtc1F3ImQP9jXDDen4zahPVN79O8WyENRGK4YtEJMvzhNj 2hyATg4T5Cg+K2ij2uZC7/AjJ2CNTvXQwZEEoAcbkAJDjH3ba6R0NKz2vd+tPBkFL7r0 Gafw== X-Gm-Message-State: AOJu0Yx+wrqE2xDDAc59opOBAmb276GiTLMz6laLuuyPhJyLB2rnucJc 2FpBrBAhH78G61mU4n6GN9gND4EiT0Lk+jE1XxaMiqdSAzlbEY79p4JxgL36Gelg/i/5BNHA6q8 qEiv8 X-Gm-Gg: Acq92OGOww0GRQlMkJxWwdVhztf/OFmpLzlFUC5vXBTM/9Uzoa7dKoC+oWgjwzuwYRZ A0XTa1TYutzXqikzbtub+1veEbbXoTCNo+vk39eNPBH6y0A1vQk4fea4KMcSENQp7vhhiqLe0mV yE+tTSwi9S/bspKTt39B2pVw8PCFQWbNnhxkSGCcvNEfjGevh42HAPCM1zb64X0qEuVRlAAUzlN dRbBcIfwijH5FQ0A8pe1E9wBWFe71pYxDVj/rYO+4zRrGjJas/1Tj+pcUW84MdIGN1gnb9RBIvf H1ed6kd+djHRjHdsZV4NTcEHTayP2bCrxw1u4uTVjiotRd5yKcNjjh50JgpFwdbZ9GH8gZscufF Yu+vTS5B9K3sIH0ryCLe7mSalUVxZlzgAJ6IoezCd7krgvmbidUVY9ekJqM7ZuGxpE1dapWtSuA K/ye9sH6a3pJ+fiB+9b/AeS7rCiiwsrhJdV44Atz05o74NcA== X-Received: by 2002:a05:6122:54b:b0:56b:8ba0:fd58 with SMTP id 71dfb90a1353d-5868efd797cmr4429896e0c.6.1779804177666; Tue, 26 May 2026 07:02:57 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:efc6:3e7d:d0ac:c69d:64f3]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-586f8f6cd40sm17050755e0c.16.2026.05.26.07.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 07:02:56 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: "H . J . Lu" Subject: [PATCH 1/2] elf: Set up TLS slotinfo for dlopen'd modules before relocation (BZ 34170) Date: Tue, 26 May 2026 11:00:45 -0300 Message-ID: <20260526140248.603938-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526140248.603938-1-adhemerval.zanella@linaro.org> References: <20260526140248.603938-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org An IFUNC resolver in a DSO that is being loaded by dlopen is allowed to read its own TLS storage during the resolver call. After af34b1376a3 ("elf: Initialize static TLS before relocation processing (BZ 34164)") that works for the initial-exec model on every supported architecture. However tt does not work dynamic-TLS path (on both -mtls-dialect mode, if the ABI supports both). Both lookup paths index the calling thread's DTV by the new module's l_tls_modid and, on miss, walk GL(dl_tls_dtv_slotinfo_list) to discover the module and lazily allocate its TLS block. The just-loaded DSO is however not yet in that list when its resolver fires, so the lookup faults inside dlopen. This is the direct dlopen analog of BZ 34164. The solution is to reorder dl_open_worker_begin so the slotinfo install happens before the relocation pass. The new order is: 1. resize_scopes, resize_tls_slotinfo, add_to_global_resize (unchanged, still recoverable). 2. update_tls_slotinfo: register the new modules in slotinfo, bump dl_tls_generation, initialise their static TLS images. 3. Relocate the new objects. IFUNC resolvers can now read their own DSO's __thread storage via any TLS model. 4. Demarcation point. 5. update_scopes, _dl_find_object_update. Checked on aarch64-linux-gnu and x86_64-linux-gnu. --- elf/Makefile | 23 ++++++ elf/dl-open.c | 51 ++++++------ elf/tst-ifunc-tls-init-gd-global-lib.c | 3 + elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c | 69 ++++++++++++++++ elf/tst-ifunc-tls-init-gd-ld.c | 89 +++++++++++++++++++++ elf/tst-ifunc-tls-init-gd-lib.c | 2 + elf/tst-ifunc-tls-init-ld-lib.c | 2 + elf/tst-ifunc-tls-init-tlsdesc-lib.c | 3 + elf/tst-ifunc-tls-init-tlsdesc.c | 69 ++++++++++++++++ 9 files changed, 285 insertions(+), 26 deletions(-) create mode 100644 elf/tst-ifunc-tls-init-gd-global-lib.c create mode 100644 elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c create mode 100644 elf/tst-ifunc-tls-init-gd-ld.c create mode 100644 elf/tst-ifunc-tls-init-gd-lib.c create mode 100644 elf/tst-ifunc-tls-init-ld-lib.c create mode 100644 elf/tst-ifunc-tls-init-tlsdesc-lib.c create mode 100644 elf/tst-ifunc-tls-init-tlsdesc.c diff --git a/elf/Makefile b/elf/Makefile index d7bab52cd97..847edf4fbb6 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -1296,6 +1296,7 @@ tests += \ tst-ifunc-plt-dlopen-bindnow \ tst-ifunc-resolver-protector \ tst-ifunc-tls-init \ + tst-ifunc-tls-init-gd-ld \ tst-ifunc-tls-write \ # tests # Note: sysdeps/x86_64/ifuncmain8.c uses ifuncmain8. @@ -1364,8 +1365,17 @@ modules-names += \ tst-ifunc-resolver-protector-mod \ tst-ifunc-tls-init-lib1 \ tst-ifunc-tls-init-lib2 \ + tst-ifunc-tls-init-gd-lib \ + tst-ifunc-tls-init-gd-global-lib \ + tst-ifunc-tls-init-ld-lib \ tst-ifunc-tls-write-lib \ # modules-names +ifneq (no,$(have-test-mtls-descriptor)) +tests += tst-ifunc-tls-init-tlsdesc +modules-names += tst-ifunc-tls-init-tlsdesc-lib +CFLAGS-tst-ifunc-tls-init-tlsdesc-lib.c += \ + -mtls-dialect=$(have-test-mtls-descriptor) +endif ifeq (no,$(with-lld)) modules-names += ifuncmod5 endif @@ -2519,6 +2529,19 @@ $(objpfx)tst-ifunc-tls-init.out: \ $(objpfx)tst-ifunc-tls-init-lib2.so $(objpfx)tst-ifunc-tls-write: $(objpfx)tst-ifunc-tls-write-lib.so +$(objpfx)tst-ifunc-tls-init-gd-ld: $(shared-thread-library) +$(objpfx)tst-ifunc-tls-init-gd-ld.out: \ + $(objpfx)tst-ifunc-tls-init-gd-lib.so \ + $(objpfx)tst-ifunc-tls-init-gd-global-lib.so \ + $(objpfx)tst-ifunc-tls-init-ld-lib.so + +ifneq (no,$(have-test-mtls-descriptor)) +$(objpfx)tst-ifunc-tls-init-tlsdesc: $(shared-thread-library) +$(objpfx)tst-ifunc-tls-init-tlsdesc.out: \ + $(objpfx)tst-ifunc-tls-init-tlsdesc-lib.so +tst-ifunc-tls-init-tlsdesc-TUNABLES = glibc.rtld.optional_static_tls=0 +endif # $(have-test-mtls-descriptor) + $(objpfx)tst-unique1.out: $(objpfx)tst-unique1mod1.so \ $(objpfx)tst-unique1mod2.so diff --git a/elf/dl-open.c b/elf/dl-open.c index ee25d4d42b4..460c181f3db 100644 --- a/elf/dl-open.c +++ b/elf/dl-open.c @@ -658,6 +658,31 @@ dl_open_worker_begin (void *a) bool relocation_in_progress = false; + /* This only performs the memory allocations. The actual update of + the scopes happens below, after failure is impossible. */ + resize_scopes (new); + + /* Increase the size of the GL (dl_tls_dtv_slotinfo_list) data + structure. */ + bool any_tls = resize_tls_slotinfo (new); + + /* Perform the necessary allocations for adding new global objects + to the global scope below. */ + if (mode & RTLD_GLOBAL) + add_to_global_resize (new); + + /* Install the new modules in the DTV slotinfo and initialise their + static TLS *before* relocation, so an IFUNC resolver firing during + the relocation loop below can reach its DSO's __thread storage via + __tls_get_addr / TLSDESC. Without this, the resolver's TLS access + for a just-loaded module would index into an unallocated DTV slot + and crash. If relocation later fails, the subsequent _dl_close_worker + cleans up these slotinfo entries via remove_slotinfo. */ + if (any_tls) + /* FIXME: This calls _dl_update_slotinfo, which aborts the process + on memory allocation failure. See bug 16134. */ + update_tls_slotinfo (new); + /* Perform relocation. This can trigger lazy binding in IFUNC resolvers. For NODELETE mappings, these dependencies are not recorded because the flag has not been applied to the newly @@ -682,19 +707,6 @@ dl_open_worker_begin (void *a) _dl_open_relocate_one_object (args, r, new->l_initfini[i], reloc_mode, &relocation_in_progress); - /* This only performs the memory allocations. The actual update of - the scopes happens below, after failure is impossible. */ - resize_scopes (new); - - /* Increase the size of the GL (dl_tls_dtv_slotinfo_list) data - structure. */ - bool any_tls = resize_tls_slotinfo (new); - - /* Perform the necessary allocations for adding new global objects - to the global scope below. */ - if (mode & RTLD_GLOBAL) - add_to_global_resize (new); - /* Demarcation point: After this, no recoverable errors are allowed. All memory allocations for new objects must have happened before. */ @@ -716,19 +728,6 @@ dl_open_worker_begin (void *a) _dl_signal_error (ENOMEM, new->l_libname->name, NULL, N_ ("cannot allocate address lookup data")); - /* FIXME: It is unclear whether the order here is correct. - Shouldn't new objects be made available for binding (and thus - execution) only after there TLS data has been set up fully? - Fixing bug 16134 will likely make this distinction less - important. */ - - /* Second stage after resize_tls_slotinfo: Update the slotinfo data - structures. */ - if (any_tls) - /* FIXME: This calls _dl_update_slotinfo, which aborts the process - on memory allocation failure. See bug 16134. */ - update_tls_slotinfo (new); - /* Notify the debugger all new objects have been relocated. */ if (relocation_in_progress) LIBC_PROBE (reloc_complete, 3, args->nsid, r, new); diff --git a/elf/tst-ifunc-tls-init-gd-global-lib.c b/elf/tst-ifunc-tls-init-gd-global-lib.c new file mode 100644 index 00000000000..9e91ab4c9bc --- /dev/null +++ b/elf/tst-ifunc-tls-init-gd-global-lib.c @@ -0,0 +1,3 @@ +#define TLS_MODEL "global-dynamic" +#define SENTINEL_STORAGE /* empty */ +#include "tst-ifunc-tls-init-gd-ld-lib-skeleton.c" diff --git a/elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c b/elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c new file mode 100644 index 00000000000..b6fd6cf06e1 --- /dev/null +++ b/elf/tst-ifunc-tls-init-gd-ld-lib-skeleton.c @@ -0,0 +1,69 @@ +/* Shared-library skeleton for tst-ifunc-tls-init-gd-ld. + 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 + . */ + +/* Unlike tst-ifunc-tls-init-lib-skeleton.c, which uses initial-exec and + resolves via a single TP-relative load, this skeleton's TLS_MODEL is + either "global-dynamic" or "local-dynamic" so the resolver's read of + 'sentinel' must traverse __tls_get_addr (or the architecture's + TLSDESC equivalent). That dynamic-TLS access can lazily allocate a + per-module TLS block, which is the path being exercised. */ + +#ifndef TLS_MODEL +# error "tst-ifunc-tls-init-gd-ld-lib-skeleton.c needs TLS_MODEL defined" +#endif + +/* Without static the relocation against the SENTINEL goes through the regular + global-symbol lookup path; combined with TLS_MODEL="global-dynamic" this + exercises the "global GD" variant rather than the file-local one. */ +#ifndef SENTINEL_STORAGE +# define SENTINEL_STORAGE static +#endif + +#define SENTINEL 0x5A5A1234 + +SENTINEL_STORAGE volatile __thread int sentinel + __attribute__ ((tls_model (TLS_MODEL))) = SENTINEL; +static volatile int last_seen_sentinel; + +static int +impl_ok (void) +{ + return SENTINEL; +} + +static int +impl_bad (void) +{ + return 0; +} + +int +get_last_seen_sentinel (void) +{ + return last_seen_sentinel; +} + +static int (*resolver (void)) (void) +{ + int s = sentinel; + last_seen_sentinel = s; + return s == SENTINEL ? impl_ok : impl_bad; +} +int ifunc_tls (void) __attribute__ ((ifunc ("resolver"))); + +int (*fptr) (void) = ifunc_tls; diff --git a/elf/tst-ifunc-tls-init-gd-ld.c b/elf/tst-ifunc-tls-init-gd-ld.c new file mode 100644 index 00000000000..20ebe4d9931 --- /dev/null +++ b/elf/tst-ifunc-tls-init-gd-ld.c @@ -0,0 +1,89 @@ +/* Check if dynamic-TLS variables (global-dynamic, local-dynamic) are + correctly initialised in IFUNC resolvers reached via dlopen. + 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 test dlopens three modules covering the dynamic-TLS access variants: + + gd-lib file-local 'sentinel' + tls_model("global-dynamic") + ld-lib file-local 'sentinel' + tls_model("local-dynamic") + gd-global-lib external 'sentinel' + tls_model("global-dynamic") + + In each case the IFUNC resolver's read of 'sentinel' must traverse the + dynamic-TLS resolution path at the moment the resolver fires during + dlopen-time relocation. + + Each variant additionally calls the resolved IFUNC from a thread spawned + after dlopen, to verify per-thread DTV propagation for the newly-loaded + module. */ + +#include +#include +#include + +#define SENTINEL 0x5A5A1234 + +struct ifunc_handles +{ + int (*get_last_seen_sentinel) (void); + int (**fptr) (void); + int (*ifunc_tls) (void); +}; + +static void * +ifunc_caller (void *arg) +{ + struct ifunc_handles *h = arg; + TEST_COMPARE ((*h->fptr) (), SENTINEL); + TEST_COMPARE (h->ifunc_tls (), SENTINEL); + return NULL; +} + +static void +test_lib (const char *soname) +{ + void *handle = xdlopen (soname, RTLD_LAZY | RTLD_LOCAL); + + struct ifunc_handles h; + h.get_last_seen_sentinel = xdlsym (handle, "get_last_seen_sentinel"); + h.fptr = xdlsym (handle, "fptr"); + h.ifunc_tls = xdlsym (handle, "ifunc_tls"); + + TEST_COMPARE (h.get_last_seen_sentinel (), SENTINEL); + + TEST_VERIFY (*h.fptr != NULL); + TEST_COMPARE ((*h.fptr) (), SENTINEL); + TEST_COMPARE (h.ifunc_tls (), SENTINEL); + + /* From a thread spawned *after* the dlopen, which exercises DTV propagation + for the new module into a fresh TCB. */ + pthread_t consumer = xpthread_create (NULL, ifunc_caller, &h); + xpthread_join (consumer); + + xdlclose (handle); +} + +static int +do_test (void) +{ + test_lib ("tst-ifunc-tls-init-gd-lib.so"); + test_lib ("tst-ifunc-tls-init-ld-lib.so"); + test_lib ("tst-ifunc-tls-init-gd-global-lib.so"); + return 0; +} + +#include diff --git a/elf/tst-ifunc-tls-init-gd-lib.c b/elf/tst-ifunc-tls-init-gd-lib.c new file mode 100644 index 00000000000..3d940f2af3c --- /dev/null +++ b/elf/tst-ifunc-tls-init-gd-lib.c @@ -0,0 +1,2 @@ +#define TLS_MODEL "global-dynamic" +#include "tst-ifunc-tls-init-gd-ld-lib-skeleton.c" diff --git a/elf/tst-ifunc-tls-init-ld-lib.c b/elf/tst-ifunc-tls-init-ld-lib.c new file mode 100644 index 00000000000..41e9f30298e --- /dev/null +++ b/elf/tst-ifunc-tls-init-ld-lib.c @@ -0,0 +1,2 @@ +#define TLS_MODEL "local-dynamic" +#include "tst-ifunc-tls-init-gd-ld-lib-skeleton.c" diff --git a/elf/tst-ifunc-tls-init-tlsdesc-lib.c b/elf/tst-ifunc-tls-init-tlsdesc-lib.c new file mode 100644 index 00000000000..9e91ab4c9bc --- /dev/null +++ b/elf/tst-ifunc-tls-init-tlsdesc-lib.c @@ -0,0 +1,3 @@ +#define TLS_MODEL "global-dynamic" +#define SENTINEL_STORAGE /* empty */ +#include "tst-ifunc-tls-init-gd-ld-lib-skeleton.c" diff --git a/elf/tst-ifunc-tls-init-tlsdesc.c b/elf/tst-ifunc-tls-init-tlsdesc.c new file mode 100644 index 00000000000..dfa99a4248c --- /dev/null +++ b/elf/tst-ifunc-tls-init-tlsdesc.c @@ -0,0 +1,69 @@ +/* Check that an IFUNC resolver in a dlopen'd DSO can read .tdata-initialised + __thread storage when the TLS access is compiled as a TLSDESC sequence. + 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 + . */ + +/* Sibling of tst-ifunc-tls-init-gd-ld, but the TLS access in the loaded + DSO is compiled with the TLSDESC dialect (x86 gnu2, aarch64 desc). */ + +#include +#include +#include + +#define SENTINEL 0x5A5A1234 + +struct ifunc_handles +{ + int (*get_last_seen_sentinel) (void); + int (**fptr) (void); + int (*ifunc_tls) (void); +}; + +static void * +ifunc_caller (void *arg) +{ + struct ifunc_handles *h = arg; + TEST_COMPARE ((*h->fptr) (), SENTINEL); + TEST_COMPARE (h->ifunc_tls (), SENTINEL); + return NULL; +} + +static int +do_test (void) +{ + void *handle = xdlopen ("tst-ifunc-tls-init-tlsdesc-lib.so", + RTLD_LAZY | RTLD_LOCAL); + + struct ifunc_handles h; + h.get_last_seen_sentinel = xdlsym (handle, "get_last_seen_sentinel"); + h.fptr = xdlsym (handle, "fptr"); + h.ifunc_tls = xdlsym (handle, "ifunc_tls"); + + TEST_COMPARE (h.get_last_seen_sentinel (), SENTINEL); + + TEST_VERIFY (*h.fptr != NULL); + TEST_COMPARE ((*h.fptr) (), SENTINEL); + TEST_COMPARE (h.ifunc_tls (), SENTINEL); + + pthread_t consumer = xpthread_create (NULL, ifunc_caller, &h); + xpthread_join (consumer); + + xdlclose (handle); + return 0; +} + +#include From patchwork Tue May 26 14:00:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 135739 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A7B774BA798E for ; Tue, 26 May 2026 14:04:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A7B774BA798E 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=Tn5KrYV3 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-dl1-x122c.google.com (mail-dl1-x122c.google.com [IPv6:2607:f8b0:4864:20::122c]) by sourceware.org (Postfix) with ESMTPS id C9D154BA23FA for ; Tue, 26 May 2026 14:03:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9D154BA23FA 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 C9D154BA23FA Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::122c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779804192; cv=none; b=JkXEXuDCPmFVcC1QT1iRsbEJzTZ/S0W3hQFeLM/HjZapkcqQh5iGhdMsqLb7JpWvp43mIPP3nP2crRKaHZ84fdVJSNjxXK/GzYJQ9XzGovAMbHkSXWSNr1/vcdBOpzjy9r9xUPL+tMCA9JTT+ALXdr5+orfEMfMBPG7h/8mhEmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1779804192; c=relaxed/simple; bh=IrtZcFTQTiWGbjiZwZrSTRa61X/3oeSXf7kF//tqpno=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pm9QNyvkNMvui2FCWEfY0L7L8x0VhXECCGMzxd1Jb+4tFrRPNX9FiyUGd0XUXW3E0rHcokDUdGW+8cR8rQMGIkWJ9/vhHzghNNa4elRYpepdUELAEXRJqVSLLwWAvdU6Juh/DjhYVr1Ny65rWWvVc1sJrQXgs+l9WWlmN+gcCeQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Tn5KrYV3 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9D154BA23FA Received: by mail-dl1-x122c.google.com with SMTP id a92af1059eb24-12ddbe104ccso7869324c88.0 for ; Tue, 26 May 2026 07:03:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1779804191; x=1780408991; 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=cdxzp9dlVbnMgz6YbfcvX69tElVwCaLkGjCX/xSI1KY=; b=Tn5KrYV3ZM1c+lQgaz1wBvptO8bJkxLZ1MeUoTbzuBmMV+9Vl8Mn0JIicwIFb/Bz4k 5n1DwPQVUSVy/cDqV/UJSV5kfsZ1Fdg2fZeqABkbUG3wGh7t42+pinpR4MgyFS+Nb3Tp /bWy6iGKjuBS5CTEUL1z16MwvxSlRGqry8G2tKzibIj+18V1FsBZZbSSk/VwImnJoHAN JCM6cNdpQS4Jd25rcVfLovw+KZN0yri2NL/v4T9/++gtMAPUUhFRf2/DcnkLhcPxjXcp CdOR3mzUKHEhr5C/2Ze15NinT0rT+BGKtSbMn/FSOZlmEln4MMKnZTntMfm+PY7pFSrE +Fqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779804191; x=1780408991; 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=cdxzp9dlVbnMgz6YbfcvX69tElVwCaLkGjCX/xSI1KY=; b=ZLUvd5yTNkEwZzI2wzNAZxy1gGyaCVkS3sttwVFK2tHOl3epWlOlZGHzp8l+hLEFSZ TH8mTofvZRdqNdKBda6HGRX34DBKfq4yP2gfrO4PDYwLqZvUwqoAIZyiuJnAtnrZhMsQ xl/sFw5ZSBp6wGcfhQ+sSmarviQCjHDR0ratWvrv6psvPvAqP7OucHbnJpymtBw8BY0m DJvVSfWn450Piyk1X/aDLWGETP2I/rfOvuRBNWJ6pPYKqttUmwi3b9qelT6KH9SEvZJM 7/bFKHyg5nbLaTUhYZNcJSCR2vVniiYazk7tmSeeNOb2VXfQtiVs1UZY9zYj2JXPzB1E OM7w== X-Gm-Message-State: AOJu0Yy3btMuLz2FmuzMb7RwC0fJacGhVKNVmV/XJ6HFl2mdtAVx1w/F GoRCGsBX5VZqAIC7yEIGXZN3yFyEworgMKC5pKhiFDVi8Gf2JcBPq81buyUBfa6lHaNI7MjPO62 Oi0+4 X-Gm-Gg: Acq92OHYYXuxPgs4FgS56UCrbXKo/U5TCy1klwnt7R9B4TCsbokklvITRh1X7YGakpF 7A/Yzkz5XpnafEjqY6qaD6rc9scpP0gLvzUKlzWG+iqfA8Kmj/KtWILEc4XVpRv9wnQhjelXmUd kEdxgKGEY7gysBqXqb3zi5OoaS2ce/OZMPIwt0TkavgCp3QpLGMgRRBrnXHvKQdrPU0+t1O1K4B /Y1bw8Js5bICm3NLNYoN9DPaYX9SJc4hqpIwpO6wlUavlzxGh1kZuKOKNIUnYInYyq5uvujhHib KWaarY6h7BWMopXXAkY7YDUUPQyVBEv/uiLanXhZZVfnhfiJcdkLV/soX8Lqej07nA0wKqItJEe Dnu41S8m5oMxNEx+9NmkhrptzA0OuvzYivevMUm0/VR+w8QR9rB+nUCTSFm/8RsvU9zQC9PMSOI s4iILTlazI0ImGNDvfGNyEJqBCqGooe7PsdyE= X-Received: by 2002:a05:6122:3b0e:b0:588:2fc:f169 with SMTP id 71dfb90a1353d-58802fcfb55mr7379617e0c.13.1779804179939; Tue, 26 May 2026 07:02:59 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c2:efc6:3e7d:d0ac:c69d:64f3]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-586f8f6cd40sm17050755e0c.16.2026.05.26.07.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 07:02:59 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: "H . J . Lu" Subject: [PATCH 2/2] elf: Remove inhibit_stack_protector from __ifunc_resolver Date: Tue, 26 May 2026 11:00:46 -0300 Message-ID: <20260526140248.603938-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260526140248.603938-1-adhemerval.zanella@linaro.org> References: <20260526140248.603938-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org With 01964c3ec8e fix ifunc resolvers can be fully instrumented with stack protector. Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu built with --enable-stack-protector=all. --- include/libc-symbols.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libc-symbols.h b/include/libc-symbols.h index 6a9f6403ab9..2387954f7fc 100644 --- a/include/libc-symbols.h +++ b/include/libc-symbols.h @@ -671,7 +671,7 @@ for linking") /* Helper / base macros for indirect function symbols. */ #define __ifunc_resolver(type_name, name, expr, init, classifier, ...) \ - classifier inhibit_stack_protector \ + classifier \ __typeof (type_name) *name##_ifunc (__VA_ARGS__) \ { \ init (); \