Search code examples
celfobjdump

Empty space between .text and .fini data segments?


I compiled a simple C program (gcc -o file file.cpp) and obtained the following output on running objdump -h file,

 12 .text         00000172  0000000000400400  0000000000400400  00000400  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
 13 .fini         00000009  0000000000400574  0000000000400574  00000574  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE

I have a quick question here.

Why is there a gap of 2 bytes after the .text section? 0x400400 + 0x172 = 0x400572, but the .fini section starts from 0x400574? Has this got something to do with alignment? I noticed similar gaps between some other sections as well.


Solution

  • The last column of the output from objdump -h file is the alignment of the section. The alignment of .fini is 4 (2**2 is 2 to the power of 2), which is why it starts at 0x400574 instead of 0x400572.

    When linking against glibc for x86-64, the alignment of 4 for the .fini section is specified in crti.o:

        .section .fini,"ax",@progbits
        .p2align 2
        .globl _fini
        .type _fini, @function
    _fini: