Previously sections in a linker script had to be sorted by segment and address
otherwise lld would fail with perplexing errors such as "section .foo file
range overlaps with .bar" or "unable to place section .foo at file offset
[...]; check your linker script for overflows".
This patch improves compatibility with ld.bfd by supporting two new cases:
- Sections with decreasing addresses in the same program header, e.g:
.text 0x2000 : {*(.text*)} :ph1
.bar 0x1000 : {*(.bar*)} :ph1
- Interleaving sections across program headers, e.g:
.text 0x2000 : {*(.text*)} :ph1
.foo 0x0 : {*(.foo*)} :ph2
.bar 0x1000 : {*(.bar*)} :ph1
While it is possible in both cases to modify the linker script we would need to
correctly detect these cases and emit more helpful diagnostics for them.
However, as lld claims it is a "drop-in replacement for the GNU linkers that
accepts the same command line arguments and linker scripts as GNU" it makes
sense to improve compatibility instead.
Supporting these cases requires sorting sections within a segment by address
then placing the output in load segment order.
A new out-of-order-sections test is also introduced.
stable_sort