Linkers, Loaders & Executables

Which describes position-independent code (PIC)?

  1. AMachine code that runs the same on any CPU
  2. BMachine code that keeps moving itself in memory while it runs
  3. CMachine code built to run correctly without modification wherever in memory it is loaded
Show answer and explanation

Answer: C. Machine code built to run correctly without modification wherever in memory it is loaded

A shared library may be loaded at a different address in each process. Position-independent code refers to functions and data not by fixed addresses but by distances from the PC or through a table of addresses (the GOT). Then the code pages need no patching when the load address changes, so one copy in physical memory can be shared by many processes.

  • A. Machine code differs for each ISA.
  • B. It does not keep relocating itself.
  • C. Correct. Shared libraries depend on it.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. What is the role of the GOT (global offset table) used in shared libraries?
  2. When dynamic linking uses lazy binding through the PLT (procedure linkage table), which statement is correct?
  3. What is the role of the dynamic linker (such as ld.so) when a dynamically linked program starts on Linux?
  4. What is the purpose of ASLR (address space layout randomization)?
  5. What is the main reason to build an executable as a PIE (position-independent executable)?