Linkers, Loaders & Executables
What is the main reason to build an executable as a PIE (position-independent executable)?
- ASo that the executable can run on any OS
- BSo that all libraries are included in the executable
- 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.