I would like to know what is the purpose of ARM scatter file and ARM Linker address MAP file ? How do they help in compilation and eventually during loading of the executable ?
-
4Do you understand what a linker is in general, what it does for you, and why you want to use one? – Olin Lathrop Apr 30 '14 at 14:01
-
1The MAP file is just for the user's reference - it's output only from the linker and is not used by any standard software component. – DoxyLover Apr 30 '14 at 17:11
-
@ Olin: The linker linkes various modules of program so that there are no unresolved references. – Abhijit K Rao May 02 '14 at 08:01
1 Answers
To compile from C code to an executable image that you can run on an ARM microcontroller, there are two steps: compile, and link.
During compile, the C code will ultimately be turned into object code, which is not usable on its own. In the middle of the process, you may be able to generate intermediate assembly listings for the C files.
During link, the object files will all be combined together and the function calls and global variables will be linked. It also decides where in the target's memory space everything will end up (code, read only data, read/write data).
This is how you can call something like printf
without having the code in your file. When you compile, it doesn't know anything about printf
except for the prototype in stdio.h
. When linked, the linker will fill in the details about where printf
actually lives in memory.
The linker uses a scatter file to know where in the target certain memory areas exist. Typically a microcontroller will map internal Flash to address 0x00000000
. Internal SRAM will exist at some other address, say 0x20000000
, and external DRAM or Flash could exist at another address, 0x80000000
. The scatter file will inform the linker of these areas and direct it to place certain sections of the output in certain areas. Typically, your executable code lives in the text
section, which would typically be stored in your internal flash. Your read only data would live in the section called rodata
and also be stored in flash. Read/write data will typically be in bss
(initialized to zero) or data
(initialized with value), and this would be placed in RAM, with initialized values being stored in another section in flash.
These section names are somewhat toolchain specific, though they are usually similar across tools.
The linker map file is an output file that tells you after linking where all your symbols have ended up. For example it may tell you that main()
has been located at 0x00000278
in Flash, and that the global variable int x
has been located at 0x20001012
in RAM. It will also tell you where linker-generated sections have been placed. These include your C stack, potentially an interrupt stack, and also possibly a heap. The scatter file usually allows you to specify the size of these sections as well.

- 250
- 1
- 5
-
Great explanation! Could I ask if linker script is the same thing with scatter files? – richieqianle Jun 12 '14 at 08:32
-
1"Scatter file" seems to be a more generic term for any file that maps memory and where things should go. I would consider a linker script file to be a specific type of scatter file that indicates where the linker sections should go. This is subjective, though. – rjp Jun 12 '14 at 20:00