lolu
lolu

Reputation: 370

ELF and virtual address in C

I am studying for a test, and I have the following question: In the ELF header it is said that the file's entry point is at 0x8049058

the code is:

section .data
    x: dd 3

    _start: mov ecx, [x]
    ...
    ...
    ... ;more code

Q: what will be the virtual address of x at run time?

the correct answer is 0x0849054

can someone please shed light on this? If x would be as followd, will it still be in the same address?

section .bss
x: resb 4

section .data

_start: mov ecx, [x]
...
...
... ;more code

where exacly does an entry point "Take" me? And what sections are close to it?

Upvotes: 0

Views: 244

Answers (1)

Jester
Jester

Reputation: 58762

If you are pedantic, there is not enough information to tell. If we assume that _start is the entry point (which is typical, but not mandatory) then given that the size of x is 4 bytes, and there is nothing else between x and _start, then the address of x is obviously _start - 4. Note that it is not normal to have the entry point in the .data section.

For the second code, you have no way to tell where .bss is in relation to .data or _start, unless you examine the headers in the binary.

Upvotes: 3

Related Questions