With two files, one compiled and linked with gcc
and the other manually with nasm
and ld
I get
- ELF 32-bit LSB shared object …
- ELF 32-bit LSB executable …
What's the difference between these two things? I can see with readelf -h
that one is
- Type:
DYN (Shared object file)
- Type:
EXEC (Executable file)
I can see these documented on Wikipedia as ET_DYN
and ET_EXEC
. What are the practical differences between these two?
Best Answer
It seems this has something to do with Position Independent Executable (PIE). When GCC compiles executable by defaults it makes them PIE which changes the output flag on the ELF Header to
ET_DYN
.You can disable the generation of PIE executables with
gcc -no-pie
If you're seeing this check the default options gcc is configured with
gcc -v
, you should see something like--enable-default-pie
.Answer inspired by this submission on StackOverflow. I intend to play more with it and explain more here.