public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Question about the tls_model attribute
@ 2012-06-13 10:03 Hans Wennborg
  2012-06-13 10:07 ` Jakub Jelinek
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Wennborg @ 2012-06-13 10:03 UTC (permalink / raw)
  To: gcc-help, jakub; +Cc: Rafael Espindola

Hi,

I have a question about the semantics of the tls_model attribute in GCC.

For code such as this:

  static __thread int __attribute((tls_model("global-dynamic"))) x;
  int *f() { return &x; }

GCC will generate code using the global-dynamic model, also when
compiled without -fpic.

It does this even though it would be safe to use the faster local-exec
model, and the static linker will probably change the code to
local-exec anyway.

Is there a reason for this? The tls_model attribute was added in [1]
by Jakub, and it looks like that patch did go out of its way also to
support e.g. global-dynamic in non-pic code.

The reason I'm asking is that I'm adding support for this attribute in
LLVM, and we're discussing [2] what the semantics should be.

Thanks,
Hans

[1]. http://gcc.gnu.org/ml/gcc-patches/2002-09/msg00668.html
[2]. http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-June/050597.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about the tls_model attribute
  2012-06-13 10:03 Question about the tls_model attribute Hans Wennborg
@ 2012-06-13 10:07 ` Jakub Jelinek
  2012-06-13 10:24   ` Hans Wennborg
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Jelinek @ 2012-06-13 10:07 UTC (permalink / raw)
  To: Hans Wennborg; +Cc: gcc-help, Rafael Espindola

On Wed, Jun 13, 2012 at 11:03:01AM +0100, Hans Wennborg wrote:
> I have a question about the semantics of the tls_model attribute in GCC.
> 
> For code such as this:
> 
>   static __thread int __attribute((tls_model("global-dynamic"))) x;
>   int *f() { return &x; }
> 
> GCC will generate code using the global-dynamic model, also when
> compiled without -fpic.

That is correct, you've asked for it, therefore you get what you've asked
for.  The linker will probably optimize it back into local exec model,
but that is a separate thing.

	Jakub

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question about the tls_model attribute
  2012-06-13 10:07 ` Jakub Jelinek
@ 2012-06-13 10:24   ` Hans Wennborg
  0 siblings, 0 replies; 3+ messages in thread
From: Hans Wennborg @ 2012-06-13 10:24 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-help, Rafael Espindola

On Wed, Jun 13, 2012 at 11:07 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> On Wed, Jun 13, 2012 at 11:03:01AM +0100, Hans Wennborg wrote:
>> I have a question about the semantics of the tls_model attribute in GCC.
>>
>> For code such as this:
>>
>>   static __thread int __attribute((tls_model("global-dynamic"))) x;
>>   int *f() { return &x; }
>>
>> GCC will generate code using the global-dynamic model, also when
>> compiled without -fpic.
>
> That is correct, you've asked for it, therefore you get what you've asked
> for.

Are there any known examples of code that depends on this behavior?

I like the "you get what you asked for" semantics, I'm just trying to
figure out if there are more reasons.

Thanks,
Hans

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-06-13 10:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-13 10:03 Question about the tls_model attribute Hans Wennborg
2012-06-13 10:07 ` Jakub Jelinek
2012-06-13 10:24   ` Hans Wennborg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).