How is the address of the text section of a PIE executable determined in Linux?
First I tried to reverse engineer it a bit: printf ' #include <stdio.h> int main() { puts("hello world"); } ' > main.c gcc -std=c99 -pie -fpie -ggdb3 -o pie main.c echo 2 | sudo tee /proc/sys/kernel/randomize_va_space readelf -s ./pie | grep -E 'main$' gdb -batch -nh \ -ex 'set disable-randomization off' \ -ex 'start' -ex 'info line' \ -ex 'start' -ex 'info line' \ -ex 'set disable-randomization on' \ -ex 'start' -ex 'info line' \ -ex 'start' -ex 'info line' \ ./pie \ ; Output: 64: 000000000000063a 23 FUNC GLOBAL DEFAULT 14 main Temporary breakpoint 1, main () at main.c:4 4 puts("hello world")