Linkers, Loaders & Executables

What is the main reason to build an executable as a PIE (position-independent executable)?

  1. ASo that the executable can run on any OS
  2. BSo that all libraries are included in the executable
  3. CSo that the executable's own code can also be placed at a different address each run by ASLR
Show answer and explanation

Answer: C. So that the executable's own code can also be placed at a different address each run by ASLR

Older executables assumed they would be loaded at a fixed address, so ASLR could shift only libraries and the stack while the main program's code addresses stayed known to attackers. A PIE builds the main program as position-independent code too, so it runs wherever it is loaded and its addresses can also be randomized. Many current Linux distributions build PIEs by default.

  • A. It does not bridge different OSes.
  • B. Including libraries is static linking.
  • C. Correct. A fixed address would leave the main program predictable.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. What does the OS loader do when a program is started (for example by execve on Linux)?
  2. In a C program, which statement is correct about the address where the OS first starts execution (the entry point)?
  3. When a C main function ends with "return 3;", what generally happens to the value 3?
  4. What happens when the strip command is applied to an executable?
  5. How does a linker treat a weak symbol?