<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Apr 29, 2013, at 5:18 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:</div><blockquote type="cite"><div dir="ltr">On Mon, Apr 29, 2013 at 5:13 PM, Bill Wendling <span dir="ltr"><<a href="mailto:isanbard@gmail.com" target="_blank">isanbard@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Apr 29, 2013, at 5:09 PM, Richard Smith <<a href="mailto:richard@metafoo.co.uk">richard@metafoo.co.uk</a>> wrote:<br>
<br>
> On Mon, Apr 29, 2013 at 3:27 PM, Bill Wendling <<a href="mailto:isanbard@gmail.com">isanbard@gmail.com</a>> wrote:<br>
> Author: void<br>
> Date: Mon Apr 29 17:27:16 2013<br>
> New Revision: 180739<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=180739&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=180739&view=rev</a><br>
> Log:<br>
> Emit the TLS intialization functions into a list.<br>
><br>
> Add the TLS initialization functions to a list of initialization functions. The<br>
> back-end takes this list and places the function pointers into the correct<br>
> section. This way they're called before `main().'<br>
><br>
> Why?<br>
<br>
</div>"Why" what? Just as the description says, we place the function pointers into the correct section and, at least on Darwin, the TLS variables are initialized via calls to the those function pointers. Just like global c'tors.</blockquote>
<div><br></div><div style="">OK, but why are we switching to eagerly initializing them rather than doing it lazily? That's going to be extremely expensive for applications which start lots of threads (say, by using std::async) and have thread_local variables with non-trivial construction or destruction -- and we still emit the dynamic initialization on every odr-use, so it doesn't seem to save us anything.</div></div></div></div></blockquote><div><br></div><div>This should be a Darwin-specific change.</div><div><br></div><div>The Darwin TLS model is that thread-local variables are lazily allocated and initialized, but only at the granularity of a single linkage unit. That is, as soon as one thread-local variable is touched, every other thread-local variable in that linkage unit is initialized at the same time. The linker implicitly synthesizes the access functions and, to do so, must receive a list of constructor functions to run, which is what this change collects. I'm not sure I can fully defend this design, but it's what we've got right now.</div><div><br></div><div>However, there is no need to apply this same model to ELF targets.</div><div><br></div><div>John.</div></div></body></html>