Hi all,
While working on our DWARF64 investigation, we ran into the same DWARF32/DWARF64 mixed-input ordering problem discussed in this earlier thread:
I would like to continue that discussion with a concrete proposal based on SHT_DWARF64.
Proposal
This RFC proposes using a new ELF section type, SHT_DWARF64, as an explicit producer/linker contract.
The proposed approach is:
- LLVM producers emit DWARF64
.debug_*sections withsh_type = SHT_DWARF64. - LLVM ELF tools and MC recognize and round-trip
SHT_DWARF64. - lld adds an opt-in option, currently drafted as
--dwarf32-before-dwarf64, to place DWARF32 debug input sections before DWARF64 ones.
The main advantage is that lld does not need to infer DWARF32 vs DWARF64 by parsing debug contents, inspecting relocations, or relying on build-system ordering. With SHT_DWARF64, lld can simply stable-partition .debug_* input sections: non-SHT_DWARF64 sections first, then SHT_DWARF64 sections, preserving relative order within each group.
Open issues for discussion
The main open question is the ABI/tooling impact of introducing a new ELF section type.
SHT_DWARF64 gives lld an explicit and cheap signal, but it is still an ELF ABI extension. I would like feedback from ELF/generic-abi/tooling maintainers on whether this direction is acceptable, what value should be used, and what compatibility impact this may have on existing ELF tools that currently expect .debug_* sections to be SHT_PROGBITS.
The current draft treats SHT_DWARF64 as producer-provided metadata and does not add fallback DWARF-content scanning in lld.
Mixed DWARF32/DWARF64 within one input section
One corner case is that a single input debug section may itself contain both DWARF32 and DWARF64 units. Section-level ordering cannot handle that case because the section is no longer an indivisible sorting unit.
A possible design is to split such sections by DWARF unit contribution, then apply the same DWARF32-before-DWARF64 ordering to the resulting pieces. This requires parsing unit boundaries and updating the affected relocations/section references after reordering. It may also need special handling for related sections whose entries are referenced from `.debug_info` rather than directly classifiable from local section contents.
The current draft keeps section type as the sorting granularity. I would like feedback on whether this mixed-within-one-section corner case is important enough to support in the initial implementation, or should be handled as a follow-up.