Skip to content

Instantly share code, notes, and snippets.

@lirenlin
Created October 2, 2018 11:59
Show Gist options
  • Save lirenlin/52b1297e5ceb52c30162a9fac6d66fa1 to your computer and use it in GitHub Desktop.
Save lirenlin/52b1297e5ceb52c30162a9fac6d66fa1 to your computer and use it in GitHub Desktop.
pie, pic, static pie
position independent executable: executable
position independent code: shared object/library
PIE is to support address space layout randomization (ASLR) in executable files.
static pie: executable without external dependency of shared library or dynamic linker.
It should be able to self-relocate itself.
There must be a entry point stub which only use pc relative addressing.
Entry point stub is loaded at a random address, and the code in it use pc relative addressing which doesn't need to know
the load address of the binary. It will somehow, call its own functions to resolve any dynamic relocations in its code with
the load address it has got during this invocation. After this finished, the binary is specilized to concrete addresses.
For normal pie (not static), the dynamic linker would resolve the dynamic relocations.
For internal symbols, use absolution addressing(offset to the beginning of binary, this is fixed during static linking time)
It is updated to RELATIVE, at runtime, base address is added to it to get complete runtime address.
For external symbols, use GOT/PLT table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment