Linkers, Loaders & Executables

What is the role of the GOT (global offset table) used in shared libraries?

  1. AAn alphabetical index of the library's function names
  2. BA table that temporarily holds data that did not fit in the cache
  3. 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.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. When dynamic linking uses lazy binding through the PLT (procedure linkage table), which statement is correct?
  2. What is the role of the dynamic linker (such as ld.so) when a dynamically linked program starts on Linux?
  3. What is the purpose of ASLR (address space layout randomization)?
  4. What is the main reason to build an executable as a PIE (position-independent executable)?
  5. What does the OS loader do when a program is started (for example by execve on Linux)?