This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ELF program header in baremetal


Hello Binutils and GDB folks.

There is a question regarding p_align in ELF Program Header.
Whilst this parameter is understandable for loading application in OS,
there is no clear picture for baremetal - must debugger to follow ELF
specification or not.
Seems like we’ve been lucky in most cases until alignment being increased
to 64kB [1] since it was small enough. Now it is not.

Below is a real case on the MCU with Arm core onboard and small memory amount.

Linker script is:
  m_interrupts  (RX) : ORIGIN = 0x1FFF8000, LENGTH = 0x00000400
  m_text        (RX) : ORIGIN = 0x1FFF8400, LENGTH = 0x00007C00

Program Header:
    LOAD off    0x00000000 vaddr 0x1fff0000 paddr 0x1fff0000 align 2**16
         filesz 0x00008400 memsz 0x00008400 flags r--
    LOAD off    0x00008400 vaddr 0x1fff8400 paddr 0x1fff8400 align 2**16
         filesz 0x00000570 memsz 0x00000570 flags rwx
    LOAD off    0x00010000 vaddr 0x20000000 paddr 0x20000000 align 2**16
         filesz 0x00000424 memsz 0x00007000 flags rw-
private flags = 5000200: [Version5 EABI] [soft-float ABI]

With the given Program Header non-GDB debuggers loads non-existent memory
and throws an error. Another ones loads this ELF with warning but with
Verification error after that. I haven’t analyzed how GDB address this,
but somehow it is not affected. Maybe GDB just ignore PH and loads sections.
Anyway such a different behavior is odd.

Another case is multicore wen we have multiple separate ELF files. Loading
one-by-one can overwrite previously loaded text/data.
Similar case with bootloader overwriting [2].


My proposal is to set ELF_MAXPAGESIZE to smallest value for baremetal
configuration.

gABI states:
  Values 0 and 1 mean no alignment is required. Otherwise, p_align should
  be a positive, integral power of 2, and p_vaddr should equal p_offset,
  modulo p_align.

Forcing -max-page-size to 0/1 doesn't work unfortunately. It still generates
non-existent segments.


Best regards,
Alex

---------------
[1] https://patches.linaro.org/patch/32565/
[2] https://www.tablix.org/~avian/blog/archives/2012/11/gnu_linker_and_elf_program_header/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]