Use -ftls-model=local-exec for RTEMS by default?

Sebastian Huber sebastian.huber@embedded-brains.de
Thu Jul 21 05:25:59 GMT 2022


On 20.07.22 15:01, Alexander Monakov wrote:
> On Wed, 20 Jul 2022, Sebastian Huber wrote:
> 
>> On 20/07/2022 13:41, Alexander Monakov wrote:
>>> On Wed, 20 Jul 2022, Sebastian Huber wrote:
>>>
>>>> How does Ada get its default TLS model?
>>> You shouldn't need to do anything special, GCC automatically selects
>>> initial-exec or local-exec for non-PIC (including PIE).
>> I am not sure, for this test program:
>>
>> extern _Thread_local int i;
>> _Thread_local int j;
>>
>> int f(void)
>> {
>>    return i + j;
>> }
>>
>> I get:
> [snip]
> 
> Thanks, I missed that you are asking about promoting initial-exec to local-exec
> rather than x-dynamic to y-exec. There's a pending patch that implements such
> promotion based on visibility information:
> https://gcc.gnu.org/pipermail/gcc-patches/2022-July/598017.html
> 
> With that patch, you'll get local-exec model for the extern variable 'i' if you
> inform the compiler that its definition will end up in the current module:
> 
> __attribute__((visibility("hidden")))
> extern _Thread_local int i;
> _Thread_local int j;
> 
> int f(void)
> {
>    return i + j;
> }
> 
> Thus I would try to enhance the binds_local_p target hook for RTEMS to inform
> the compiler that there's no dynamic linking (although apart from TLS variables
> I cannot instantly name other places where it would enhance optimization).

This sounds like an interesting approach in the long run, however, I 
need a short term solution which I can back port to GCC 10, 11, and 12. 
I guess I will add a

MULTILIB_EXTRA_OPTS = ftls-model=local-exec

to all RTEMS multilib configurations.

In general I think the target hooks are hard to customize for operating 
systems.

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/


More information about the Gcc mailing list