There is no standard for linker map files. Each linker writes its own report, the documentation describes only what it contains rather than its exact layout, and the layout can change between versions. This page describes four families as their documentation and source code show them; the examples are illustrations built from the format strings in that source, not copies of real files.
GNU ld
Written with -Map=file (or to standard output with
-M / --print-map). -Map=- writes to standard
output, a directory name puts the file inside that directory, and % in the
name is replaced by the output file’s path. The manual says the map shows where object
files are placed in memory, how common symbols are allocated, every archive member
included and the symbol that caused it, and the values given to symbols. GNU ld’s
source (ldmain.c and ldlang.c) prints these headings:
| Heading | Contents |
|---|---|
Archive member included to satisfy reference by file (symbol) | For each archive member pulled in: the member as archive(member) (or just its name), then, lined up in a second column, the file that referred to it and the symbol in brackets. |
As-needed library included to satisfy reference by file (symbol) | The same for shared libraries given with --as-needed. |
Allocating common symbols | A table headed Common symbol, size, file. |
Discarded input sections (or There are no discarded input sections) | Input sections removed from the link. Shown by default; --no-print-map-discarded leaves it out. |
Memory Configuration | A table of Name, Origin, Length and Attributes: the memory regions. |
Linker script and memory map | The main part (below). |
Cross Reference Table | Only with --cref, which the manual says goes into the map file when there is one. |
Lines in the memory map
The source prints these kinds of line (format strings from ldlang.c):
| Line | Meaning |
|---|---|
LOAD file | An input file. |
START GROUP … END GROUP | A group of input files. |
| Output section | Its name on a new line, then its address and size; load address 0x… follows when the load address differs. |
| Input section | Indented by one space: the section name, then 0xaddress size file; with relaxation, (size before relaxing) may follow. |
| Symbol | Its address and name, under the input section; local symbols, listed with --print-map-locals, are marked (local). |
*fill* | Padding inserted by the linker, with its address and size. |
| Script commands | Input section patterns such as SORT_BY_NAME(…) and EXCLUDE_FILE(…), and INSERT commands, as written in the script. |
OUTPUT(file target) | The output file, with its target name when known. |
Exact column widths and the order of these lines in a real map are not set out in the manual; read the source or a real map for them.
LLD for ELF
ld.lld -Map=file writes one table, ordered by address, showing
output sections, the input sections inside each, and the symbols inside each input
section. Its header line is:
VMA LMA Size Align Out In Symbol
201000 201000 15 4 .text
201000 201000 e 4 test.o:(.text)
201000 201000 0 1 main
20100e 20100e 0 1 local
| Column | Format | Meaning |
|---|---|---|
| VMA | hexadecimal, right-aligned in 16 columns (8 for 32-bit) | Virtual (run-time) address. |
| LMA | same | Load address; differs from VMA when the section is copied at start-up. |
| Size | hexadecimal, 8 columns | Size in bytes. |
| Align | decimal, 5 columns | Alignment; 1 on symbol lines. |
| Out | at the left | Output section name. |
| In | indented 8 spaces | Input section as file:(section); also linker-script commands and assignments inside a section. |
| Symbol | indented 16 spaces | Symbol name, demangled. |
With --cref, a Cross Reference Table follows, with
Symbol left-aligned in 49 columns and File: the defining file on
the symbol’s line, then each referring file on its own line.
Microsoft linker (link.exe) and lld-link
Written with /MAP[:filename]; the default name is the
program’s base name with .map. Microsoft’s documentation lists what it
holds; the lines quoted below are from LLD’s lld-link, whose
MapFile.cpp says it writes “the same format as link.exe (based on
observations)”.
| Part | Contents |
|---|---|
| Module name | The program’s base name, on the first line. |
| Timestamp | Timestamp is hex (date): the time stamp from the program file header, not the file system. |
| Preferred load address | Preferred load address is hex: the image base, 16 hexadecimal digits. |
| Groups | A table headed Start, Length, Name, Class: each group’s start as section:offset (%04x:%08x), its length (8 hexadecimal digits and H), name and class (CODE or DATA). |
| Public symbols | A table headed Address, Publics by Value, Rva+Base, Lib:Object: each public symbol’s section:offset, name, flat address (16 hexadecimal digits) and the object file that defines it (as library:object for library members), or <absolute>, <linker-defined> or <common>. link.exe sometimes writes f or i markers between the address and the file; LLD leaves that space blank, and their exact meaning is not documented. |
| Entry point | entry point at section:offset. |
| Static symbols | Static symbols, in the same columns as the publics. |
| Exports | Only with /MAPINFO:EXPORTS: in LLD, a heading Exports, a header ordinal name, then each ordinal and name, with exported name: when the export name differs. |
EXPORTS is the only /MAPINFO argument current
documentation lists. lld-link /MAP writes this layout.
Apple ld and LLD for Mach-O
Written with -map path. The layout below is the one
ld64.lld writes, from its source; it is meant to match Apple’s linker,
whose own source was not read. Headings start with #, columns are
separated by tabs, contents are in address order, and dead-stripped contents are
included.
| Heading | Contents |
|---|---|
# Path: file | The output file. |
# Arch: arch | Its architecture name. |
# Object files: | One line per input, [ n] path, with archive members as lib.a(member.o). Index 0 is linker synthesized: contents the linker made itself. |
# Sections: | Header # Address Size Segment Section, then one line per section: address and size as 0x%08X, segment and section names. |
# Symbols: | Header # Address Size File Name, then one line per symbol: address, size, [n] index of the object file, and name. Synthesised entries carry descriptive names such as literal string: …, non-lazy-pointer-to-local: …, compact unwind info or helper helper. |
# Dead Stripped Symbols: | When dead stripping is on: header # Size File Name, then each removed symbol with <<dead>> in place of an address. |
# Path: hello
# Arch: arm64
# Object files:
[ 0] linker synthesized
[ 1] hello.o
# Sections:
# Address Size Segment Section
0x100003F8C 0x00000024 __TEXT __text
# Symbols:
# Address Size File Name
0x100003F8C 0x00000024 [ 1] _main
# Dead Stripped Symbols:
# Size File Name
<<dead>> 0x00000010 [ 1] _unused
Sources
GNU, ld command-line
options (-M, -Map, --cref, the map
options); GNU ld source ldmain.c and ldlang.c (headings and
line formats). LLVM LLD source ELF/MapFile.cpp,
COFF/MapFile.cpp and MachO/MapFile.cpp. Microsoft,
/MAP
(Generate Mapfile) and
/MAPINFO.
Not covered or unknown: the exact layout link.exe itself writes (only LLD’s copy of
it was read), the meaning of its f and i markers, Apple’s
own ld source, and other linkers such as gold.