Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Aditya Vidyadhar Kamath <akamath996@gmail.com>,
	ulrich.weigand@de.ibm.com,  tom@tromey.com
Cc: gdb-patches@sourceware.org, Aditya.Kamath1@ibm.com,
	sangamesh.swamy@in.ibm.com
Subject: Re: [PATCH v3 2/3] This patch adds support to debug thread local variables defined in shared libraries in AIX.
Date: Tue, 8 Sep 2026 11:20:26 -0400	[thread overview]
Message-ID: <5bbabb63-9cf0-4d66-b254-e6b4c2cf201c@polymtl.ca> (raw)
In-Reply-To: <20260908133222.70926-2-akamath996@gmail.com>

On 9/8/26 9:32 AM, Aditya Vidyadhar Kamath wrote:
> From: Aditya Vidyadhar Kamath <aditya.kamath1@ibm.com>
> 
> Sample debug output of this patch is as below
> Thread 3 hit Breakpoint 1, thread_runner (arg=0x2) at tls_main.c:36
> 36        volatile int bp_here = 0; (void)bp_here;
> 
> $3 = 20
> $4 = 40
> thread 2: my_tls_var=20  lib_tls_var=40
> [Thread 1 (tid 101646715) (id 1) exited]
> [Thread 515 (tid 88015327) (id 3) exited]
> [Inferior 1 (process 21758254) exited normally]
> 
> where lib_tls_var=40 is a variable from a thread library.
> 
> Module-id resolution for shared libraries uses two strategies:
> 
> 1. R_TLSML (local-dynamic): there is exactly one R_TLSML reloc per
>    module, and the loader always writes that module's own id into the
>    corresponding TOC slot.  Read it from the inferior and return it.
> 
> 2. R_TLSM (global-dynamic): each R_TLSM relocation in any loaded module's .loader
>    section references the library that exports the named TLS symbol.
>    Scan R_TLSM relocs across all loaded objfiles for each, resolve the
>    loader symbol name and check whether the library of interest exports
>    it.  If so, read the TOC slot value, that is the library's module-id.
>    Matching is done by symbol name, not by symbol value, so two
>    libraries that both define a TLS variable at within-module offset 0
>    are distinguished correctly.
> 
> The module-id is cached in a per-objfile structure so the .loader scan
> is paid only once per shared library.
> 
> Module-id 0 is a valid AIX loader assignment in initial-exec model and
> is not treated as "not yet allocated".  The main executable is
> distinguished from a module-id-0 library by returning the out-of-band
> sentinel XCOFF_MODID_MAIN_EXE (UINT64_MAX) instead of 0.
> 
> the address computation is done using 3 cases, they are:
> 
> - XCOFF_MODID_MAIN_EXE: local-exec where the XCOFF symbol value is the
>   signed TP-relative offset directly; address = tp + offset.
> 
> - module-id 0 is initial-execed shared library where the AIX loader merges all
>   initial-exec modules into one contiguous TLS segment and adjusts each
>   variable's TP-relative offset accordingly.  The link-time XCOFF symbol
>   value does not necessarily equal the runtime offset.  The patch scans
>   the library's R_TLS slots and matches by l_value (unique within one
>   module) to find the slot the loader filled with the actual runtime
>   TP-relative offset, then computes address = tp + runtime_offset.
> 
> - module-id n > 0 is global-dynamic where we iterate the per-thread thread vector:
>   tls_base = thread_vector[n]; address = tls_base + offset.

Please reword the commit subject to something like:

  Add support for TLS variables in shared libraries on AIX

Simon

  reply	other threads:[~2026-09-08 15:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-08 13:32 Aditya Vidyadhar Kamath
2026-09-08 15:20 ` Simon Marchi [this message]
2026-09-10  9:19   ` Aditya Kamath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5bbabb63-9cf0-4d66-b254-e6b4c2cf201c@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=Aditya.Kamath1@ibm.com \
    --cc=akamath996@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sangamesh.swamy@in.ibm.com \
    --cc=tom@tromey.com \
    --cc=ulrich.weigand@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox