10.3 Global and Weak Symbols
When a symbol reference appears in an object file without a corresponding
definition, the symbol is declared external. By default, external symbols have global
binding and are referred to as global symbols. External symbols may be explicitly declared
with weak binding, using the __weak__
attribute in C or
the .weak
directive in assembly language.
As the name implies, global symbols are visible to all input files involved in the link. There must be one (and only one) definition for every global symbol referenced. If a global definition is not found among the input files, archives will be searched and the first archive module found that contains the needed definition will be loaded. If a definition is not found for a global symbol, a link error is reported.
The names of weak symbols share the same name space as those for global symbols, but are handled differently. Multiple definitions of a weak symbol are permitted. If a weak definition is not found among the input files, archives are not searched and a value of 0 is assumed for all references to the weak symbol. A global symbol definition of the same name will take precedence over a weak definition (or the lack of one). In essence, weak symbols are considered optional and may be replaced by global symbols, or ignored entirely.