Introduction
A linker map file is a text report that a linker writes, on request, alongside the program or library it builds. It shows where everything ended up: the address and size of each section or segment, which object file and library each piece came from, and the address of each public symbol. Developers use it to find what makes a program large, to check the memory layout of firmware, and to turn a crash address into a function name when no other debug information is at hand.
The usual extension is .map, which is also used for
JavaScript source maps and other unrelated
formats.
Structure
There is no standard layout: each linker writes its own, and it can change between versions. Most map files have the same parts in some form: the program name and timestamp, a table of sections or segments with start addresses and lengths, a list of the input object files and libraries with what each contributed, and a list of public symbols sorted by name or by address. The Microsoft linker also gives the preferred load address and the entry point; the GNU linker lists the archive members it pulled in and why, and the memory regions of the linker script.
Ask for one with /MAP for the Microsoft linker, -Map=file
for the GNU linker and LLD on Linux, and -map file for Apple’s linker.
The layouts by linker page shows each
linker’s headings, columns and markers.
Not described
Known, not yet covered
- Reference: the exact column widths of GNU ld’s map, the gold linker’s map, and Apple’s
ldmap as the linker source writes it, on the layouts page. - Viewer: there is no viewer for linker maps yet.
Unknown
- Reference: link.exe’s own map layout: no standard or Microsoft document defines map files, so anything beyond observed output is undocumented.
Also used for
- JavaScript source map – JSON that maps minified or compiled web code back to its source.
Links
Software
- Visual Studio – Microsoft’s development environment, whose linker writes them with
/MAP(Windows) - GNU Binutils – GNU’s binary tools, whose
ldwrites them with-Map(Linux, macOS, Windows) - LLD – the LLVM linker, which writes them too (Linux, macOS, Windows)
- Text editor – any editor can read them, since they are plain text
Reference
- Command-line options – the GNU ld manual’s list of options, including
-Map