Page MenuHomePhabricator

Page alignment / Debug symbols
Open, Needs TriagePublic

Description

Hi,
I noticed that the ATF for some SoCs is not linked to an aligned address. E.g. ZYNQ-US.
There is a linker flag for on GNU-LD "--nmagic" which disables page alignment.

The problem does not affect the section table but the program headers.
Without --nmagic the Program Headers (PHDRS) look like this:
$ aarch64-linux-gnu-readelf -l bl31.elf

Elf file type is EXEC (Executable file)
Entry point 0xfffea000
There are 2 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000000000 0x00000000fffe0000 0x00000000fffe0000
                 0x0000000000016a4d 0x000000000001f000  RWE    0x10000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x10

 Section to Segment mapping:
  Segment Sections...
   00     .text .rodata .data stacks .bss xlat_table coherent_ram 
   01

while with --nmagic the program headers look like this:
$ aarch64-linux-gnu-readelf -l bl31.elf

Elf file type is EXEC (Executable file)
Entry point 0xfffea000
There are 2 program headers, starting at offset 64

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000001000 0x00000000fffea000 0x00000000fffea000
                 0x000000000000ca4d 0x0000000000015000  RWE    0x1000
  GNU_STACK      0x0000000000000000 0x0000000000000000 0x0000000000000000
                 0x0000000000000000 0x0000000000000000  RW     0x10

 Section to Segment mapping:
  Segment Sections...
   00     .text .rodata .data stacks .bss xlat_table coherent_ram 
   01

. The BIG difference is that that without --nmagic the PHDRS basically say: to load the file

copy (<start of elf file>+0x0)++0x16a4d to 0xFFFE0000 on the platform

. This includes the ELF header by the way + overwrites for ZYNQ-US the FSBL-Handoff table when using Xilinx FSBL.
When I link with page alignment disabled (with --nmagic) the PHDRS basically say: to load the file

copy (<start of elf file>+0x1000)++0xca4d to 0xFFFEA000 on the platform

. This time the FSBL-Handoff table gets not overwritten on ZYNQ-US.

Some debug solutions on the market perfer to use the PHDRS (e.g. to load code for a foreign architecture) over the section table. Thus it destroys the in my situation the FSBL handoff.
Is there a reason why ATF does not link with --nmagic?
Is there another reason why the debug symbols are not generated when compiling in release?

Event Timeline

userid0x0 updated the task description. (Show Details)Mar 27 2020, 4:39 PM