Gcc / ld: overlapping sections (.tbss, .init_array) in a statically linked ELF binary

I compile a very simple one-line hi-world on a Debian 7 system on an x86_64 machine with gcc version 4.8.2 (Debian 4.8.2-21):

gcc test.c -static -o test

and I get an ELF executable that includes the following sections:

[17] .tdata            PROGBITS         00000000006b4000  000b4000
     0000000000000020  0000000000000000 WAT       0     0     8
[18] .tbss             NOBITS           00000000006b4020  000b4020
     0000000000000030  0000000000000000 WAT       0     0     8
[19] .init_array       INIT_ARRAY       00000000006b4020  000b4020
     0000000000000010  0000000000000000  WA       0     0     8
[20] .fini_array       FINI_ARRAY       00000000006b4030  000b4030
     0000000000000010  0000000000000000  WA       0     0     8
[21] .jcr              PROGBITS         00000000006b4040  000b4040
     0000000000000008  0000000000000000  WA       0     0     8
[22] .data.rel.ro      PROGBITS         00000000006b4060  000b4060
     00000000000000e4  0000000000000000  WA       0     0     32

Note that the section .tbssis allocated at 0x6b4020..0x6b4050 (0x30 bytes) and intersects it with the section .init_arrayin the 0x6b4020..0x6b4030 section (0x10 bytes), .fini_arrayat 0x6b4030..0x6b4040 (0x10 bytes) and with .jcrin the 0x6b4040..0x6b4848 section 8 bytes).

Please note that it does not overlap with the following sections, for example, .data.rel.robut, probably, because the alignment .data.rel.rois 32, and therefore it cannot be placed earlier than 0x6b4060.

, , . , glibc, .tbss - .bss (.. , ). .tbss , ? .init_array, .fini_array .jcr (, , , TLS), bss? - ?

, , 0x6b4020 ? .tbss .init_array ? ?

+4
2

.tbss , TLS, GLIBC.

, .tbss .tbdata script:

...
.gcc_except_table   : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
/* Thread Local Storage sections  */
.tdata          : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
.tbss           : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
.preinit_array     :
{
  PROVIDE_HIDDEN (__preinit_array_start = .);
  KEEP (*(.preinit_array))
  PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array     :
{
   PROVIDE_HIDDEN (__init_array_start = .);
   KEEP (*(SORT(.init_array.*)))
   KEEP (*(.init_array))
   PROVIDE_HIDDEN (__init_array_end = .);
}
...

- (.tbdata) ( ). .init_array ( .preinit_array, ), , .tbss, , , GNU LD:/p >

/* .tbss sections effectively have zero size.  */
if ((os->bfd_section->flags & SEC_HAS_CONTENTS) != 0
    || (os->bfd_section->flags & SEC_THREAD_LOCAL) == 0
    || link_info.relocatable)
  dotdelta = TO_ADDR (os->bfd_section->size);
else
  dotdelta = 0;    // <----------------
dot += dotdelta;

.tbss , SEC_THREAD_LOCAL, (NOBITS), else. , , .tbss, , ( "" ).

, .tbss ELF :

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x0000000000400000 0x0000000000400000
                 0x00000000000b1f24 0x00000000000b1f24  R E    200000
  LOAD           0x00000000000b2000 0x00000000006b2000 0x00000000006b2000
                 0x0000000000002288 0x00000000000174d8  RW     200000
  NOTE           0x0000000000000158 0x0000000000400158 0x0000000000400158
                 0x0000000000000044 0x0000000000000044  R      4
  TLS            0x00000000000b2000 0x00000000006b2000 0x00000000006b2000 <---+
                 0x0000000000000020 0x0000000000000060  R      8              |
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000     |
                 0x0000000000000000 0x0000000000000000  RW     8              |
                                                                              |
 Section to Segment mapping:                                                  |
  Segment Sections...                                                         |
   00     .note.ABI-tag ...                                                   |
   01     .tdata .ctors ...                                                   |
   02     .note.ABI-tag ...                                                   |
   03     .tdata .tbss    <---------------------------------------------------+
   04
+5

, :

1) SHT_NOBITS

2) tbss

SHT_NOBITS , .

NOBITS, bss, PROGBITS .

tbss - , . : .

. - .

1) :

. , init_array tbss. , :

if (isTLSSegment) tlsStartAddr += section->memSize();

, .

2)

tdata tbss , . , , , . , .

tbss ( tdata) .

, - " " . , "" - .

, .

+2

All Articles