* Use -ftls-model=local-exec for RTEMS by default? @ 2022-07-20 8:43 Sebastian Huber 2022-07-20 9:28 ` Sebastian Huber 0 siblings, 1 reply; 9+ messages in thread From: Sebastian Huber @ 2022-07-20 8:43 UTC (permalink / raw) To: GCC Development Hello, RTEMS applications are usually fully statically linked together with the operating system. So, we can use the -ftls-model=local-exec TLS model. The default value for this option is defined in common.opt: ftls-model= Common Joined RejectNegative Enum(tls_model) Var(flag_tls_default) Init(TLS_MODEL_GLOBAL_DYNAMIC) -ftls-model=[global-dynamic|local-dynamic|initial-exec|local-exec] Set the default thread-local storage code generation model. Would it be possible to customize the default value for RTEMS? -- 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/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Use -ftls-model=local-exec for RTEMS by default? 2022-07-20 8:43 Use -ftls-model=local-exec for RTEMS by default? Sebastian Huber @ 2022-07-20 9:28 ` Sebastian Huber 2022-07-20 11:41 ` Alexander Monakov 0 siblings, 1 reply; 9+ messages in thread From: Sebastian Huber @ 2022-07-20 9:28 UTC (permalink / raw) To: GCC Development On 20/07/2022 10:43, Sebastian Huber wrote: > Hello, > > RTEMS applications are usually fully statically linked together with the > operating system. So, we can use the -ftls-model=local-exec TLS model. > The default value for this option is defined in common.opt: > > ftls-model= > Common Joined RejectNegative Enum(tls_model) Var(flag_tls_default) > Init(TLS_MODEL_GLOBAL_DYNAMIC) > -ftls-model=[global-dynamic|local-dynamic|initial-exec|local-exec] > Set the default thread-local storage code generation model. > > Would it be possible to customize the default value for RTEMS? I think this could be done by adding #define CC1_SPEC "%{!ftls-model=*:-ftls-model=local-exec}" to gcc/config/rtems.h. However, the CC1_SPEC is also defined by several targets. Would it be possible to add an OS_CC1_SPEC like this? diff --git a/gcc/gcc.cc b/gcc/gcc.cc index bb07cc244e3..7ddabc888b0 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -709,6 +709,12 @@ proper position among the other output files. */ #define CC1_SPEC "" #endif +/* config.h can define OS_CC1_SPEC to provide extra args to cc1 and cc1plus + or operating system specific extra switch-translations. */ +#ifndef OS_CC1_SPEC +#define OS_CC1_SPEC "" +#endif + /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus or extra switch-translations. */ #ifndef CC1PLUS_SPEC @@ -1194,7 +1200,7 @@ proper position among the other output files. */ static const char *asm_debug = ASM_DEBUG_SPEC; static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC; static const char *cpp_spec = CPP_SPEC; -static const char *cc1_spec = CC1_SPEC; +static const char *cc1_spec = CC1_SPEC OS_CC1_SPEC; static const char *cc1plus_spec = CC1PLUS_SPEC; static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC; static const char *link_ssp_spec = LINK_SSP_SPEC; How does Ada get its default TLS model? -- 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/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Use -ftls-model=local-exec for RTEMS by default? 2022-07-20 9:28 ` Sebastian Huber @ 2022-07-20 11:41 ` Alexander Monakov 2022-07-20 11:48 ` Sebastian Huber 0 siblings, 1 reply; 9+ messages in thread From: Alexander Monakov @ 2022-07-20 11:41 UTC (permalink / raw) To: Sebastian Huber; +Cc: GCC Development 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). Alexander ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Use -ftls-model=local-exec for RTEMS by default? 2022-07-20 11:41 ` Alexander Monakov @ 2022-07-20 11:48 ` Sebastian Huber 2022-07-20 13:01 ` Alexander Monakov 0 siblings, 1 reply; 9+ messages in thread From: Sebastian Huber @ 2022-07-20 11:48 UTC (permalink / raw) To: Alexander Monakov; +Cc: GCC Development 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: powerpc-rtems6-gcc -S -O2 -o - tls.c .file "tls.c" .machine ppc .section ".text" .align 2 .globl f .type f, @function f: .LFB0: .cfi_startproc lis 9,_GLOBAL_OFFSET_TABLE_@ha addis 10,2,j@tprel@ha la 9,_GLOBAL_OFFSET_TABLE_@l(9) addi 10,10,j@tprel@l lwz 9,i@got@tprel(9) lwz 10,0(10) add 9,9,i@tls lwz 3,0(9) add 3,3,10 blr .cfi_endproc .LFE0: .size f,.-f .globl j .section .tbss,"awT",@nobits .align 2 .type j, @object .size j, 4 j: .zero 4 .ident "GCC: (GNU) 12.1.1 20220711 [master 5efa23f3389]" .section .note.GNU-stack,"",@progbits and: powerpc-rtems6-gcc -S -O2 -o - tls.c -ftls-model=local-exec .file "tls.c" .machine ppc .section ".text" .align 2 .globl f .type f, @function f: .LFB0: .cfi_startproc addis 10,2,i@tprel@ha addis 9,2,j@tprel@ha addi 10,10,i@tprel@l addi 9,9,j@tprel@l lwz 3,0(10) lwz 9,0(9) add 3,3,9 blr .cfi_endproc .LFE0: .size f,.-f .globl j .section .tbss,"awT",@nobits .align 2 .type j, @object .size j, 4 j: .zero 4 .ident "GCC: (GNU) 12.1.1 20220711 [master 5efa23f3389]" .section .note.GNU-stack,"",@progbits -- 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/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Use -ftls-model=local-exec for RTEMS by default? 2022-07-20 11:48 ` Sebastian Huber @ 2022-07-20 13:01 ` Alexander Monakov 2022-07-21 5:25 ` Sebastian Huber 0 siblings, 1 reply; 9+ messages in thread From: Alexander Monakov @ 2022-07-20 13:01 UTC (permalink / raw) To: Sebastian Huber; +Cc: GCC Development 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). HTH Alexander ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Use -ftls-model=local-exec for RTEMS by default? 2022-07-20 13:01 ` Alexander Monakov @ 2022-07-21 5:25 ` Sebastian Huber 2022-07-21 8:03 ` Iain Sandoe 0 siblings, 1 reply; 9+ messages in thread From: Sebastian Huber @ 2022-07-21 5:25 UTC (permalink / raw) To: Alexander Monakov; +Cc: GCC Development 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/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Use -ftls-model=local-exec for RTEMS by default? 2022-07-21 5:25 ` Sebastian Huber @ 2022-07-21 8:03 ` Iain Sandoe 2022-07-22 11:19 ` Sebastian Huber 0 siblings, 1 reply; 9+ messages in thread From: Iain Sandoe @ 2022-07-21 8:03 UTC (permalink / raw) To: Sebastian Huber; +Cc: Alexander Monakov, GCC Development > On 21 Jul 2022, at 06:25, Sebastian Huber <sebastian.huber@embedded-brains.de> wrote: > > 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. (IMO) It can be not too tricky - Darwin customises several - you just have to override the default definition in your target-specific header and provide the replacement e.g ( override in config/darwin.h, replacement in config/darwin.cc): #undef TARGET_ENCODE_SECTION_INFO #define TARGET_ENCODE_SECTION_INFO darwin_encode_section_info 0.02GBP only, as always ;) Iain > > -- > 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/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Use -ftls-model=local-exec for RTEMS by default? 2022-07-21 8:03 ` Iain Sandoe @ 2022-07-22 11:19 ` Sebastian Huber 2022-07-22 11:35 ` Iain Sandoe 0 siblings, 1 reply; 9+ messages in thread From: Sebastian Huber @ 2022-07-22 11:19 UTC (permalink / raw) To: Iain Sandoe; +Cc: GCC Development On 21.07.22 10:03, Iain Sandoe wrote: >> 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. > (IMO) It can be not too tricky - Darwin customises several - you just have to override the default definition in your target-specific header and provide the replacement e.g ( override in config/darwin.h, replacement in config/darwin.cc): > > #undef TARGET_ENCODE_SECTION_INFO > #define TARGET_ENCODE_SECTION_INFO darwin_encode_section_info The problem is that in this case you need a target-specific copy and paste solution. For example lets suppose you want to use #define CC1_SPEC "%{!ftls-model=*:-ftls-model=local-exec}" for RTEMS (in gcc/config/rtems.h), then you have a problem on for example microblaze (gcc/config/microblaze/microblaze.h): #ifndef CC1_SPEC #define CC1_SPEC " \ %{G*} \ %(subtarget_cc1_spec) \ %{mxl-multiply-high:-mcpu=v6.00.a} \ " #endif or nios2 (gcc/config/nios2/nios2.h): #define CC1_SPEC "%{G*}" For each target you would have to check if you have to provide some extra times for CC1_SPEC through copy and paste. -- 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/ ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Use -ftls-model=local-exec for RTEMS by default? 2022-07-22 11:19 ` Sebastian Huber @ 2022-07-22 11:35 ` Iain Sandoe 0 siblings, 0 replies; 9+ messages in thread From: Iain Sandoe @ 2022-07-22 11:35 UTC (permalink / raw) To: Sebastian Huber; +Cc: GCC Development > On 22 Jul 2022, at 12:19, Sebastian Huber <sebastian.huber@embedded-brains.de> wrote: > > On 21.07.22 10:03, Iain Sandoe wrote: >>> 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. >> (IMO) It can be not too tricky - Darwin customises several - you just have to override the default definition in your target-specific header and provide the replacement e.g ( override in config/darwin.h, replacement in config/darwin.cc): >> #undef TARGET_ENCODE_SECTION_INFO >> #define TARGET_ENCODE_SECTION_INFO darwin_encode_section_info > > The problem is that in this case you need a target-specific copy and paste solution. For example lets suppose you want to use > > #define CC1_SPEC "%{!ftls-model=*:-ftls-model=local-exec}" > > for RTEMS (in gcc/config/rtems.h), then you have a problem on for example microblaze (gcc/config/microblaze/microblaze.h): > > #ifndef CC1_SPEC > #define CC1_SPEC " \ > %{G*} \ > %(subtarget_cc1_spec) \ > %{mxl-multiply-high:-mcpu=v6.00.a} \ > " > #endif > > or nios2 (gcc/config/nios2/nios2.h): > > #define CC1_SPEC "%{G*}" > > For each target you would have to check if you have to provide some extra times for CC1_SPEC through copy and paste. Yes, there is a curious ‘inversion’ process where, to the OS, the architectures are sub-targets, but to the GCC implementation the OSs are sub-targets of the arch, it can be possible to work around this by declaring SUBTARGET_SPEC_XXXX and then appending that to the various users. However, it could be that even that will not work easily in this case. Iain ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-07-22 11:35 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2022-07-20 8:43 Use -ftls-model=local-exec for RTEMS by default? Sebastian Huber 2022-07-20 9:28 ` Sebastian Huber 2022-07-20 11:41 ` Alexander Monakov 2022-07-20 11:48 ` Sebastian Huber 2022-07-20 13:01 ` Alexander Monakov 2022-07-21 5:25 ` Sebastian Huber 2022-07-21 8:03 ` Iain Sandoe 2022-07-22 11:19 ` Sebastian Huber 2022-07-22 11:35 ` Iain Sandoe
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).