Solaris/x86 port - how to get the TLS section?

Kai Nacke via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Thu Nov 27 09:39:20 PST 2014


On Thursday, 27 November 2014 at 12:23:18 UTC, Jacob Carlborg 
wrote:
> On 2014-11-26 18:33, Kai Nacke wrote:
>
>> That is no problem. The trouble starts because the TLS section 
>> is
>> allocated for every thread (at least if the thread touches a 
>> variable in
>> this section). I need to find the start of the section at 
>> runtime for a
>> thread. The module id helps her because __tls_get_addr() can 
>> then be used.
>
> Are you referring what you're supposed to pass to 
> __tls_get_addr when generating a call to __tls_get_addr in the 
> compiler?
>
> Or is it in the runtime where you need to access the TLS data 
> to get the roots for the GC?

Here are the dirty details:

On Linux and FreeBSD, the module id and size of the TLS section 
is found in the ELF structure dl_phdr_info. The module id is 
converted to a pointer to the first byte of the TLS section for 
every thread:

     auto ti = tls_index(moduleId, 0);
     return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. sz];

(sz is the size)

Solaris does not have the dl_phdr_info.dlpi_tls_modid field 
therefore this methods breaks.

But I think I found the solution. After reading the link you 
posted the tenth time I realized the following sentence:

"The static TLS arena associated with the calculated TLS size 
tlssizeS, is placed immediately preceding the thread pointer tpt. 
Accesses to this TLS data is based off of subtractions from tpt."

The thread pointer is fs:0 or gs:0 on Intel and r7 on Sparc. The 
size of the TLS data is found in the ELF header as before. I 
simply need to do the rounding as documented in the chapter and 
then I can calculate the required pointer.

Great!!!

Regards,
Kai


More information about the digitalmars-d-ldc mailing list