From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4fbeDT82mWqQgiMAWB0awg (envelope-from ) for ; Thu, 03 Sep 2026 04:56:31 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=r/sIb+DQ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2B9FA1E167; Thu, 03 Sep 2026 04:56:31 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_SBL_CSS autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id C0F3C1E09B for ; Thu, 03 Sep 2026 04:56:28 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0ED7B4BAE7CE for ; Thu, 3 Sep 2026 08:56:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0ED7B4BAE7CE Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=r/sIb+DQ Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 065484BA23E2 for ; Thu, 3 Sep 2026 08:56:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 065484BA23E2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 065484BA23E2 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788425762; cv=none; b=CxHm8XQXDQUAOenX2YVdVGdYllQbS5UsqPzzcb6gaP/FOLgoHldLvRVY8xN2OIFpb1ofPKLqxryhEzK6++2rwnn7XcDj5hqBTS3A3gmIX7GISvBkLJad4FBWtMnU+v/OyLLd5fX2r7CFuEfVv6ue/GmwiTOfTiGdE/VqPFBo9lE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788425762; c=relaxed/simple; bh=nfYyoXJVg9ODi8msD0MdxU53Bs5kcuOZJT9BGdxyhqk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m/lCWik+hY5HLeky9be5bBdao9ZLOaYpE0LcFjwCRbVyZum9CDCNTY1ImjrGUJzscNtItjAtpAdL+qzB0p/s3bmiUiRgqY2anWAbfWU11hYmtyW5b1zTKSJ54ZL1iIwY3tw5+RV504FVoVVPs79SweKvT21HJVQdnx4ryAFyMzE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=r/sIb+DQ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 065484BA23E2 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-398d2b28acfso1679026a91.1 for ; Thu, 03 Sep 2026 01:56:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788425761; x=1789030561; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Jh+zTz3PEDe5or3lS7by8evVQS7Bin35ft7LR6SHFxI=; b=r/sIb+DQhvAvEh17ha9cED5AZOG5YiFEA1fJaQStKt9sBd3/yhNKaW4dfFevSXJeuH J5tbUAeYYcZUbyqpvhX3mNDa0MSdIQ1dd6703QZLl4ugTglA0VonEoAbpi0EZE9422ZA nD2VSitCaYg476OUvYhVUmOczMfwz3BDjxkyiOiQU6Au5GVND3qdVktoDvjewy8Gvwiz xPbkt0Q1CzUXbqlBSDO7QNxTa8KwlVBFUCLHhSTsXGKHHrcM6ZLUugsgvqtxWi4hJ3A8 fxOawDDS9TG4C52wNrz8jRwv4CyuTa43B7FA9e20R0F8wvRQx00q/aTqY7bA7HwM8RMi gAwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788425761; x=1789030561; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Jh+zTz3PEDe5or3lS7by8evVQS7Bin35ft7LR6SHFxI=; b=rKf3y0Glo2rt4JyQa0TvyV7ij3TEqiYM9Lk3+IFTHDW2xr+nLdJh/F7o920YGpbADD nPVhyy3PmYmRsy2qpG0pg8Er52/6lWfAxJ4DQAvhQEAYQEI9Da5vbUoPTsnYR9LTsDeS wyc4oWQt4bF7X3iQWW6UsdbAbEjQCiEC8yYelIu+FKA6I+5TN9wWWVAxgB0N4MABvrOK tvE2FDfCaF0TtLt/4MhXnyjf5LxGZXoh7PWdcTeUZePWmpVRtTuZRpu7HCTR2AHdZ3HS t0u4PmCDLYrQ5q7lndspj6lABqwmQyKwo0X8LO1BjVIIcrbgl0TwwV4vaKdAxUz9uofk vKjw== X-Gm-Message-State: AFuF++m8y6ugrxQKlaA8BH0NhkuIJCwCFravUygqY/z+eDeFEAYp7SCn ADPdwmv90U/B3+JGzDz8lxV4oGsQXTKufmoBUKCBBBFbZPSgR1Wg7LwP X-Gm-Gg: AYBFou16toayd9ZCKNEKOLUb9p4bNX1X5xy36vC92qEUnQcc8YfDg+BeH4jAKQAWefL oL8OOAZRj+j+pbjZetbQVb/e7HOuuCS9W8cJdgEh/XgKulGpQ1G3i1HiPYrfgGDa0uXa+ZalAKF bf7C6RnqsNawKomhaVd+te8iXsZx7sr0ue4OykuDwJv+b5WafgD2UT20nj8pYk+XXVxkS4ID5KR pjQlzJrlx9t2nmRIDxjINbUpwWZneWnkZBDrahllGWoHoteOCsXu50CJJBzJGXnEyV5Rt6oIrjO tKKkvsHJMkWNKm0paSYvT18/vZIsJUIl0muux1ldFnqyU+VmiGm15QRhuG38lOQutwcPcHivrfY gDvoT0bVGhSNDNTQCu2u83sjKnW8g/mJYXzBo5zv8dk4Ugu8taB4q5lmgNkrPxNBGsPoAoYLq2z nPUN6bZhDULdWBgx2XwqG+fD027urUpwY6ncjpO7On7X+hURZ0tOgX4dtNNT8FuP1pR2CWOdkwK 6TvlIPfzuJBROaRMis4N1/RCZiV X-Received: by 2002:a17:90b:3907:b0:381:11eb:d78e with SMTP id 98e67ed59e1d1-39aee066e04mr13962071a91.14.1788425760806; Thu, 03 Sep 2026 01:56:00 -0700 (PDT) Received: from localhost.localdomain ([122.171.17.193]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-14319785bd8sm8012126c88.0.2026.09.03.01.55.57 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Sep 2026 01:55:59 -0700 (PDT) From: Aditya Vidyadhar Kamath To: ulrich.weigand@de.ibm.com, simon.marchi@polymtl.ca, tom@tromey.com Cc: gdb-patches@sourceware.org, Aditya.Kamath1@ibm.com, sangamesh.swamy@in.ibm.com Subject: [PATCH v3] Add TLS variable debug support for AIX [ 64-bit XCOFF files only] Date: Thu, 3 Sep 2026 14:25:24 +0530 Message-ID: <20260903085523.39514-2-akamath996@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Aditya Kamath This is a patch that adds TLS debug support for variables in AIX for 64 bit XCOFF binaries only. Currently in AIX, if we debug a TLS variable we get, (gdb) print tls_counter Cannot find thread-local variables on this target This patch uses thread pointer in R13 plus adds the offset to get the TLS variable address. Also adds the AIX specific gdbarch () methods. After this patch we get, gdb/gdb thread-local GNU gdb (GDB) 18.0.50.20260728-git Copyright (C) 2026 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "powerpc64-ibm-aix7.2.0.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: . +------------------------------------------------------------------------------+ | Find the GDB manual online at: | | http://www.gnu.org/software/gdb/documentation/. | | For help, type "help". | | Type "apropos word" to search for commands related to "word". | +------------------------------------------------------------------------------+ Reading symbols from thread-local... (gdb) b 16 Breakpoint 1 at 0x10000894: file thread-local.c, line 16. (gdb) r Starting program: /home/aditya/binutils-gdb/thread-local [New Thread 258 (tid 118292825) (id 2)] [Switching to thread 2 (Thread 258 (tid 118292825))] Thread 2 hit Breakpoint 1, thread_function (arg=0x1) at thread-local.c:16 16 sleep(1); (gdb) p tls_counter $1 = 100 (gdb) q On AIX the thread pointer is in R13. For variables defined in the main executable (lm_addr == 0) the linker resolves them to local-exec model: the XCOFF symbol value is a signed TP-relative offset baked in at link time. GDB reads R13 and returns tp + (int64_t)offset. Shared-library TLS is not yet supported and returns an error. --- gdb/rs6000-aix-tdep.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c index d823fea5645..76763f08e08 100644 --- a/gdb/rs6000-aix-tdep.c +++ b/gdb/rs6000-aix-tdep.c @@ -39,6 +39,7 @@ #include "gdbsupport/xml-utils.h" #include "trad-frame.h" #include "frame-unwind.h" +#include "inferior.h" /* If the kernel has to deliver a signal, it pushes a sigcontext structure on the stack and then calls the signal handler, passing @@ -1355,6 +1356,59 @@ rs6000_aix_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, offset, len, 0); } +/* For AIX, use the rs6000_aix_fetch_tls_load_module_address gdbarch method. */ + +static CORE_ADDR +rs6000_aix_fetch_tls_load_module_address (struct objfile *objfile) +{ + /* TLS variables from shared libraries cannot be directly fetched + via the thread pointer if they were loaded by dlopen(). */ + if (objfile->flags & OBJF_SHARED) + throw_error (TLS_GENERIC_ERROR, + _("TLS lookup via thread pointer is not supported for " + "shared library \"%s\"; full DTV-based lookup is not " + "yet implemented for AIX"), + objfile_name (objfile)); + + return 0; +} + +/* Implement the get_thread_local_address gdbarch method for AIX. + + On 64-bit AIX the thread pointer (TP) is in R13. For variables in + the main executable (lm_addr == 0) the XCOFF symbol value is a + signed TP-relative offset baked in at link time: + address = tp + (int64_t) offset */ + +static CORE_ADDR +rs6000_aix_get_thread_local_address (struct gdbarch *gdbarch, ptid_t ptid, + CORE_ADDR lm_addr, CORE_ADDR offset) +{ + ppc_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + /* Only 64-bit AIX is supported. */ + if (tdep->wordsize != 8) + throw_error (TLS_GENERIC_ERROR, + _("TLS lookup not yet supported for 32-bit AIX")); + + int tp_regnum = PPC_R0_REGNUM + 13; + regcache *regcache + = get_thread_arch_regcache (current_inferior (), ptid, gdbarch); + target_fetch_registers (regcache, tp_regnum); + + ULONGEST tp; + if (regcache->cooked_read (tp_regnum, &tp) != REG_VALID) + throw_error (TLS_GENERIC_ERROR, + _("Unable to fetch thread pointer for TLS lookup")); + + /* local-exec: XCOFF symbol value is a signed TP-relative offset. */ + if (lm_addr == 0) + return tp + (CORE_ADDR)(int64_t) offset; + + throw_error (TLS_GENERIC_ERROR, + _("TLS in shared libraries not yet supported on AIX")); +} + static void rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -1411,6 +1465,13 @@ rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch) set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset); set_gdbarch_make_solib_ops (gdbarch, make_aix_solib_ops); + + set_gdbarch_get_thread_local_address + (gdbarch, rs6000_aix_get_thread_local_address); + + set_gdbarch_fetch_tls_load_module_address + (gdbarch, rs6000_aix_fetch_tls_load_module_address); + frame_unwind_append_unwinder (gdbarch, &aix_sighandle_frame_unwind); } -- 2.51.2