Course: Computer Architectures
Source lesson: ARM Toolchain
1. Why a toolchain is needed
C, C++ and assembly files are separate source descriptions. The ARM processor needs one final image containing machine code, data and addresses. The toolchain performs that transformation in stages.
source files → object files → linked image → loaded ARM programA cross-compiler runs on the development computer and creates code for an ARM target. It does not translate ARM machine code back into C or C++.
2. Compile, link and convert
Compile and assemble
armclang translates C/C++ into ARM object code and can assemble GNU-style assembly. armasm handles legacy ARM assembly syntax. Each source file becomes an object file. At this point, a reference to a function in another file may still be unresolved.
Link
armlink combines object files and libraries. It resolves symbols such as function and variable names, removes unused sections and assigns final addresses. It needs the target memory map so that code, constants, RAM data, stack and heap are placed in valid regions.
A scatter file supplies this memory layout when the default arrangement is insufficient.
Inspect and convert
fromelf reads an ELF image, displays disassembly or symbols and converts the image to formats used by loaders and programming tools, such as plain binary and Intel HEX.
3. Load view and execution view
The two views answer different questions.
| View | Question | Typical location |
|---|---|---|
| Load view | Where are the bytes stored in the image? | Flash or ROM |
| Execution view | Where does the program use them at runtime? | Flash and/or RAM |
Read-only code and constants often have the same load and execution address because they execute directly from Flash.
Initialized writable data usually differs:
Flash load address
↓ startup copy
RAM execution addressExample:
int counter = 10;The initial value 10 is stored in the Flash image. Before main(), startup code copies it to the RAM address used by counter. The program then reads and writes the RAM copy.
Zero-initialized data has no initial values that need to be copied. Startup code reserves its RAM region and fills it with zeros.
4. Startup before main()
reset → Reset_Handler → runtime entry → main()Reset_Handler is the first application-level code reached after reset. The C runtime then prepares the environment by setting up stack and heap information, initializing library data, copying initialized data to RAM, clearing zero-initialized data and calling constructors when needed. The source identifies __main and __rt_entry in this path.
5. Output files as debugging tools
- The executable
.elfor.axfcontains the linked image and can include symbols and debug data. - A listing file lets you compare source instructions with generated machine code.
- A dependency file explains why a source file is rebuilt.
- A map file shows where symbols and sections were placed and how much memory they use.
- A static call graph shows who calls whom.
- A build log records the complete build configuration and result.
The map file is especially useful when a variable appears at an unexpected address or a memory region is full.
6. Optimization changes what you see
At O0, generated instructions usually follow the source more directly. At higher levels, the compiler may keep values in registers, inline functions, remove unused work or reorder instructions. The executable can become smaller or faster while the debugger view becomes less direct.
Compiler optimization happens while producing object files. Link-time removal of unused sections happens later and can occur independently.
Common confusions
- A compiler translates source code to object code. A linker combines object code and assigns final addresses.
- Load address means storage in the image. Execution address means runtime use.
- Flash-to-RAM copying applies to initialized writable data. Read-only code may execute directly from Flash.
main()is the user function. Startup code and__mainprepare the environment before it runs.- An ELF image contains metadata that a plain binary may omit.
Retrieval questions with answers
-
Why can
counterhave different addresses in the two views?
Its initial value is stored in Flash, then copied to the RAM address where the running program reads and writes it. -
Which tool resolves a function referenced from another object file?
armlinkresolves the symbol and assigns the function’s final address. -
What happens to a zero-initialized global before
main()?
Startup code reserves its RAM region and clears it to zero. -
Why can a high optimization level make a breakpoint disappear?
The compiler may remove or transform the source operation, so no matching instruction remains. -
What would you inspect to find a variable’s final address and section size?
The linker map file.