[cxx-abi-dev] thread_local CONstructors

Richard Henderson rth at redhat.com
Wed Sep 26 14:59:44 UTC 2012


On 09/24/2012 08:49 PM, Jason Merrill wrote:
> Jakub suggested that it would be more efficient for variables that do need dynamic initialization to have the wrapper check a guard variable before calling the init function rather than from within the init function.  We could do that, too:
> 
> extern void i_init() __attribute ((weak));
> extern thread_local bool i_done __attribute ((weak));
> inline int& i_wrapper()
> {
>   if (i_init && !i_done) i_init();
>   return i;
> }
> 
> Note that we can't test the address of i_done to see if it's defined because undefined weak TLS variables resolve to a non-null pointer value.  So we test the address of i_init instead.

Given that I_DONE is thread_local, and could reside outside the current DSO, it is almost certain to require the use of the global-dynamic TLS model.  Which itself implies a function call to __tls_get_addr.

I think it likely that it would be more efficient to rely on I_INIT testing I_DONE at the start.  That's fewer symbols exported from a DSO, fewer runtime relocations, and since I_DONE can then be static, the use of the local-dynamic TLS model.  Which means that one call to __tls_get_addr can be shared for the lookup of I and I_DONE.


r~


More information about the cxx-abi-dev mailing list