[PATCH] D50688: [LLD] Sort alloc/non-alloc output sections in linkerscripts

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 14 03:04:36 PDT 2018


peter.smith added a comment.

Interesting. This seems to be one of the situations where linker scripts aren't specified well enough to give a definitive answer of what a linker should do.

The approach of sorting non-alloc after alloc matches the linker's implicit rules but is it really respecting the SECTIONS command. ld.bfd appears to keep the order of the section headers, even assigning the non-alloc sections an address as if they were in the same place as given in the linker script. However it gives them 0 size when calculating the address of the next alloc section, and sorts the non alloc sections in the file so that the non-alloc sections don't appear in PT_LOAD program headers. This seems to match the intention of the script more closely but whether this makes any significant difference for a real program to depend on I don't know.

In an ideal world people wouldn't write linker scripts that mix non-alloc with alloc but I think it is probably unavoidable and we should either try and fix by sorting the sections or at least giving a warning/error message if we need scripts to conform to it. I personally think sorting the sections is probably as much code as diagnosing an error and is close enough to gold and bfd behaviour to be good enough.

On the Arm specific side. The SHT_ARM_ATTRIBUTES section was intended only for Objects. The presence or absence of the section in an executable or shared object is at the discretion of the linker, so a portable program should never rely on its presence in the ELF file. Initially LLD just discarded it but I found out that eglibc that was used on Ubuntu Trusty (14.04) scanned shared objects section header table for it in order to determine the float-abi; it really shouldn't have been doing that but if we were to make LLD work on Trusty we'd need to put it in the ELF file.



================
Comment at: test/ELF/linkerscript/sections.s:28
 
 # Sections are put in order specified in linker script, other than alloc
 # sections going first.
----------------
The comment here implies that LLD used to sort SHF_ALLOC before non SHF_ALLOC. A dig in the logs shows that in r281778 this was the intention but it was later modified, possibly by r302903 but it could have been earlier.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D50688





More information about the llvm-commits mailing list