readelf -S libc.so
There are 43 section headers, starting at offset 0x24ded0:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .hash HASH 100000b4 0000b4 002070 04 A 2 0 4
[ 2] .dynsym DYNSYM 10002124 002124 004130 10 A 3 2 4
[ 3] .dynstr STRTAB 10006254 006254 002a36 00 A 0 0 1
[ 4] .rela.dyn RELA 10008c8c 008c8c 000c54 0c A 2 0 4
[ 5] .rela.text RELA 100098e0 0098e0 000018 0c A 2 11 4
[ 6] .rela.data.rel.ro RELA 100098f8 0098f8 000768 0c A 2 21 4
[ 7] .rela.data RELA 1000a060 00a060 000384 0c A 2 28 4
[ 8] .rela.got2 RELA 1000a3e4 00a3e4 004524 0c A 2 25 4
[ 9] .rela.sdata RELA 1000e908 00e908 000030 0c A 2 31 4
[10] .rela.plt RELA 1000e938 00e938 001440 0c A 2 13 4
[11] .text PROGBITS 1000fd80 00fd80 0665d4 00 AX 0 0 32
[12] .rela.text RELA 00000000 24e588 00de24 0c 41 11 4
[13] .plt NOBITS 10077000 076354 001488 00 AX 0 0 4
[14] .rodata PROGBITS 10079000 079000 02e6f4 00 A 0 0 8
[15] .rela.rodata RELA 00000000 25c3ac 0093e4 0c 41 14 4
[16] .eh_frame PROGBITS 100a76f4 0a76f4 000000 00 A 0 0 4
[17] .ctors PROGBITS 100b76f4 0a76f4 000040 00 WA 0 0 4
[18] .rela.ctors RELA 00000000 265790 00009c 0c 41 17 4
[19] .dtors PROGBITS 100b7734 0a7734 000044 00 WA 0 0 4
[20] .rela.dtors RELA 00000000 26582c 0000a8 0c 41 19 4
[21] .data.rel.ro PROGBITS 100b7778 0a7778 000304 00 WA 0 0 4
[22] .rela.data.rel.ro RELA 00000000 2658d4 000768 0c 41 21 4
[23] .fixup PROGBITS 100b7a7c 0a7a7c 0003b0 00 WA 0 0 4
[24] .rela.fixup RELA 00000000 26603c 000b10 0c 41 23 4
[25] .got2 PROGBITS 100b7e2c 0a7e2c 00170c 00 WA 0 0 4
[26] .rela.got2 RELA 00000000 266b4c 004524 0c 41 25 4
[27] .dynamic DYNAMIC 100b9538 0a9538 0000b8 08 WA 3 0 4
[28] .data PROGBITS 100b95f0 0a95f0 0003a8 00 WA 0 0 4
[29] .rela.data RELA 00000000 26b070 000384 0c 41 28 4
[30] .got PROGBITS 100b9998 0a9998 000010 04 WA 0 0 4
[31] .sdata PROGBITS 100b99a8 0a99a8 000046 00 WA 0 0 4
[32] .rela.sdata RELA 00000000 26b3f4 000030 0c 41 31 4
[33] .sbss NOBITS 100b99f0 0a99ee 000142 00 WA 0 0 4
[34] .bss NOBITS 100b9b40 0a99ee 002470 00 WA 0 0 16
[35] .stab PROGBITS 00000000 0a99f0 0db738 0c 37 0 4
[36] .rela.stab RELA 00000000 26b424 008b74 0c 41 35 4
[37] .stabstr STRTAB 00000000 185128 0c8c6b 00 0 0 1
[38] .comment PROGBITS 00000000 24dd93 000023 01 MS 0 0 1
[39] .gnu.attributes GNU_ATTRIBUTES 00000000 24ddb6 000012 00 0 0 1
[40] .shstrtab STRTAB 00000000 24ddc8 000105 00 0 0 1
[41] .symtab SYMTAB 00000000 273f98 009c90 10 42 1464 4
[42] .strtab STRTAB 00000000 27dc28 006421 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
v (VLE), p (processor specific)
readelf -S printf
There are 38 section headers, starting at offset 0x1b258:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 010000f4 0000f4 000011 00 A 0 0 1
[ 2] .hash HASH 01000108 000108 0000b0 04 A 3 0 4
[ 3] .dynsym DYNSYM 010001b8 0001b8 000190 10 A 4 1 4
[ 4] .dynstr STRTAB 01000348 000348 000143 00 A 0 0 1
[ 5] .rela.bss RELA 0100048c 00048c 000018 0c A 3 17 4
[ 6] .rela.plt RELA 010004a4 0004a4 000048 0c A 3 9 4
[ 7] .text PROGBITS 010004ec 0004ec 001b40 00 AX 0 0 4
[ 8] .rela.text RELA 00000000 01b848 000b28 0c 36 7 4
[ 9] .plt NOBITS 01003000 00202c 000090 00 AX 0 0 4
[10] .rodata PROGBITS 01004000 004000 000092 00 A 0 0 4
[11] .eh_frame PROGBITS 01004094 004094 000000 00 A 0 0 4
[12] .ctors PROGBITS 01014094 004094 000004 00 WA 0 0 4
[13] .dtors PROGBITS 01014098 004098 000004 00 WA 0 0 4
[14] .dynamic DYNAMIC 0101409c 00409c 0000b0 08 WA 4 0 4
[15] .data PROGBITS 0101414c 00414c 000000 00 WA 0 0 1
[16] .got PROGBITS 0101414c 00414c 000010 04 WA 0 0 4
[17] .bss NOBITS 0101415c 00415c 000034 00 WA 0 0 4
[18] .stab PROGBITS 00000000 00415c 0005f4 0c 20 0 4
[19] .rela.stab RELA 00000000 01c370 000090 0c 36 18 4
[20] .stabstr STRTAB 00000000 004750 0047c3 00 0 0 1
[21] .comment PROGBITS 00000000 008f13 000023 01 MS 0 0 1
[22] .debug_aranges PROGBITS 00000000 008f36 000020 00 0 0 1
[23] .rela.debug_arang RELA 00000000 01c400 000018 0c 36 22 4
[24] .debug_info PROGBITS 00000000 008f56 00a913 00 0 0 1
[25] .rela.debug_info RELA 00000000 01c418 006b70 0c 36 24 4
[26] .debug_abbrev PROGBITS 00000000 013869 0005cb 00 0 0 1
[27] .debug_line PROGBITS 00000000 013e34 0014cc 00 0 0 1
[28] .rela.debug_line RELA 00000000 022f88 00000c 0c 36 27 4
[29] .debug_frame PROGBITS 00000000 015300 000634 00 0 0 4
[30] .rela.debug_frame RELA 00000000 022f94 000348 0c 36 29 4
[31] .debug_str PROGBITS 00000000 015934 004cbe 01 MS 0 0 1
[32] .debug_loclists PROGBITS 00000000 01a5f2 000a4b 00 0 0 1
[33] .rela.debug_locli RELA 00000000 0232dc 000024 0c 36 32 4
[34] .debug_rnglists PROGBITS 00000000 01b03d 0000eb 00 0 0 1
[35] .shstrtab STRTAB 00000000 01b128 00012f 00 0 0 1
[36] .symtab SYMTAB 00000000 023300 000600 10 37 51 4
[37] .strtab STRTAB 00000000 023900 00044d 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
v (VLE), p (processor specific)
readelf -S libc.so
There are 43 section headers, starting at offset 0x2981d8:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .hash HASH 100000b4 0000b4 00212c 04 A 2 0 4
[ 2] .dynsym DYNSYM 100021e0 0021e0 004420 10 A 3 2 4
[ 3] .dynstr STRTAB 10006600 006600 002bfd 00 A 0 0 1
[ 4] .rela.dyn RELA 10009200 009200 000c54 0c A 2 0 4
[ 5] .rela.text RELA 10009e54 009e54 000018 0c A 2 11 4
[ 6] .rela.data.rel.ro RELA 10009e6c 009e6c 000768 0c A 2 21 4
[ 7] .rela.data RELA 1000a5d4 00a5d4 000384 0c A 2 28 4
[ 8] .rela.got2 RELA 1000a958 00a958 00b220 0c A 2 25 4
[ 9] .rela.sdata RELA 10015b78 015b78 000030 0c A 2 31 4
[10] .rela.plt RELA 10015ba8 015ba8 001578 0c A 2 13 4
[11] .text PROGBITS 10017120 017120 07b36c 00 AX 0 0 32
[12] .rela.text RELA 00000000 298890 015990 0c 41 11 4
[13] .plt NOBITS 10093000 09248c 0015c0 00 AX 0 0 4
[14] .rodata PROGBITS 10095000 095000 038c9f 00 A 0 0 8
[15] .rela.rodata RELA 00000000 2ae220 0093e4 0c 41 14 4
[16] .eh_frame PROGBITS 100cdca0 0cdca0 000000 00 A 0 0 4
[17] .ctors PROGBITS 100de000 0ce000 000040 00 WA 0 0 4
[18] .rela.ctors RELA 00000000 2b7604 00009c 0c 41 17 4
[19] .dtors PROGBITS 100de040 0ce040 000044 00 WA 0 0 4
[20] .rela.dtors RELA 00000000 2b76a0 0000a8 0c 41 19 4
[21] .data.rel.ro PROGBITS 100de084 0ce084 000304 00 WA 0 0 4
[22] .rela.data.rel.ro RELA 00000000 2b7748 000768 0c 41 21 4
[23] .fixup PROGBITS 100de388 0ce388 0003b0 00 WA 0 0 4
[24] .rela.fixup RELA 00000000 2b7eb0 000b10 0c 41 23 4
[25] .got2 PROGBITS 100de738 0ce738 003b60 00 WA 0 0 4
[26] .rela.got2 RELA 00000000 2b89c0 00b220 0c 41 25 4
[27] .dynamic DYNAMIC 100e2298 0d2298 0000b8 08 WA 3 0 4
[28] .data PROGBITS 100e2350 0d2350 0003ac 00 WA 0 0 4
[29] .rela.data RELA 00000000 2c3be0 000384 0c 41 28 4
[30] .got PROGBITS 100e26fc 0d26fc 000010 04 WA 0 0 4
[31] .sdata PROGBITS 100e270c 0d270c 00004a 00 WA 0 0 4
[32] .rela.sdata RELA 00000000 2c3f64 000030 0c 41 31 4
[33] .sbss NOBITS 100e2758 0d2756 000142 00 WA 0 0 4
[34] .bss NOBITS 100e28a0 0d2756 0024b0 00 WA 0 0 16
[35] .stab PROGBITS 00000000 0d2758 0f1d64 0c 37 0 4
[36] .rela.stab RELA 00000000 2c3f94 00beb0 0c 41 35 4
[37] .stabstr STRTAB 00000000 1c44bc 0d3be2 00 0 0 1
[38] .comment PROGBITS 00000000 29809e 000023 01 MS 0 0 1
[39] .gnu.attributes GNU_ATTRIBUTES 00000000 2980c1 000012 00 0 0 1
[40] .shstrtab STRTAB 00000000 2980d3 000105 00 0 0 1
[41] .symtab SYMTAB 00000000 2cfe44 00c110 10 42 2001 4
[42] .strtab STRTAB 00000000 2dbf54 0068fc 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
v (VLE), p (processor specific)
readelf -S printf
There are 38 section headers, starting at offset 0x1b258:
Section Headers:
[Nr] Name Type Addr Off Size ES Flg Lk Inf Al
[ 0] NULL 00000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 010000f4 0000f4 000011 00 A 0 0 1
[ 2] .hash HASH 01000108 000108 0000b0 04 A 3 0 4
[ 3] .dynsym DYNSYM 010001b8 0001b8 000190 10 A 4 1 4
[ 4] .dynstr STRTAB 01000348 000348 000143 00 A 0 0 1
[ 5] .rela.bss RELA 0100048c 00048c 000018 0c A 3 17 4
[ 6] .rela.plt RELA 010004a4 0004a4 000048 0c A 3 9 4
[ 7] .text PROGBITS 010004ec 0004ec 001b40 00 AX 0 0 4
[ 8] .rela.text RELA 00000000 01b848 000b28 0c 36 7 4
[ 9] .plt NOBITS 01003000 00202c 000090 00 AX 0 0 4
[10] .rodata PROGBITS 01004000 004000 000092 00 A 0 0 4
[11] .eh_frame PROGBITS 01004094 004094 000000 00 A 0 0 4
[12] .ctors PROGBITS 01014094 004094 000004 00 WA 0 0 4
[13] .dtors PROGBITS 01014098 004098 000004 00 WA 0 0 4
[14] .dynamic DYNAMIC 0101409c 00409c 0000b0 08 WA 4 0 4
[15] .data PROGBITS 0101414c 00414c 000000 00 WA 0 0 1
[16] .got PROGBITS 0101414c 00414c 000010 04 WA 0 0 4
[17] .bss NOBITS 0101415c 00415c 000034 00 WA 0 0 4
[18] .stab PROGBITS 00000000 00415c 0005f4 0c 20 0 4
[19] .rela.stab RELA 00000000 01c370 000090 0c 36 18 4
[20] .stabstr STRTAB 00000000 004750 0047c3 00 0 0 1
[21] .comment PROGBITS 00000000 008f13 000023 01 MS 0 0 1
[22] .debug_aranges PROGBITS 00000000 008f36 000020 00 0 0 1
[23] .rela.debug_arang RELA 00000000 01c400 000018 0c 36 22 4
[24] .debug_info PROGBITS 00000000 008f56 00a913 00 0 0 1
[25] .rela.debug_info RELA 00000000 01c418 006b70 0c 36 24 4
[26] .debug_abbrev PROGBITS 00000000 013869 0005cb 00 0 0 1
[27] .debug_line PROGBITS 00000000 013e34 0014cc 00 0 0 1
[28] .rela.debug_line RELA 00000000 022f88 00000c 0c 36 27 4
[29] .debug_frame PROGBITS 00000000 015300 000634 00 0 0 4
[30] .rela.debug_frame RELA 00000000 022f94 000348 0c 36 29 4
[31] .debug_str PROGBITS 00000000 015934 004cbe 01 MS 0 0 1
[32] .debug_loclists PROGBITS 00000000 01a5f2 000a4b 00 0 0 1
[33] .rela.debug_locli RELA 00000000 0232dc 000024 0c 36 32 4
[34] .debug_rnglists PROGBITS 00000000 01b03d 0000eb 00 0 0 1
[35] .shstrtab STRTAB 00000000 01b128 00012f 00 0 0 1
[36] .symtab SYMTAB 00000000 023300 000600 10 37 51 4
[37] .strtab STRTAB 00000000 023900 00044d 00 0 0 1
Key to Flags:
W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
L (link order), O (extra OS processing required), G (group), T (TLS),
C (compressed), x (unknown), o (OS specific), E (exclude),
v (VLE), p (processor specific)
This is the objdump -S of libc.so and printf without and with DEBUG. Sections are the same. printf exe is the same in address, size and offset. I don't understand what can be different between one an another. The only difference that is present in two builds is the DEBUG flag. I've also added -gstabs to the non-debug version just to be sure that it wasn't the problem..
Constructors are created in this way now:
#define CONSTRUCTOR(name, pri) \
static void __attribute__((used, constructor(pri))) name##_ctor(VOID); \
static void (*__##name##_ctor)(void) = name##_ctor; \
static void name##_ctor(void)
#define DESTRUCTOR(name, pri) \
static void __attribute__((used, destructor(pri))) name##_dtor(VOID); \
static void (*__##name##_dtor)(void) = name##_dtor; \
static void name##_dtor(void)
But I can revert to the original version that was using .ctors/.dtors sections