Linkers, Loaders & Executables
What is the role of the GOT (global offset table) used in shared libraries?
- AAn alphabetical index of the library's function names
- BA table that temporarily holds data that did not fit in the cache
- CA table of the actual addresses of external variables and functions, filled by the dynamic linker at run time, through which the code refers to them
Show answer and explanation
Answer: C. A table of the actual addresses of external variables and functions, filled by the dynamic linker at run time, through which the code refers to them
Position-independent code cannot write the address of a variable in another library directly into an instruction. So each module has a table of addresses (the GOT); the code reads a GOT entry at a PC-relative distance and uses the address stored there. The dynamic linker writes the real addresses into the GOT when the module is loaded. Only the writable data of the GOT is patched, so the code pages remain shared.
- A. It is a table of addresses, not an index.
- B. It has nothing to do with the cache.
- C. Correct. Only the data table is patched, never the code.