From: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
To: "akamath996@gmail.com" <akamath996@gmail.com>,
"tom@tromey.com" <tom@tromey.com>,
"simon.marchi@polymtl.ca" <simon.marchi@polymtl.ca>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
SANGAMESH MALLAYYA <sangamesh.swamy@in.ibm.com>,
Aditya Kamath <Aditya.Kamath1@ibm.com>
Subject: Re: [PATCH v4 2/3] Add support for TLS variables in shared libraries on AIX.
Date: Thu, 10 Sep 2026 10:46:00 +0000 [thread overview]
Message-ID: <405a947722b44e71d60ca1e8667a4660bcee58b2.camel@de.ibm.com> (raw)
In-Reply-To: <20260910101553.85926-2-akamath996@gmail.com>
Aditya Vidyadhar Kamath <akamath996@gmail.com> wrote:
>- 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.
That last part I suspect still won't work correctly in all cases:
+ /* l_value holds the link-time TP-relative offset. It is unique
+ within a module, so matching against static_offset identifies
+ exactly the right variable. */
+ if ((CORE_ADDR)(int64_t) ldsym.l_value != static_offset)
+ continue;
Sure, the offset is unique within the module where the TLS variable
is defined. But you are not actually guaranteed to be within that
module at this point. In fact, more likely than not, "objfile" at
this point is some *other* module that has a *reference* to the
TLS variable in question - or actually some *other* TLS variable
defined in another module with the same static offset ...
I guess you could again compare names here. Or else, maybe you can
actually pre-compute the offset earlier: at the point where you find
a R_TLSM relocation referencing a module, and the module ID is zero,
shouldn't there be a R_TLS relocation for that same symbol as well?
If you compare the relocated TOC value for R_TLS with the static
offset of the symbol, that difference should be the (fixed) offset
of the module's TLS block within the merged initial-exec TLS block.
So you could remember a pair of "(module ID; offset)" and then
apply the offset when resolving symbols. (Maybe the pair can be
encoded more efficiently since you only need the offset if the
module ID is zero.)
I'm not sure how to handle the R_TLSML case - I think if a module
has that relocation, there should also be at least one instance
of an R_TLS_LD to a symbol in the module, and then you could
again compute the block offset.
However, I guess depending on compiler options it might also be
the case that all references to TLS symbols in a given module
happen to only use R_TLS_IE - in that case, you know the module
must be in the initial-exec segment (i.e. module ID zero), and
then again get the offset from the R_TLS_IE relocated value.
Bye,
Ulrich
prev parent reply other threads:[~2026-09-10 10:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-10 10:15 Aditya Vidyadhar Kamath
2026-09-10 10:46 ` Ulrich Weigand [this message]
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=405a947722b44e71d60ca1e8667a4660bcee58b2.camel@de.ibm.com \
--to=ulrich.weigand@de.ibm.com \
--cc=Aditya.Kamath1@ibm.com \
--cc=akamath996@gmail.com \
--cc=gdb-patches@sourceware.org \
--cc=sangamesh.swamy@in.ibm.com \
--cc=simon.marchi@polymtl.ca \
--cc=tom@tromey.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