Hi Ulrich,

Thank you for the update. Please see my comments below. I am sending v5 version of the patch series.

>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 …

Please check the rs6000_aix_objfile_exports_symbol where name is matched to the owning library before l_value is compared


>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.

This is implemented implicitly. The runtime TOC value for an R_TLS_LD slot in an initial-exec library already holds the loader-adjusted absolute TP-relative offset, so reading it directly gives the right answer without needing a separate block-offset computation.


>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.
In v5 of the patch 
rs6000_aix_find_initial_exec_tls_offset () only scans R_TLS and R_TLS_LD slots , it does not scan R_TLS_IE. But R_TLS_IE slots don't need scanning, the linker writes the final absolute TP-relative offset directly into the XCOFF symbol value at link time, so offset (the static symbol value GDB received) is already correct. When no R_TLS/R_TLS_LD slot is found, the code falls through to:

return tp + (CORE_ADDR)(int64_t) offset;

Let me know if I missed anything that we need.


Thanks and regards,

Aditya.