[lld] [ELF] Warn if specified section address is smaller than image base (PR #140187)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Fri May 16 07:27:13 PDT 2025


https://github.com/smithp35 approved this pull request.

I wish GNU ld had a better specification of what these options are meant to do. 

I've set approved as a warning is definitely an improvement. I've got a few suggestions on some alternatives but I don't have a particularly strong case for any of them as this is likely a corner case.

It looks like we're defining `--image-base` to be the address of the first loadable segment (and not specifically the first loadable text segment as in ld.bfd, or the first loadable ro-data segment using lld order). With that definition any section placed lower than `--image-base` is now generating a warning, and we're generating a loadable program header (potentially out of order for it anyway).

There's a few alternatives we could consider:
* It is an error if a `SHF_ALLOC` is out of bounds of the lowest loadable segment.
* We take the instruction literally and the out of bounds section does not get a program header, this includes potentially making the ELF header and segement header non allocateable.
* We could lower (with a warning) the image base to the lowest allocateable section.
A possible addition when this occurs is to set the headers as not allocatable so we don't create the program header for the ELF header and Program Header.

I've got a mild preference to making this an error. 

As an aside the ELF spec can be satisfied by sorting the loadable program header entries by p_vaddr. The segments in the file don't have to be in order if we're going by the letter of the specification. That could be worth doing anyway to help out people with strict loaders but without a linker script (or suitable command-line option) that has ascending segment p_vaddr order.  

https://github.com/llvm/llvm-project/pull/140187


More information about the llvm-commits mailing list