diff options
author | Fangrui Song <i@maskray.me> | 2020-11-12 08:53:11 -0800 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2020-11-12 08:53:11 -0800 |
commit | 73d01a80cec397cb4e66ebb88a1204866b31ca59 (patch) | |
tree | 3fb8888418ccbdb6c03ad8678c9df0120532dfd7 /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 2a9aed0e8b538955f38f036bd34ea79adfce2ad7 (diff) | |
download | llvm-73d01a80cec397cb4e66ebb88a1204866b31ca59.zip llvm-73d01a80cec397cb4e66ebb88a1204866b31ca59.tar.gz llvm-73d01a80cec397cb4e66ebb88a1204866b31ca59.tar.bz2 |
[ELF] Sort by input order within an input section description
According to
https://sourceware.org/binutils/docs/ld/Input-Section-Basics.html#Input-Section-Basics
for `*(.a .b)`, the order should match the input order:
* for `ld 1.o 2.o`, sections from 1.o precede sections from 2.o
* within a file, `.a` and `.b` appear in the section header table order
This patch implements the behavior. The interaction with `SORT*` and --sort-section is:
Matched sections are ordered by radix sort with the keys being `(SORT*, --sort-section, input order)`,
where `SORT*` (if present) is most significant.
> Note, multiple `SORT*` within an input section description has undocumented and
> confusing behaviors in GNU ld:
> https://sourceware.org/pipermail/binutils/2020-November/114083.html
> Therefore multiple `SORT*` is not the focus for this patch but
> this patch still strives to have an explainable behavior.
As an example, we partition `SORT(a.*) b.* c.* SORT(d.*)`, into
`SORT(a.*) | b.* c.* | SORT(d.*)` and perform sorting within groups. Sections
matched by patterns between two `SORT*` are sorted by input order. If
--sort-alignment is given, they are sorted by --sort-alignment, breaking tie by
input order.
This patch also allows a section to be matched by multiple patterns, previously
duplicated sections could occupy more space in the output and had erroneous zero bytes.
The patch is in preparation for support for
`*(SORT_BY_INIT_PRIORITY(.init_array.* .ctors.*)) *(.init_array .ctors)`,
which will allow LLD to mix .ctors*/.init_array* like GNU ld (gold's --ctors-in-init-array)
PR44698 and PR48096
Reviewed By: grimar, psmith
Differential Revision: https://reviews.llvm.org/D91127
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
0 files changed, 0 insertions, 0 deletions