On 2013-05-30 11:42, Iain Buclaw wrote:

It's the same problem with what we currently have.  LD when it gets
all reference symbols that are to go into the tls section (for Linux,
at least) has the right to reorder the symbols.  As such, trying to
push _tlsstart as the first symbol in the compiler has no guarantees
it will be the first symbol in the object file.

For Mac OS X there's a function to get a section form an image:

getsectbynamefromheader
getsectbynamefromheader_64

Documented here:

https://developer.apple.com/library/mac/#documentation/developertools/Reference/MachOReference/Reference/reference.html

You can get the mach_header (image) using this callback function:

_dyld_register_func_for_add_image

Or using the same approach Martin Nowak used for Linux.

The problem with the above function is that you cannot unregister the callback. If you have a dynamic library that registers a callback, i.e. druntime. If the dynamic library gets unloaded you will have a crash the next type "dlopen" is used.

A solution to that problem would be to either use the same approach Martin Nowak used or any of these undocumented functions from the dynamic linker:

void dyld_register_image_state_change_handler(dyld_image_states state, bool batch, dyld_image_state_change_handler handler)

Works like "_dyld_register_func_for_add_image" but will force the image using it to not be unloaded, or something like that.

Or:

void dyld_enumerate_tlv_storage(dyld_tlv_state_change_handler handler)

If I recall correctly, LDC is using "dyld_enumerate_tlv_storage".

--
/Jacob Carlborg

Reply via email to