10.10. Partial (Incremental) Linking¶
An output file that has been linked can be linked again with additional modules. This is known as partial linking or incremental linking. Partial linking allows you to partition large applications, link each part separately, and then link all the parts together to create the final executable program.
Follow these guidelines for producing a file that you will relink:
The intermediate files produced by the linker must have relocation information. Use the --relocatable option when you link the file the first time. (See Producing a Relocatable Output Module (--relocatable option).)
Intermediate files must have symbolic information. By default, the linker retains symbolic information in its output. Do not use the --no_sym_table option if you plan to relink a file, because --no_sym_table strips symbolic information from the output module. (See Strip Symbolic Information (--no_symtable Option).)
Intermediate link operations should be concerned only with the formation of output sections and not with allocation. All allocation, binding, and MEMORY directives should be performed in the final link.
If the intermediate files have global symbols that have the same name as global symbols in other files and you want them to be treated as static (visible only within the intermediate file), you must link the files with the --make_static option (see Make All Global Symbols Static (--make_static Option)).
If you are linking C code, do not use --ram_model or --rom_model until the final link. Every time you invoke the linker with the --ram_model or --rom_model option, the linker attempts to create an entry point. (See C Language Options (--ram_model and --rom_model Options), Autoinitializing Variables at Run Time (--rom_model), and Initializing Variables at Load Time (--ram_model).)
The following example shows how you can use partial linking:
Step 1: Link the file file1.com; use the --relocatable option to retain relocation information in the output file tempout1.out.
tiarmclang -Wl,--relocatable,--output_file=tempout1 file1.com
file1.com contains:
SECTIONS
{
ss1: {
f1.c.o
f2.c.o
.
.
.
fn.c.o
}
}
Step 2: Link the file file2.com; use the --relocatable option to retain relocation information in the output file tempout2.out.
tiarmclang -Wl,--relocatable,--output_file=tempout2 file2.com
file2.com contains:
SECTIONS
{
ss2: {
g1.c.o
g2.c.o
.
.
.
gn.c.o
}
}
Step 3: Link tempout1.out and tempout2.out.
tiarmclang -Wl,--map_file=final.map,--output_file=final.out tempout1.out tempout2.out