www.kxcad.net Home > Electronic Index > Altium(Protel) Index
The linker takes one or more relocatable object files and/or libraries as input. A relocatable object file, as generated by the assembler, contains the following information:
Header information: Overall information about the file, such as the code size, name of the source file it was assembled from, and creation date.
Object code: Binary code and data, divided into various named sections. Sections are contiguous chunks of code or data that have to be placed in specific parts of the memory. The program addresses start at zero for each section in the object file.
Symbols: Some symbols are exported - defined within the file for use in other files. Other symbols are imported - used in the file but not defined (external symbols). Generally these symbols are names of routines or names of data objects.
Relocation information: A list of places with symbolic references that the linker has to replace with actual addresses. When in the code an external symbol (a symbol defined in another file or in a library) is referenced, the assembler does not know the symbol's size and address. Instead, the assembler generates a call to a preliminary relocatable address (usually 0000), while stating the symbol name.
Debug information: Other information about the object code that is used by a debugger. The assembler optionally generates this information and can consist of line numbers, C source code, local symbols and descriptions of data structures.
The linker resolves the external references between the supplied relocatable object files and/or libraries and combines the supplied relocatable object files into a single relocatable linker object file.
The linker starts its task by scanning all specified relocatable object files and libraries. If the linker encounters an unresolved symbol, it remembers its name and continues scanning. The symbol may be defined elsewhere in the same file, or in one of the other files or libraries that you specified to the linker. If the symbol is defined in a library, the linker extracts the object file with the symbol definition from the library. This way the linker collects all definitions and references of all of the symbols.
With this information, the linker combines the object code of all relocatable object files. The linker combines sections with the same section name and attributes into single sections, starting each section at address zero. The linker also substitutes (external) symbol references by (relocatable) numerical addresses where possible. At the end of the linking phase, the linker either writes the results to a file (a single relocatable object file) or keeps the results in memory for further processing during the locating phase.
The resulting file of the linking phase is a single relocatable object file (.out). If this file contains unresolved references, you can link this file with other relocatable object files (.obj) or libraries (.lib) to resolve the remaining unresolved references.
With the linker command line option --link-only, you can tell the linker to only perform this linking phase and skip the locating phase. The linker complains if any unresolved references are left.