See https://lists.llvm.org/pipermail/llvm-dev/2020-November/146522.html
"[LLD] Support DWARF64, debug_info "sorting""
If a .debug_* output section S can be larger than 32-bit and its section
offset is referenced by a DWARF32 input section of itself or another .debug_* output section,
S may be subject to 32-bit relocation overflow. If we place such DWARF32
sections before DWARF64 sections, we can likely mitigate overflows.
Parsing DWARF is time consuming, breaks the "smart format, dumb linker" design goal of ELF,
and can get in the way if we eagerly free uncompressed buffers after OutputSection::writeTo.
So we use the relocation idea proposed by Igor Kudrin
https://lists.llvm.org/pipermail/llvm-dev/2020-November/146528.html
In practice, the first relocation of .debug_* is good indicator whether it is a
DWARF64 section, to list a few:
- .debug_info: the first relocation is a .debug_abbrev offset
- .debug_names references .debug_info: the first relocation is a .debug_info offset
- .debug_aranges references .debug_info: the first relocation is a .debug_info offset
- .debug_str_offsets references .debug_str: the first relocation is a .debug_str offset
- ...
This patch adds the partition code to finalizeInputSections so that it works
for both orphan sections and when an output section description for .debug_info
is used. In some sense --dwarf32-before-dwarf64 will behave like
--sort-section: it can affect input section order of a wildcard.
"place" sounds like the linker isn't allowed to place DWARF32 sections first, but this obviously isn't the behaviour, if users just so happen to place objects in the right order on the command-line. Perhaps "sort" makes it clearer?