SPRUI03E June 2015 – January 2023
There are two ways to exhaustively search for unresolved symbols:
The linker normally reads input files, including archive libraries, only once when they are encountered on the command line or in the command file. When an archive is read, any members that resolve references to undefined symbols are included in the link. If an input file later references a symbol defined in a previously read archive library, the reference is not resolved.
With the --reread_libs option, you can force the linker to reread all libraries. The linker rereads libraries until no more references can be resolved. Linking using --reread_libs may be slower, so you should use it only as needed. For example, if a.lib contains a reference to a symbol defined in b.lib, and b.lib contains a reference to a symbol defined in a.lib, you can resolve the mutual dependencies by listing one of the libraries twice, as in:
cl6x --run_linker --library=a.lib --library=b.lib --library=a.lib
or you can force the linker to do it for you:
cl6x --run_linker --reread_libs --library=a.lib --library=b.lib
The --priority option provides an alternate search mechanism for libraries. Using --priority causes each unresolved reference to be satisfied by the first library that contains a definition for that symbol. For example:
objfile references A
lib1 defines B
lib2 defines A, B; obj defining A references B
% cl6x --run_linker objfile lib1 lib2
Under the existing model, objfile resolves its reference to A in lib2, pulling in a reference to B, which resolves to the B in lib2.
Under --priority, objfile resolves its reference to A in lib2, pulling in a reference to B, but now B is resolved by searching the libraries in order and resolves B to the first definition it finds, namely the one in lib1.
The --priority option is useful for libraries that provide overriding definitions for related sets of functions in other libraries without having to provide a complete version of the whole library.
For example, suppose you want to override versions of malloc and free defined in the rts6600_elf.lib without providing a full replacement for rts6600_elf.lib. Using --priority and linking your new library before rts6600_elf.lib guarantees that all references to malloc and free resolve to the new library.
The --priority option is intended to support linking programs with SYS/BIOS where situations like the one illustrated above occur.