how to define a Program Headers start address

Asked by Hake Huang on 2017-03-17

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

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Thomas Preud'homme
Solved:
2017-03-20
Last query:
2017-03-20
Last reply:
2017-03-17

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.

Hake Huang (hakehuang) said : #2

Hi Thomas,

it works thanks a lot.

Regards.

Hake Huang (hakehuang) said : #3

Thanks Thomas Preud'homme, that solved my question.

Tony (tonyk) said : #4

This is a linker bug -- see my question here: https://answers.launchpad.net/gcc-arm-embedded/+question/677514

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.