This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [ELF] Add emission of an optional linkmap section
Needs ReviewPublic

Authored by bd1976llvm on Sep 14 2021, 7:42 PM.

Details

Summary

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:

PropertyValue
sh_typeSHT_DEBUG_LLD_LINKMAP
sh_flags0
sh_addr0
sh_offsetoffset of the section in the file
sh_sizesection size
sh_linkindex of the corresponding .debug_lld_linkmap_str section
sh_info0
sh_addralign1
sh_entsize1

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).

Diff Detail

Event Timeline

bd1976llvm created this revision.Sep 14 2021, 7:42 PM
bd1976llvm requested review of this revision.Sep 14 2021, 7:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 14 2021, 7:42 PM
bd1976llvm retitled this revision from [LLD] Add emission of an optional linkmap section to [LLD] [ELF] Add emission of an optional linkmap section .Sep 14 2021, 7:53 PM
phosek added a subscriber: phosek.Sep 15 2021, 10:50 AM

Fix linux build and formatting issues.

Fix off-by-one problem.

bd1976llvm edited the summary of this revision. (Show Details)Sep 16 2021, 9:25 AM
bd1976llvm edited the summary of this revision. (Show Details)Sep 16 2021, 3:44 PM
bd1976llvm edited the summary of this revision. (Show Details)Sep 23 2021, 5:42 PM