7.6.1 How Linkers Resolve Multiply-Defined Global Symbols
At compile time, the compiler exports each global symbol to the assembler as eitherstrongorweak,andtheassembler encodes this information implicitly in the symbol table of the relocatable object file. Functions
and initialized global variables get strong symbols. Uninitialized global variables get weak symbols. For
the example program in Figure 7.1, buf, bufp0,main,andswapare strong symbols;bufp1isaweak
symbol.
Given this notion of strong and weak symbols, Unix linkers use the following rules for dealing with multiplydefined symbols:
- Rule 1: Multiple strong symbols are not allowed.
- Rule 2: Given a strong symbol and multiple weak symbols, choose the strong symbol.
- Rule 3: Given multiple weak symbols, choose any of the weak symbols