Search code examples
clinuxelfsegment

ELF second load segment address of .data + .bss


ELF output of readelf

In this case, is right that address of:

.data start at 0x08048054 up to 0x08048054+0x0000e

.bss start at 0x08048054+0x0000e up to 0x0804805+0x00016

or am I missing something? please clarify it for me.

EDIT

I used this command to get the information as in the image:

readelf -l filename

Solution

  • Ok, so where do I begin... Yes both .data and .bss are in that region in memory. The problem is that there is no way to figure out what order they are in.

    We can assume that the default order is followed and make an educated guess but I don't like that.

    Through the lengthy comment thread under the question you mentioned something interesting, that wasn't evident in your question.

    the executable isn't dynamically linked as file command says: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped in this case, there's no a linker script, isn't? – The Mask

    In this case the library contains the symbol table with all of the symbol offsets. This table includes section information. It will be processed by the linker when you compile your application. At that point it is your linker script that controls the order in which the .data and .bss sections are out put in.

    If it is the default linker script, look it up. If it is custom, you should have access to it and can read it. If unsure elaborate here and we'll try and help :)

    I myself have asked a question that is unrelated but offers example code of a linker script and some C code. In that linker script the .bss segment came after the .data segment.