public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Force global-dynamic TLS model
@ 2020-06-23 20:37 Nikos Dragazis
  2020-06-24  8:59 ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Nikos Dragazis @ 2020-06-23 20:37 UTC (permalink / raw)
  To: gcc-help

Hi all,

Apologies if this has already been answered before.

I am experimenting with thread-local variables. I was wondering if it is
possible to make gcc force a specific TLS access model for some TLS
variables.

For example, let's say we have an ELF executable that defines and
accesses a TLS variable. From gcc's man page, I read that, in this case,
gcc will use the initial-exec TLS model by default. My question is if we
can change that and, say, use the global-dynamic model. To this end, I
have tried the `-ftls-model=global-dynamic` option and the `tls_model`
gcc variable attribute. None of these worked.

So, my question is: In this particular example, can we force gcc to use
the global-dynamic instead of the initial-exec TLS model?  And, in
general, can we force gcc to use global-dynamic for all accesses to
thread-local variables?

Thanks,
Nikos

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

* Re: Force global-dynamic TLS model
  2020-06-23 20:37 Force global-dynamic TLS model Nikos Dragazis
@ 2020-06-24  8:59 ` Florian Weimer
  2020-06-24 11:00   ` Nikos Dragazis
  0 siblings, 1 reply; 5+ messages in thread
From: Florian Weimer @ 2020-06-24  8:59 UTC (permalink / raw)
  To: Nikos Dragazis; +Cc: gcc-help

* Nikos Dragazis:

> For example, let's say we have an ELF executable that defines and
> accesses a TLS variable. From gcc's man page, I read that, in this case,
> gcc will use the initial-exec TLS model by default. My question is if we
> can change that and, say, use the global-dynamic model. To this end, I
> have tried the `-ftls-model=global-dynamic` option and the `tls_model`
> gcc variable attribute. None of these worked.

Try -ftls-model=global-dynamic -fpic.  This will prevent GCC from
performing relaxation.  For many targets, the link editor still performs
relaxation.  To turn this off, you will have to link the executable with
-shared, I think, with some hackery to produce an executable that can
actually be run.

Thanks,
Florian


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

* Re: Force global-dynamic TLS model
  2020-06-24  8:59 ` Florian Weimer
@ 2020-06-24 11:00   ` Nikos Dragazis
  2020-06-24 13:21     ` Segher Boessenkool
  0 siblings, 1 reply; 5+ messages in thread
From: Nikos Dragazis @ 2020-06-24 11:00 UTC (permalink / raw)
  To: Florian Weimer; +Cc: gcc-help

On 24/6/20 11:59 π.μ., Florian Weimer wrote:

> * Nikos Dragazis:
>
>> For example, let's say we have an ELF executable that defines and
>> accesses a TLS variable. From gcc's man page, I read that, in this case,
>> gcc will use the initial-exec TLS model by default. My question is if we
>> can change that and, say, use the global-dynamic model. To this end, I
>> have tried the `-ftls-model=global-dynamic` option and the `tls_model`
>> gcc variable attribute. None of these worked.
Hi Florian,

Thanks for the quick reply! Some comments inline.
> Try -ftls-model=global-dynamic -fpic.  This will prevent GCC from
> performing relaxation.
I tried this and, indeed, it forces the compiler to avoid relaxations.
Also the "tls_model" variable attribute worked in my case.
>    For many targets, the link editor still performs
> relaxation.  To turn this off, you will have to link the executable with
> -shared, I think, with some hackery to produce an executable that can
> actually be run.
You are right. This is what is happening in my case. So, the problem is
not the compiler, is the static linker. And there is no option that can
turn off relaxations on the static linker.

Thanks again,
Nikos

> Thanks,
> Florian
>

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

* Re: Force global-dynamic TLS model
  2020-06-24 11:00   ` Nikos Dragazis
@ 2020-06-24 13:21     ` Segher Boessenkool
  2020-06-24 13:23       ` Florian Weimer
  0 siblings, 1 reply; 5+ messages in thread
From: Segher Boessenkool @ 2020-06-24 13:21 UTC (permalink / raw)
  To: Nikos Dragazis; +Cc: Florian Weimer, gcc-help

On Wed, Jun 24, 2020 at 02:00:57PM +0300, Nikos Dragazis wrote:
> On 24/6/20 11:59 π.μ., Florian Weimer wrote:
> >   For many targets, the link editor still performs
> >relaxation.  To turn this off, you will have to link the executable with
> >-shared, I think, with some hackery to produce an executable that can
> >actually be run.
> You are right. This is what is happening in my case. So, the problem is
> not the compiler, is the static linker. And there is no option that can
> turn off relaxations on the static linker.

There is the --no-relax option to ld (pass it as -Wl,--no-relax from GCC),
but turing off all relaxation may have unintended consequences.


Segher

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

* Re: Force global-dynamic TLS model
  2020-06-24 13:21     ` Segher Boessenkool
@ 2020-06-24 13:23       ` Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2020-06-24 13:23 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: Nikos Dragazis, gcc-help

* Segher Boessenkool:

> On Wed, Jun 24, 2020 at 02:00:57PM +0300, Nikos Dragazis wrote:
>> On 24/6/20 11:59 π.μ., Florian Weimer wrote:
>> >   For many targets, the link editor still performs
>> >relaxation.  To turn this off, you will have to link the executable with
>> >-shared, I think, with some hackery to produce an executable that can
>> >actually be run.
>> You are right. This is what is happening in my case. So, the problem is
>> not the compiler, is the static linker. And there is no option that can
>> turn off relaxations on the static linker.
>
> There is the --no-relax option to ld (pass it as -Wl,--no-relax from GCC),
> but turing off all relaxation may have unintended consequences.

It does not seem to have an effect on these relocations, neither with
BFD ld nor gold.

Thanks,
Florian


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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 20:37 Force global-dynamic TLS model Nikos Dragazis
2020-06-24  8:59 ` Florian Weimer
2020-06-24 11:00   ` Nikos Dragazis
2020-06-24 13:21     ` Segher Boessenkool
2020-06-24 13:23       ` Florian Weimer

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).