CS485G Spring 2015 35
(a) Programs define symbols and reference them:
1 void swap() {...} // exported global identifier
2 extern int myGlobal; // imported global identifier
3 int myGlobal; // also local, so exported, too
4 swap(&myGlobal, &myLocal); // reference identifiers
(b) The compiler uses an internal data structure called the symbol
table to keep track of all identifiers.
(c) The symbol table, indexed by the identifier, includes informa-
tion such as type, location, and global/local flag.
(d) The compiler includes the global symbols as part of the object
file it outputs.
(e) The object file marks any reference to an imported global as
“dangling”.
(f) The linker resolves dangling references by connecting them to
the proper identifier in another object file.
(g) The compiler has already resolved references to local symbols.
(h) It’s a link-time error if the linker discovers multiple possible res-
olutions.
(i) If desired, the linker then consults libraries to resolve any still-
dangling references by adding more object files.
(j) If the linker can resolve all dangling references, the result is an
executable file that the operating system can load and run.
(k) Otherwise, the result is an object file that can be used for further
linking steps.
(l) The early Unix convention was to call the executable file “a.out”;
now it usually has a name without an extension.
6. Shared object files
(a) If desired, the linker can store its result as a shared object file
(conventional extension “.so”), which the program can load
into memory dynamically (typically when the program starts)
in such a way that it is shared among all processes that need it.
(b) Libraries are usually shared object files.
(c) When the linker resolves a identifier by referring to a shared
object file, it leaves it dangling (but resolved); full resolution
happens when the shared object file is loaded into memory.
Kommentare zu diesen Handbüchern