Loy
Loy

Reputation: 3

How elf file loaded correct memory address and executed successfully?

As I know basic difference between bin and elf that

Bin file contain only bit or bytes of data and you need to give address of memory when you load it in memory,

while in case of elf it have symbol look-ups and relocatable table, so no need to give address when you program it.

Now see attached image. I am using LPCexpresso to program elf file in device. if you not give base address then it will take 0x00000000 by default. Now i first programme bootloader.elf and then main.elf. in both case I am not giving base address.

Now my question is if I am not giving address then how elf file decide to program correct location and after programming one image if I programme another image then isn't it overwrite first one? (because in both case we haven't give address and by default it 0x00000000)

Upvotes: 0

Views: 2018

Answers (1)

juansolsona
juansolsona

Reputation: 187

Normally this information is inside the ELF file created by the linker script.

As part of the GNU binutils, there is a tool called "readelf", that shows information about the ELF sections and headers. Unfortunatelly these tools uses to have a prefix depending on its configuration tool, most likely it will be called "arm-none-readelf". If you do not have it, checkout http://www.yagarto.org/

So, if you type "arm-none-readelf main.elf -a" it should show something like:

ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           YOUR ARCHITECTURE
  Version:                           0x1
  Entry point address:               YOUR ENTRY ADDRESS
  Start of program headers:          52 (bytes into file)
  Start of section headers:          YOUR SIZE
  Flags:                             0x300
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         36
  Size of section headers:           40 (bytes)
  Number of section headers:         55
  Section header string table index: 52

(Please note that this is just example data).

Normally in all the compiler there are options for the linker that allows to specify the load address of your ELF, (uses to be called .ld file).

Hope it helps.

Upvotes: 3

Related Questions