6.2 Psects and Relocation
The linker can read both relocatable object files (.o extension) and object-file libraries (.a extension). Library files are a collection of object files packaged into a single unit and once unpacked, are processed in the same way as individual object files.
Each object file consists of a number of records. Each record has a type that indicates what sort of information it holds. Some record types hold general information about the target device and its configuration, other records types can hold data; and others, program debugging information.
A lot of the information in object files relates to psects (program sections). Psects are an assembly domain construct and are essentially a block of something, either instructions or data. Everything that contributes to the program is located in a psect. See 4.8 Program Sections for an introductory guide. There is a particular record type that is used to hold the data in psects. The bulk of each object file consists of psect records containing the executable code and some objects.
The linker performs the following tasks.
- Combining the content of all referenced relocatable object files into one.
- Relocation of psects contained in the object files into the available device memory.
- Fixup of symbolic references in content of the psects.
Relocation consists of allocating the psects into the memory of the target device.
The target device memory specification is passed to the linker by the way
of linker options. These options are generated by the command-line driver, pic-as
. There are no linker scripts or means of specifying options in
any source file. The default linker options rarely need adjusting. But they can be changed,
if required, with caution, using the driver option -Wl
, (see 3.4.36 Wl: Pass Option To The Linker,
Option).
Once the psects have been placed at their final memory locations, symbolic references made within the psect can be replaced with absolute values. This is a process called fixup.
The output of the linker is a single object file. This object file is absolute, since relocation is complete and all code and objects have been assigned an address.