You create a linker map file by passing a specific option to your linker during the build process. This file provides detailed information about the layout of your executable or library, including sections, symbols, and their addresses.
Generating a Linker Map File
The standard way to request a linker map file is by using the -Map
option, followed by the desired output filename.
For example, if you want the map file to be named output.map
, you would typically add:
-Map=output.map
to the linker command line.
Using GCC or G++ (GNU Compiler Collection)
When using GCC or G++, which utilize the GNU linker (ld
), you often pass linker options via the compiler driver using the -Wl
flag. The -Wl
flag passes the comma-separated arguments directly to the linker.
Based on the provided reference and standard GCC documentation, to generate a map file named output.map
with GCC/G++, you would use:
-Wl,-Map=output.map
This tells the GCC/G++ compiler driver to pass -Map=output.map
as an option to the underlying linker (ld
).
Creating Map Files in IDEs (like Vitis)
Integrated Development Environments (IDEs) usually provide graphical interfaces to configure build options. As mentioned in the reference regarding Vitis, you can generate the MAP file by:
- Opening the application's C/C++ settings.
- Navigating to the linker options or settings.
- Adding the specific linker option (
-Wl,-Map=output.map
for GCC-based toolchains) within the designated input field for linker flags.
The exact steps and location of the setting might vary slightly depending on the IDE and version.
What Information is in a Map File?
A linker map file is invaluable for debugging memory usage and symbol resolution issues. It typically includes:
- Section Layout: Details about where different sections (like
.text
for code,.data
for initialized data,.bss
for uninitialized data, etc.) are placed in memory and their sizes. - Symbol Table: A list of all symbols (functions, variables) and their final addresses.
- Input Files: Which object files and libraries were linked.
- Memory Usage: Often a summary of memory regions and how they are utilized.
Here's a simplified view of common information found in a map file:
Information Category | Description |
---|---|
Memory Layout | Addresses and sizes of memory regions (RAM, Flash) |
Section Details | Start address, size, and attributes of each section |
Symbol Listing | Address and source object file for each symbol |
Discarded Sections | Sections removed by the linker optimization |
Creating and analyzing the linker map file is a critical step in optimizing memory usage and understanding the final structure of your compiled program.