| Global Imports

Previous | The TIGCC Linker | Next

Just like startup sections, the concept of global imports is unique to the TIGCC linker. Global imports and startup sections are closely related to each other: It is best to keep startup sections in archive files, so they can be imported as needed, but the existing method of importing archive file members does not work. Usually, an archive file member is imported if a symbol it exports is referenced in a relocation entry. However, code that requires a specific startup section to be included does not necessarily reference any of the symbols in the corresponding archive member; it just needs the startup code to be there. A global import solves this problem by importing an archive member without inserting its address anywhere.
Actually, a global import imports all archive members that export the symbol referenced by the import (and even more, see Conditional Reaction to Global Imports). If no archive member exports this symbol, a warning is emitted. This way, it is very easy to create archive files that react to multiple imports; for example:

- File 1 exports the symbols A and B.
- File 2 exports the symbols B and C.
- File 3 exports the symbols A and C.

A global import for A would cause the files 1 and 3 to be included in the program. If it could only import one file, 6 files would be needed to get the same result:

- File 1 exports the symbol A and creates two global imports for File4 and File6.
- File 2 exports the symbol B and creates two global imports for File4 and File5.
- File 3 exports the symbol C and creates two global imports for File5 and File6.
- File 4 exports the symbol File4.
- File 5 exports the symbol File5.
- File 6 exports the symbol File6.

Global import can be created using the __ref_all_... control symbol. Some global imports are also created automatically by the linker on certain conditions.

- Conditional Reaction to Global Imports
- Automatically Created Global Imports