[PATCH] D95198: [ELF] Fix program header alloc when first PT_LOAD is not at lowest VMA

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 25 02:50:18 PST 2021


peter.smith added a comment.

I'm not clear on what the requirements are here. I would be very interested to see a reference to placing headers in the first loadable program segment. That sounds like it could be a convention of some linker/platform, but I can't remember seeing that in any specification.

The best reference I've found is in Levine's Linkers and Loaders book (from 2000) where it talks about

  ELF files extend the "header in the address space" trick used in QMAGIC a.out files to make the executable file as compact as possible at the cost of some unused space in the address space."

Looking up QMAGIC it says:

   Compact pageable files consider the a.out header to be part of the text segment, because there's no particular reason that the code in the text segment has to start at location zero.
  ...
  The code actually starts immediately after the header and the whole page is mapped into the second page of the process, leaving the first page unmapped so that pointer references to location zero will fail. This has the harmless side effect of mapping the header into the process as well.

My understanding of embedded systems (mostly deeply embedded with at most an RTOS) is that the loadable segments are extracted from the ELF file and burned into ROM/Flash. The program never refers to the ELF header and program headers. It sounds like you have a requirement to place the ELF header and program headers in an arbitrary segment?

If so, rather than alter the QMAGIC convention, I think it would be better to use the PHDRS linker script command https://sourceware.org/binutils/docs/ld/PHDRS.html I believe that permits the headers to be allocated to a user controlled segment. If LLD's PHDRS support isn't good enough (compared to BFD) I'd prefer we improved it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95198/new/

https://reviews.llvm.org/D95198



More information about the llvm-commits mailing list