0

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?

Fifoernik
  • 9,779
  • 1
  • 21
  • 27
lolu
  • 370
  • 4
  • 20

1 Answers1

3

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.

Jester
  • 56,577
  • 4
  • 81
  • 125
  • is it ok to asume that all the variables in the .data section will be exacly "above" the entry? since it is in the same section? – lolu Jul 20 '15 at 16:05
  • 1
    Yes, they are not reordered within the section. – Jester Jul 20 '15 at 16:05