TLS data/BSS alignment

Sebastian Huber sebastian.huber@embedded-brains.de
Mon Mar 23 12:41:03 GMT 2020


On 23/03/2020 13:22, Nick Clifton wrote:

> Hi Sebastian,
>
>> somehow the alignment of the TLS BSS section is applied also to the TLS data section.
> You didn't say for which architecture(s) this is happening, so I am
> assuming that you are working with x86_64...
I checked this with a native x86_64 GNU/Linux and some RTEMS 
cross-compilers (e.g. arm, powerpc, riscv). It seems some generic code 
is used here.
>
>> I tried to find the corresponding code in the GNU ld sources, but had no success so far.
> Have a look at this code in ld/ldfile.c:lang_output_section_find_by_flags()
>
> 	  if (!(differ & (SEC_THREAD_LOCAL | SEC_ALLOC)))
> 	    {
> 	      /* .tdata and .tbss must be adjacent and in that order.  */
> 	      if (!(look_flags & SEC_LOAD)
> 		  && (sec_flags & SEC_LOAD))
> 		/* ..so if we're at a .tbss section and we're placing
> 		   a .tdata section stop looking and return the
> 		   previous section.  */
> 		break;
> 	      found = look;
> 	      seen_thread_local = TRUE;
>
> This starts around line 1646 in the latest sources.  My reading
> of this code it that when placing the .tdata section the output
> section for the .tbss section is used and so it inherits its
> alignment.  I have not actually tested this theory however, but
> it might be a good place to start looking.
Thanks for the hint. I found this code also, but I didn't understand how 
the different output sections in the ELF file are generated. I guess I 
have to dig a bit deeper.



More information about the Binutils mailing list