public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* ELF program header in baremetal
@ 2019-10-21 10:18 Alexander Fedotov
  2019-11-11 14:58 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Fedotov @ 2019-10-21 10:18 UTC (permalink / raw)
  To: binutils, gdb

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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: ELF program header in baremetal
  2019-10-21 10:18 ELF program header in baremetal Alexander Fedotov
@ 2019-11-11 14:58 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2019-11-11 14:58 UTC (permalink / raw)
  To: Alexander Fedotov, binutils, gdb

Hi Alexander,

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

Isn't this what the arm-nacl configuration target does ?


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

Have you tried using the -n or the -N linker command line options ?

Cheers
  Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-11 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-21 10:18 ELF program header in baremetal Alexander Fedotov
2019-11-11 14:58 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).