How Linkers Resolve Multiply-Defined Global Symbols

来源:互联网 发布:淘宝省市区街道联动js 编辑:程序博客网 时间:2024/05/01 11:28

7.6.1 How Linkers Resolve Multiply-Defined Global Symbols

At compile time, the compiler exports each global symbol to the assembler as eitherstrongorweak,andthe
assembler 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
0 0
原创粉丝点击