This adds the emission of an optional section, .debug_lld_linkmap, to the output.
The .debug_lld_linkmap section contains a list of entries that describe how the linker has mapped input sections to address regions.
The section starts with a header consisting of two fields:
length (uleb)The length in bytes of the linkmap data not including the length field itself. This allows for padding to be added to the section, useful for purposes such as slop for incremental linking. The value cannot exceed Elf_Off.
version (uleb)The version of this description information. Currently, 0. The value cannot exceed Elf_Word.
The header is followed by a single field:
entries (uleb)The number of entries in this section. This allows for pre-allocating an array of entry structures. The value cannot exceed Elf_Off.
Followed by a list of entries. Each entry describes a section from an input file and its location in the runtime memory image of the output. Entries are composed of 4 ulebs:
File (uleb)An offset into the .debug_lld_linkmap_str section. The associated string contains the path of an object file that was a linker input. The value cannot exceed Elf_Off.
Section (uleb)An offset into the .debug_lld_linkmap_str section. The associated string contains the name of an ELF section from the file identified by the first field in this entry. The value cannot exceed Elf_Off.
Address (uleb)The virtual address that the linker assigned to the section. The value cannot exceed Elf_Addr.
Size (uleb)The size of the section in the run-time memory image. The value cannot exceed Elf_Off.
ELF section header fields are:
|sh_offset||offset of the section in the file|
|sh_link||index of the corresponding .debug_lld_linkmap_str section|
See corresponding RFC for motivation: https://lists.llvm.org/pipermail/llvm-dev/2021-September/152697.html
Note that .debug_lld_linkmap provides similar information to the -Map option. However, emitting the section is *much* more efficient than generating a -Map file. Testing with a chromium package on my windows development box, I recorded the following results with this patch:
Base link = 3.524 s
With -Map =8.441 s
With --debug-sections = 3.910 s.
The additional information occupied 20% of the chromium ELF size (compiled without debugging data).