how to define a Program Headers start address

Asked by Hake Huang

using the readelf tool I always get below result
$ readelf.exe -l hello_world.elf

Elf file type is EXEC (Executable file)
Entry point 0xa4d1
There are 3 program headers, starting at offset 52

Program Headers:
  Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
  LOAD 0x000000 0x00000000 0x00000000 0x0a400 0x0a400 R 0x10000
  LOAD 0x00a400 0x0000a400 0x0000a400 0x02544 0x02544 RWE 0x10000
  LOAD 0x010000 0x20000000 0x0000c944 0x00068 0x008b0 RW 0x10000

 Section to Segment mapping:
  Segment Sections...
   00 .interrupts
   01 .text .ARM .init_array .fini_array
   02 .data .bss .heap .stack

Means the first Program HEADers are always start from 0x00000000, how can I modify it? as in my application, the 0x00000000 - 0x00009ffff is reserved.

Question information

English Edit question
GNU Arm Embedded Toolchain Edit question
No assignee Edit question
Solved by:
Thomas Preud'homme
Last query:
Last reply:
Revision history for this message
Best Thomas Preud'homme (thomas-preudhomme) said :

Hi Hake,

If you set the .interrupt section to be at an address higher than 0x0009fff and pass --nmagic to the linker then the first segment will only include the .interrupt and it will start where .interrupt start. --nmagic is necessary for the first segment to not include the file and ELF header.

Best regards.

Revision history for this message
Hake Huang (hakehuang) said :

Hi Thomas,

it works thanks a lot.


Revision history for this message
Hake Huang (hakehuang) said :

Thanks Thomas Preud'homme, that solved my question.

Revision history for this message
Tony (tonyk) said :

This is a linker bug -- see my question here:

It happens when the in-page offset of the first program segment (which is 0xa400 here) is >= the size of the ELF file header. So the linker correctly puts the segment in the first page of the ELF file, but erroneously extends the segment downwards to the beginning of the file.