[PATCH] D50688: [LLD] Warn if non-alloc sections occur before alloc sections in linker scripts

ben via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 07:41:56 PDT 2018


bd1976llvm added a comment.

In https://reviews.llvm.org/D50688#1207394, @kschwarz wrote:

> Thanks for the link! However, I'm not sure if this is really related. The issue there was that a non-alloc section should be placed into a program header explicitly via PHDRS commands, which might be a valid use case.


It is certainly a use case that is important to our customers. As I remember that change resulted in the ability to mix non-alloc and alloc output sections in a PHDR using the PHDRS command. If we are going to fix this bug by moving to compatibility with gnu-ld for non-shf-alloc sections then we shouldn't allow the assignment of non-shf-alloc sections to segments that represent "segments of memory which the system loader will load from the file" e.g. PT_LOAD segments even via the PHDRS command. In other words we should do something like your sorting fix in both the automatic PHDR case and the PHDRS command case.

> In "automatic" program header creation, a non-alloc section will never appear in a program header, but unfortunately the header creation, orphan placement and address assignment all rely on the strict separation of alloc and non-alloc sections and will produce a broken ELF for mixed sections.
> 
> Since non-alloc sections can only be put under a program header via PHDRS commands, I think issuing a warning if no PHDRS commands are given and alloc/non-alloc sections are mixed and not touching the rest of the code should be okay.
>  What do you think?

I was (very hopefully) thinking that header creation, orphan placement and address assignment could be adjusted to cope with a mixture of alloc and non-alloc without too much turbulence... but I haven't looked into it so it may be difficult. If we don't change the current code and LLD is going to create a broken elf in these cases then maybe we should actually error rather than warn?


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D50688





More information about the llvm-commits mailing list