<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Linkers part 7</title>
	<atom:link href="http://www.airs.com/blog/archives/44/feed" rel="self" type="application/rss+xml" />
	<link>http://www.airs.com/blog/archives/44</link>
	<description>Ian Lance Taylor</description>
	<lastBuildDate>Mon, 26 Jul 2010 08:38:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-18291</link>
		<dc:creator>Ian Lance Taylor</dc:creator>
		<pubDate>Mon, 15 Mar 2010 16:54:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-18291</guid>
		<description>Thanks for the comment.  I guess I&#039;m not sure just what you are saying.  It&#039;s true that when an executable uses the default IE model to access a TLS variable defined in a shared library, the dynamic linker has to resolve that access at startup time, rather than lazily.  This doesn&#039;t really affect how the shared libraries access the TLS variable, though; they will continue to use a function call to resolve the address.

Lazy binding is not really a feature of TLS variables.  Lazy binding is used for function calls, not variable references.  TLS variables do support lazy allocation, which is not quite the same thing.  It&#039;s true that if an executable refers to a TLS variable, then that variable can not be allocated lazily.  But that doesn&#039;t really matter, as the allocation of a TLS variable referenced by an executable is essentially free.  It simply becomes part of the executable&#039;s TLS segment.</description>
		<content:encoded><![CDATA[<p>Thanks for the comment.  I guess I&#8217;m not sure just what you are saying.  It&#8217;s true that when an executable uses the default IE model to access a TLS variable defined in a shared library, the dynamic linker has to resolve that access at startup time, rather than lazily.  This doesn&#8217;t really affect how the shared libraries access the TLS variable, though; they will continue to use a function call to resolve the address.</p>
<p>Lazy binding is not really a feature of TLS variables.  Lazy binding is used for function calls, not variable references.  TLS variables do support lazy allocation, which is not quite the same thing.  It&#8217;s true that if an executable refers to a TLS variable, then that variable can not be allocated lazily.  But that doesn&#8217;t really matter, as the allocation of a TLS variable referenced by an executable is essentially free.  It simply becomes part of the executable&#8217;s TLS segment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: erichtsai</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-18290</link>
		<dc:creator>erichtsai</dc:creator>
		<pubDate>Mon, 15 Mar 2010 10:52:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-18290</guid>
		<description>Great blog!

After went through a couple of TLS related documents, I still have questions.  It seems to me that, by default, an executable will use IE model to access external TLS variable.   With IE model, an executable can access all TLS variables in shared libraries explicitly linked with that executable.  So, I think these shared objects can&#039;t support lazy binding for this executable any more.  In order to support lazy binding, either GD model or dlsym() has to be used.  Am I right?

Thanks!

Eric</description>
		<content:encoded><![CDATA[<p>Great blog!</p>
<p>After went through a couple of TLS related documents, I still have questions.  It seems to me that, by default, an executable will use IE model to access external TLS variable.   With IE model, an executable can access all TLS variables in shared libraries explicitly linked with that executable.  So, I think these shared objects can&#8217;t support lazy binding for this executable any more.  In order to support lazy binding, either GD model or dlsym() has to be used.  Am I right?</p>
<p>Thanks!</p>
<p>Eric</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-14798</link>
		<dc:creator>Ian Lance Taylor</dc:creator>
		<pubDate>Tue, 16 Sep 2008 14:22:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-14798</guid>
		<description>__thread only works for global or static variables.  It sounds like you wrote

int main() { __thread int i; }

That makes i a local variable in main, which in C is known as an &quot;auto&quot; variable (from the very old but still supported syntax &quot;auto int i;&quot;).  A local variable can not be a TLS variable.  Or, to put it another way, local variables are always TLS variables, in the sense that they can only be accessed by a single thread.  TLS only makes sense when speaking about variables which can be accessed by multiple threads, which means a global or static variable.</description>
		<content:encoded><![CDATA[<p>__thread only works for global or static variables.  It sounds like you wrote</p>
<p>int main() { __thread int i; }</p>
<p>That makes i a local variable in main, which in C is known as an &#8220;auto&#8221; variable (from the very old but still supported syntax &#8220;auto int i;&#8221;).  A local variable can not be a TLS variable.  Or, to put it another way, local variables are always TLS variables, in the sense that they can only be accessed by a single thread.  TLS only makes sense when speaking about variables which can be accessed by multiple threads, which means a global or static variable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: avjo</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-14797</link>
		<dc:creator>avjo</dc:creator>
		<pubDate>Mon, 15 Sep 2008 12:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-14797</guid>
		<description>Hi Ian,

When I&#039;m trying to use __thread in an application, I get the following gcc error:

error: function-scope â€˜iâ€™ implicitly auto and declared â€˜__threadâ€™

(all I did is trying to compile an empty C main with the line &#039;__thread int i;&#039;)

Any idea what is wrong ? (I&#039;m using gcc 4.2.3 (Ubuntu 4.2.3-2ubuntu7) on 2.6.24-19 (ubuntu generic x86_64 kernel) on x86_64 platform...

The compile line is just &#039;gcc attempt.c&#039;..

Thank you!
~avjo</description>
		<content:encoded><![CDATA[<p>Hi Ian,</p>
<p>When I&#8217;m trying to use __thread in an application, I get the following gcc error:</p>
<p>error: function-scope â€˜iâ€™ implicitly auto and declared â€˜__threadâ€™</p>
<p>(all I did is trying to compile an empty C main with the line &#8216;__thread int i;&#8217;)</p>
<p>Any idea what is wrong ? (I&#8217;m using gcc 4.2.3 (Ubuntu 4.2.3-2ubuntu7) on 2.6.24-19 (ubuntu generic x86_64 kernel) on x86_64 platform&#8230;</p>
<p>The compile line is just &#8216;gcc attempt.c&#8217;..</p>
<p>Thank you!<br />
~avjo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: avjo</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-12624</link>
		<dc:creator>avjo</dc:creator>
		<pubDate>Wed, 23 Apr 2008 06:07:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-12624</guid>
		<description>Thank you.

(PS - I still hope to pre-order you Linkers book one day ;)</description>
		<content:encoded><![CDATA[<p>Thank you.</p>
<p>(PS &#8211; I still hope to pre-order you Linkers book one day <img src='http://www.airs.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-12613</link>
		<dc:creator>Ian Lance Taylor</dc:creator>
		<pubDate>Wed, 23 Apr 2008 01:15:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-12613</guid>
		<description>As long as your kernel is 2.6.x, you should be able to use __thread variables.  The only reason I know to prefer pthread_getspecific is that you can pass a destructor routine to pthread_key_create, which will be run when a thread exits.  I don&#039;t think there is any way to run a destructor for a __thread variable.  In general __thread variables are more efficient and should be preferred.</description>
		<content:encoded><![CDATA[<p>As long as your kernel is 2.6.x, you should be able to use __thread variables.  The only reason I know to prefer pthread_getspecific is that you can pass a destructor routine to pthread_key_create, which will be run when a thread exits.  I don&#8217;t think there is any way to run a destructor for a __thread variable.  In general __thread variables are more efficient and should be preferred.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: avjo</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-12505</link>
		<dc:creator>avjo</dc:creator>
		<pubDate>Sun, 20 Apr 2008 17:51:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-12505</guid>
		<description>Hi Ian,

Is there any reason at all to prefer the pthread_getspecific/setspecific
library calls over a __thread variable ?

What about embedded systems with relatively old kernels (2.6.10 the
oldest) ?

Thanks!
~avjo</description>
		<content:encoded><![CDATA[<p>Hi Ian,</p>
<p>Is there any reason at all to prefer the pthread_getspecific/setspecific<br />
library calls over a __thread variable ?</p>
<p>What about embedded systems with relatively old kernels (2.6.10 the<br />
oldest) ?</p>
<p>Thanks!<br />
~avjo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-6460</link>
		<dc:creator>Ian Lance Taylor</dc:creator>
		<pubDate>Wed, 07 Nov 2007 15:23:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-6460</guid>
		<description>They don&#039;t seem to be in the assembler documentation.  I think your best bet would be look at the i386 ELF ABI supplement and at the TLS documentation.  Here are some links.  Look for the sample assembler code.  In general the keywords correlate to specific relocation types.

http://sco.com/developers/devspecs/
http://docs.sun.com/app/docs/doc/817-1984/6mhm7pl2a
http://people.redhat.com/drepper/tls.pdf
http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/RFC-TLSDESC-x86.txt</description>
		<content:encoded><![CDATA[<p>They don&#8217;t seem to be in the assembler documentation.  I think your best bet would be look at the i386 ELF ABI supplement and at the TLS documentation.  Here are some links.  Look for the sample assembler code.  In general the keywords correlate to specific relocation types.</p>
<p><a href="http://sco.com/developers/devspecs/" rel="nofollow">http://sco.com/developers/devspecs/</a><br />
<a href="http://docs.sun.com/app/docs/doc/817-1984/6mhm7pl2a" rel="nofollow">http://docs.sun.com/app/docs/doc/817-1984/6mhm7pl2a</a><br />
<a href="http://people.redhat.com/drepper/tls.pdf" rel="nofollow">http://people.redhat.com/drepper/tls.pdf</a><br />
<a href="http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/RFC-TLSDESC-x86.txt" rel="nofollow">http://www.lsd.ic.unicamp.br/~oliva/writeups/TLS/RFC-TLSDESC-x86.txt</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: avjo</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-6457</link>
		<dc:creator>avjo</dc:creator>
		<pubDate>Wed, 07 Nov 2007 15:04:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-6457</guid>
		<description>Hi Ian and thanks for the explanation.

Do you know of any online page I can read more about
this list of supported keywords ?

Thanks again
~avjo</description>
		<content:encoded><![CDATA[<p>Hi Ian and thanks for the explanation.</p>
<p>Do you know of any online page I can read more about<br />
this list of supported keywords ?</p>
<p>Thanks again<br />
~avjo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Lance Taylor</title>
		<link>http://www.airs.com/blog/archives/44/comment-page-1#comment-6338</link>
		<dc:creator>Ian Lance Taylor</dc:creator>
		<pubDate>Mon, 05 Nov 2007 14:13:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.airs.com/blog/archives/44#comment-6338</guid>
		<description>Thanks for the note.

The &#039;@&#039; keywords are extensions to the existing assembly language.  They don&#039;t change the assembly, but they tell the assembler which relocation types to generate for the operand to which they are attached.  The supported keywords are: PLTOFF (64-bit only), PLT,  GOTPLT (64-bit only),  GOTOFF, GOTPCREL (64-bit only),  TLSGD, TLSLDM, TLSLD (64-bit only), GOTTPOFF,  TPOFF, NTPOFF (32-bit only), DTPOFF, GOTNTPOFF (32-bit only), INDNTPOFF (32-bit only), GOT, TLSDESC, TLSCALL.

The %gs register is a segment register.  The x86 supports several segment registers.  These days they are generally all set to the same value, but in the 80286 days they were used to select different portions of memory for different parts of the program.  %gs:0 means address 0 in the segment addressed by the %gs segment register.</description>
		<content:encoded><![CDATA[<p>Thanks for the note.</p>
<p>The &#8216;@&#8217; keywords are extensions to the existing assembly language.  They don&#8217;t change the assembly, but they tell the assembler which relocation types to generate for the operand to which they are attached.  The supported keywords are: PLTOFF (64-bit only), PLT,  GOTPLT (64-bit only),  GOTOFF, GOTPCREL (64-bit only),  TLSGD, TLSLDM, TLSLD (64-bit only), GOTTPOFF,  TPOFF, NTPOFF (32-bit only), DTPOFF, GOTNTPOFF (32-bit only), INDNTPOFF (32-bit only), GOT, TLSDESC, TLSCALL.</p>
<p>The %gs register is a segment register.  The x86 supports several segment registers.  These days they are generally all set to the same value, but in the 80286 days they were used to select different portions of memory for different parts of the program.  %gs:0 means address 0 in the segment addressed by the %gs segment register.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
