[Issue 9476] Support native TLS on Mac OS X
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 7 04:34:34 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9476
--- Comment #2 from Jacob Carlborg <doob at me.com> 2013-03-07 04:34:32 PST ---
Right, I forgot about this. This is some information for a couple of post I
wrote in the newgroups:
Original code: http://pastebin.com/UKb6etWD
Disassembly with TLS: http://pastebin.com/nkdnE9w6
Disassembly without TLS: http://pastebin.com/vuvEBWWH
Object dump with TLS: http://pastebin.com/PqpPw56a
Object dump without TLS: http://pastebin.com/ki6atzEm
The source code for the dynamic linker on Mac OS X 10.7+ with the TLS handling:
http://opensource.apple.com/source/dyld/dyld-210.2.3/src/threadLocalHelpers.s
http://opensource.apple.com/source/dyld/dyld-210.2.3/src/threadLocalVariables.c
A description of what's basically happening in the source code above:
"I've done some investigation. Currently DMD inserts a call to the
__tls_get_addr function when accessing a TLS variable. This is implemented in
druntime.
In Mac OS X 10.7 it works similar but instead of inserting a call to
__tls_get_addr there's a struct looking like this (written in D) :
struct TLVDescriptor
{
void* function (TLVDescriptor*) thunk;
size_t key;
size_t offset;
}
The dynamic linker will iterate all loaded images and extract the section
containing the TLS data. I guess this section consists of a list of
TLVDescriptor*. The dynamic linker will set the "thunk" to a function
"tlv_get_addrs", implemented in assembly in the dynamic linker. It will set the
key to a key created by "pthread_key_create". It will also map the image with
this key. This key is same for all TLVDescriptor of a given image.
Instead of calling "__tls_get_addr" I think that the compiler will need to call
the thunk passing in the TLVDescriptor itself to the thunk.
The "tlv_get_addrs" function will then extract the key and from that key it can
get the image the address belongs to.
Does that make any sens? Is that something the DMD could do, that is call the
thunk instead of "__tls_get_addr".?"
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list