[PATCH] D84001: [ELF] Allow mixed SHF_LINK_ORDER & non-SHF_LINK_ORDER sections and sort within InputSectionDescription

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 20:54:46 PDT 2020


MaskRay created this revision.
MaskRay added reviewers: grimar, jhenderson, pcc, phosek, psmith.
Herald added subscribers: llvm-commits, fedor.sergeev, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

LLD currently does not allow non-contiguous SHF_LINK_ORDER components in an
output section. This makes it infeasible to add SHF_LINK_ORDER to an existing
metadata section if backward compatibility with older object files are
concerned.

We did not allow mixed components (like GNU ld) and D77007 <https://reviews.llvm.org/D77007> relaxed to allow
non-contiguous SHF_LINK_ORDER components. This patch allows arbitrary mix, with
sorting performed within an InputSectionDescription. For example,
`.rodata : {*(.rodata.foo) *(.rodata.bar)}`, has two InputSectionDescription's.
If there is at least one SHF_LINK_ORDER and at least one non-SHF_LINK_ORDER in
.rodata.foo, they are ordered within `*(.rodata.foo)`: we arbitrarily place
SHF_LINK_ORDER components before non-SHF_LINK_ORDER components (like Solaris ld).

`*(.rodata.bar)` is ordered similarly, but the two InputSectionDescription's
don't interact.  It can be argued that this is more reasonable than the previous
behavior where written order was not respected.

It would be nice if the two different semantics (ordering requirement & garbage
collection) were not overloaded on one section flag, however, it is probably
difficult to obtain a generic flag at this point
(https://groups.google.com/forum/#!topic/generic-abi/hgx_m1aXqUo
"SHF_LINK_ORDER's original semantics make upgrade difficult").

(Actually, without the GC semantics, SHF_LINK_ORDER would still have the
sh_link!=0 & sh_link=0 issue. It is just that people find the GC semantics more
useful and tend to use the feature more often.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84001

Files:
  lld/ELF/Writer.cpp
  lld/test/ELF/linkerscript/linkorder.s
  lld/test/ELF/linkorder-mixed.test

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84001.278656.patch
Type: text/x-patch
Size: 8297 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200717/e1cbd1e8/attachment.bin>


More information about the llvm-commits mailing list