Supporting emulated tls

Iain Buclaw ibuclaw at ubuntu.com
Sun Mar 18 05:21:51 PDT 2012


On 18 March 2012 11:32, Johannes Pfau <nospam at example.com> wrote:
> I thought about supporting emulated tls a little. The GCC emutls.c
> implementation currently can't work with the gc, as every TLS variable
> is allocated individually and therefore we don't have a contiguous
> memory region for the gc. I think these are the possible solutions:
>
> * Try to fix GCCs emutls to allocate all tls memory for a module
>  (application/shared object) at once. That's the best solution
>  and native TLS works this way, but I'm not sure if we can extract
>  enough information from the runtime linker to make this work (we
>  need at least the combined size of all tls variables).
>
> * Provide a callback in GCC's emutls which is called after every
>  allocation. This could call GC.addRange for every variable, but I
>  guess adding huge amounts of ranges is slow.
>

Painfully slow.


> * Make it possible to register a custom allocator for GCC's emutls (not
>  sure if possible, as this would have to be set up very early in
>  application startup). Then allocate the memory directly from the GC
>  (but this memory should only be scanned, not collected)
>
> * Replace the calls to mallloc in emutls.c with a custom, region based
>  memory allocator. (This is not a perfect solution though, it can
>  always happen that we'll need more memory)
>
>
>
> * Do not use GCC's emutls at all, roll a custom solution. This could be
>  compatible with / based on dmd's tls emulation for OSX. Most of the
>  implementation is in core.thread, all that's necessary is to group
>  the tls data into a _tls_data_array and call ___tls_get_addr for
>  every tls access. I'm not sure if this can be done in the
>  'middle-end' though and it doesn't support shared libraries yet.
>

If we are going to fix TLS, I'd rather it be in the most platform
agnostic way possible, if it could be helped. That would mean also
scrapping the current implementation on Linux (just tries to mimic
what dmd does, and has corner cases where it doesn't always get it
right).




-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the D.gnu mailing list