From patchwork Mon Aug 17 14:21:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 141547 X-Patchwork-Delegate: Wilco.Dijkstra@arm.com 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 DDFFB4BA23FF for ; Mon, 17 Aug 2026 14:22:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDFFB4BA23FF 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=oMddXHSh X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-vk1-xa35.google.com (mail-vk1-xa35.google.com [IPv6:2607:f8b0:4864:20::a35]) by sourceware.org (Postfix) with ESMTPS id A24454BA7985 for ; Mon, 17 Aug 2026 14:21:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A24454BA7985 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 A24454BA7985 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::a35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786976504; cv=none; b=NijMbmbgMMFoqNrY5LkFnHlyS+1MYvj3iGELQYr2Ckp73+GLCbYQvqVAe45lEXMxp6bshsQyq+sDPn0JfFD1YKN5XH1q9jpFrFeAW34S4EK8B1dKhP6j4TphncT5tD8Qf72ubZ7PYyKtfj8FFg+BlpumQiWOqi2sWRCCj3b3NXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786976504; c=relaxed/simple; bh=1Sb4TMbFqVN3KdrTbD5AzyWWGXXjGxdWLx8yG6/sIgo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sVsBbHt1UVbfoMOuEm+smv/h4wETWEygwhex9EExCOCRY1IqRdohDD83OfbeL+UJQbOj1sKAwsMwtGsrJsLm8lBE95VfS86mii/+OdOKTiR9bKPdof28k4w/WFDPtE6izICR2+pCxZQDkXIoCDm/pXT9+RbgoJ8I3pHZp8+vtzc= 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=oMddXHSh DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A24454BA7985 Received: by mail-vk1-xa35.google.com with SMTP id 71dfb90a1353d-5c38568d9e1so1466091e0c.3 for ; Mon, 17 Aug 2026 07:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1786976504; x=1787581304; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=YA0uBL5KFZFgTjfOkUUq9rYp9yzam731meSR157o390=; b=oMddXHShSUmKP2uMadInXw8LylvdNoFCFEYVEuNbOqxa62uYDrWFWDCwlwkfseqd1S tuUV9tdir8AvznUENp8+b5/9q77qapNXt3OXw4VbUBhcalolICuBdRciEoit0aU3QeQ+ c2z/SosbxdAd7o5KkdMRhjhMAk2JUhEq5ML5KDdD1+uftWAs+C/KXsOZyaduGf9JKyCH AiZPVR+U4UzgLL0es8o0JwpfzxJchkL+xCj401eMGfy83YJdEbN+HdnNlliwJtJmRSKG 55xaUo33iDW4MWUXaN0uyjGPs0Q74b0VGxVG79hPUu0e8qmGs6Fxdra5d2PUuejPYOQ+ /OIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786976504; x=1787581304; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=YA0uBL5KFZFgTjfOkUUq9rYp9yzam731meSR157o390=; b=RzesPSkeoT2q8ocO+CorqqkcUv9b1USMhf2AJUtJEQlaDbDX75i0Y18ceQ/0BwDxZ4 WlRzEdXzu3PN0Yz6JnfMdymRSp0VBGeaY2J/Tp/qsBelt6uoBICapPVew2QBS9etfHQM X6bQJimM06IyOqc3ZRze4COz/grxMuXD6QhVGua0efr2ZQKB3KE0kBIQV4cVdb0v56k/ ySBUKZ/aN71tRZ7TTDfSAZO0q3NcFsmLX6BoYGDla/bkzeszy7b/W5OJy62R4TVPJE4I dryyi8lMYW60vu9Uaj3zdoGTB8urPQFJ2asIA5GlZrQ2QcqUA6sZ09SkMbeyZpmuFm1x aWLg== X-Gm-Message-State: AOJu0YzNFW4yfUlvBRslOGfbLtv2yF6ct4TRgypVZKiC1Bg2HbH2IAcG OdrC1qmEZvN1NSxct5XKgDAi5hsTNFemIwuC2aVMQ7fVayaMGPw98qh8mKbYzscpEJTKFMZmrTR +e0IugzI= X-Gm-Gg: AR+sD12v/nsBZkNreRlqA1qVrmBVtC3eP0b6lFNF3Ki6mzRb4zESqdJstN0Qhh1T1gk 69ClJoOBxZGq2Ef0NSei6TjVmC8vzIPuJ7mgk+q9UgX3uaLmfkAEnqul1B1WqhuTlfTISRlyA81 BWuPnvh+xacZfTAp/vRdwmPMpjgTtc8kdCKAL3L8KaQIQeR3BJIuhVmYQF/YHpm3mpyrJ7dlHhg AuMlITjs25ff+0EX3TvRmJpG1WP2gQJjyXdkhngtERj1lJ5QOwP208Vtbr6ss+nIWAgu/ubgGRJ 3VQ7tbCCAlZun2FUmccsfouiFkUZAL3OenV8J13gjhv4kfF4YLZtyRxgEKj/4qlsMbPXadXQlkf Pe/Fuv/1U/p802qn2rpuBCQGAYByjW1kEqwhWw0H7Qp3LWo8fZNNgoYfp/6hmIp4LRoa4h94T1t NGHOrHQETxpsuC0FBwmwhcwAwD884NrEB1/+VkZrLmRpbNloZHplLQgL7+dYLWNI6rpw403TsWh pwOOSBSBmdxQdAoEt1DMI4k6qJCBQ== X-Received: by 2002:a05:6122:32c4:b0:5c3:61c2:9ec6 with SMTP id 71dfb90a1353d-5c5ce816be9mr160462e0c.7.1786976503922; Mon, 17 Aug 2026 07:21:43 -0700 (PDT) Received: from mandiga ([2804:1b3:a7c1:58d7:d5a4:b6b6:ccee:cdc]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5c5c78c91fdsm940507e0c.10.2026.08.17.07.21.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Aug 2026 07:21:43 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] elf: Fix ld.so SIGSEGV in trace mode with unresolved TLS symbols (BZ 34532) Date: Mon, 17 Aug 2026 11:21:37 -0300 Message-ID: <20260817142139.451836-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org On loongarch and hppa, running ld.so in trace mode on an object with dynamic relocations against undefined TLS symbols crashes with SIGSEGV. Add the same NULL guards used by all other targets. Checked on loongarch64-linux-gnu-lp64d and hppa-linux-gnu. --- elf/Makefile | 5 +++ elf/tst-trace-tls-mod.c | 41 +++++++++++++++++ elf/tst-trace-tls.c | 82 ++++++++++++++++++++++++++++++++++ sysdeps/hppa/dl-machine.h | 4 +- sysdeps/loongarch/dl-machine.h | 14 ++++-- 5 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 elf/tst-trace-tls-mod.c create mode 100644 elf/tst-trace-tls.c diff --git a/elf/Makefile b/elf/Makefile index dbc6cfec7fe..d9abbad1cf7 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -529,6 +529,7 @@ tests += \ tst-tlsalign \ tst-tlsalign-extern \ tst-tlsgap \ + tst-trace-tls \ tst-unique1 \ tst-unique2 \ tst-unwind-ctor \ @@ -1108,6 +1109,7 @@ modules-names += \ tst-tlsmod7 \ tst-tlsmod8 \ tst-tlsmod9 \ + tst-trace-tls-mod \ tst-unique1mod1 \ tst-unique1mod2 \ tst-unique2mod1 \ @@ -3544,6 +3546,9 @@ $(objpfx)tst-nodeps2-mod.so: $(common-objpfx)libc.so \ $(objpfx)tst-nodeps2.out: \ $(objpfx)tst-nodeps1-mod.so $(objpfx)tst-nodeps2-mod.so +$(objpfx)tst-trace-tls.out: $(objpfx)tst-trace-tls-mod.so $(objpfx)ld.so +tst-trace-tls-mod.so-no-z-defs = yes + $(objpfx)tst-tlsgap: $(shared-thread-library) $(objpfx)tst-tlsgap.out: \ $(objpfx)tst-tlsgap-mod0.so \ diff --git a/elf/tst-trace-tls-mod.c b/elf/tst-trace-tls-mod.c new file mode 100644 index 00000000000..7b855fd814c --- /dev/null +++ b/elf/tst-trace-tls-mod.c @@ -0,0 +1,41 @@ +/* Shared object with relocations against undefined TLS symbols. + 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 + . */ + +extern __thread int missing_tls_gd + __attribute__ ((tls_model ("global-dynamic"))); +extern __thread int missing_tls_ie + __attribute__ ((tls_model ("initial-exec"))); +extern int missing_data; + +int +access_tls_gd (void) +{ + return missing_tls_gd; +} + +int +access_tls_ie (void) +{ + return missing_tls_ie; +} + +int +access_data (void) +{ + return missing_data; +} diff --git a/elf/tst-trace-tls.c b/elf/tst-trace-tls.c new file mode 100644 index 00000000000..2d541b1a519 --- /dev/null +++ b/elf/tst-trace-tls.c @@ -0,0 +1,82 @@ +/* Check that trace mode handles unresolved TLS symbols (bug XXXXX). + Copyright (C) 2026 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include + +/* Check if unresolved TLS symbol in trace mode (LD_TRACE_LOADED_OBJECTS) + is correctly reported. */ + +static char *mod; + +static struct support_capture_subprocess +run_ldso (const char *env1, const char *env2) +{ + char *const argv[] = + { (char *) support_objdir_elf_ldso, (char *) mod, NULL }; + char *const envp[] = + { (char *) "LD_TRACE_LOADED_OBJECTS=1", (char *) env1, (char *) env2, + NULL }; + + struct support_capture_subprocess result + = support_capture_subprogram (argv[0], argv, envp); + support_capture_subprocess_check (&result, "tst-trace-tls", 0, + sc_allow_stdout | sc_allow_stderr); + return result; +} + +static void +run_trace (const char *title, const char *env1, const char *env2, + bool check_undefined) +{ + printf ("info: checking %s\n", title); + + struct support_capture_subprocess result = run_ldso (env1, env2); + + if (check_undefined) + { + TEST_VERIFY (strstr (result.err.buffer, + "undefined symbol: missing_tls_gd") != NULL); + TEST_VERIFY (strstr (result.err.buffer, + "undefined symbol: missing_tls_ie") != NULL); + TEST_VERIFY (strstr (result.err.buffer, + "undefined symbol: missing_data") != NULL); + } + + support_capture_subprocess_free (&result); +} + +static int +do_test (void) +{ + mod = xasprintf ("%s/elf/tst-trace-tls-mod.so", support_objdir_root); + + run_trace ("ldd -d", "LD_WARN=yes", NULL, true); + run_trace ("ldd -r", "LD_WARN=yes", "LD_BIND_NOW=1", true); + run_trace ("ldd -u", "LD_DEBUG=unused", NULL, false); + + free (mod); + + return 0; +} + +#include diff --git a/sysdeps/hppa/dl-machine.h b/sysdeps/hppa/dl-machine.h index 9bdbd85b6b3..ba2e4123c6e 100644 --- a/sysdeps/hppa/dl-machine.h +++ b/sysdeps/hppa/dl-machine.h @@ -700,7 +700,9 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[], #if !defined RTLD_BOOTSTRAP case R_PARISC_TLS_DTPMOD32: - value = sym_map->l_tls_modid; + /* The sym_map may be NULL in trace mode (LD_TRACE_LOADED_OBJECTS). */ + if (sym_map != NULL) + value = sym_map->l_tls_modid; break; case R_PARISC_TLS_DTPOFF32: diff --git a/sysdeps/loongarch/dl-machine.h b/sysdeps/loongarch/dl-machine.h index ae295264ae9..1fb2635f92e 100644 --- a/sysdeps/loongarch/dl-machine.h +++ b/sysdeps/loongarch/dl-machine.h @@ -197,16 +197,22 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[], #ifndef RTLD_BOOTSTRAP case __WORDSIZE == 64 ? R_LARCH_TLS_DTPMOD64 : R_LARCH_TLS_DTPMOD32: - *addr_field = sym_map->l_tls_modid; + /* The sym_map may be NULL in trace mode (LD_TRACE_LOADED_OBJECTS). */ + if (sym_map != NULL) + *addr_field = sym_map->l_tls_modid; break; case __WORDSIZE == 64 ? R_LARCH_TLS_DTPREL64 : R_LARCH_TLS_DTPREL32: - *addr_field = TLS_DTPREL_VALUE (sym) + reloc->r_addend; + if (sym != NULL) + *addr_field = TLS_DTPREL_VALUE (sym) + reloc->r_addend; break; case __WORDSIZE == 64 ? R_LARCH_TLS_TPREL64 : R_LARCH_TLS_TPREL32: - CHECK_STATIC_TLS (map, sym_map, sym); - *addr_field = TLS_TPREL_VALUE (sym_map, sym) + reloc->r_addend; + if (sym != NULL) + { + CHECK_STATIC_TLS (map, sym_map, sym); + *addr_field = TLS_TPREL_VALUE (sym_map, sym) + reloc->r_addend; + } break; case __WORDSIZE == 64 ? R_LARCH_TLS_DESC64 : R_LARCH_TLS_DESC32: