Jeffrey&Lynny

一个温馨小家庭的.Net生活

导航

Linker and Loader

P1. When will link take place?
It can take action in 3 different places:
1. compile-time
2. load-time
3. run-time.

P2. To create executable file, the compiler must complete 2 tasks:
1. Symbol Resolution: associate the symbol definition with symbol reference in OBJ files.
2. Relocation: allocate the memory location for various symbols. Modify all the symbol references to corresponding memory location.

P3, there are 3 types of "object files":
1. Relocatable object file.
2. Executable object file.
3. Sharable object file.

P4, Symbol table contains 3 types of symbols:
1. global defined symbol
2. referenced external symbol
3. local referenced and defined symbol.(Note: it is different from local variable, which is managed in stack. Linker does not care of local variables)

P5, Relocation has 2 steps:
1. combile all the sections in the final object file, and assign memory location to the symbols
2. modify all the symbol references, so that they point to the correct runtime memory address.(linker with the help of "Relocation Entry")
Note: because compiler only knows about the currect module file, so whenever it encounters a unknown symbol reference, it will generate a "Relocation Entry" for linker's reference.

P6, How linker resolves unresolved externals symbol with libraries?(Q31998 in KB)
1. Find all modules in the library that define current unresolved externals. 
2. Process those modules (you may pickup more unresolved externals). The linker keeps making passes through that library until no new unresolved externals are picked up. 
3. It then advances to the next library. 

Note: In a similar manner, the linker makes a pass through the entire set of libraries. After the last library is searched, if new unresolved externals have been picked up, it returns to the first library and makes another pass.(With this algorithm, we can resolve most of the cross-reference issue)


posted on 2006-04-16 21:22  比尔盖房  阅读(1005)  评论(1编辑  收藏  举报