I file /bin/ls
and get the output:
/bin/ls: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, stripped
And I found the reason is that my gentoo is compiling everything with -pie .
If I pass -nopie to gcc, I will get the right answer:
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, not stripped
Also, I find something at building a .so that is also an executable. It uses -pie to make a DSO executable.
In gcc's man page, it describes in brief:
-pie
Produce a position independent executable on targets that support it.
So I'm wondering what -pie do exactly? How it makes my executable to be recognized as a shared object?