9.5.1 Basic Linker Script Concepts
The linker combines input files into a single output file. The output file and each input file are in a special data format known as an ELF object file format. Each file is called an object file. Each object file contains, among other things, a list of sections. A section in an input file is called an input section; similarly, a section in the output file is an output section.
Each section in an object file has a name and a size. Most sections also have an associated block of data, known as the section contents. A section may be marked as loadable, which mean that the contents should be loaded into memory when the output file is run. A section with no contents may be allocatable, which means that an area in memory should be set aside, but nothing in particular should be loaded there (in some cases this memory must be zeroed out).
Every loadable or allocatable output section has two addresses. The first is the VMA, or virtual memory address. This is the address the section will have when the output file is run. The second is the LMA, or load memory address. This is the address at which the section will be loaded. In most cases, the two addresses will be the same. An example of when they might be different is when a section is intended to contain RAM-located functions (e.g. the default .ramfunc
section). In this case, the program-memory address would be the LMA and the data-memory address would be the VMA.
The sections in an object file can be viewed by using the xc32-objdump
program with the -h
option.
Every object file also has a list of symbols, known as the symbol table. A symbol may be defined or undefined. Each symbol has a name, and each defined symbol has an address, among other information. If a C program is compiled into an object file, a defined symbol will be created for every defined function and global or static variable. Every undefined function or global variable which is referenced in the input file will become an undefined symbol.
Symbols in an object file can be viewed by using the xc32-nm
program, or by using the xc32-objdump
program with the -t
option.