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
The more common name in LLD for this would be seen