https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116642

--- Comment #30 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #29)
> That is: `-static -pie` which should remove the requirement of
> `-Wl,--no-dynamic-linker` too.
> 
> Basically a (non-static) PIE binary requires using the dynamic loader to do
> the relocations while a static PIE does not.

Actually -static-pie.  -static-pie is different from -static -pie (with a
space):

$ cc -static-pie hw.c
$ file a.out
a.out: ELF 64-bit LSB pie executable, x86-64, version 1 (GNU/Linux), static-pie
linked, for GNU/Linux 6.10.0, with debug_info, not stripped
$ cc -static -pie hw.c
$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically
linked, for GNU/Linux 6.10.0, with debug_info, not stripped

>From a "normal programmer" perspective, ASLR is performed for the former, but
not the latter.

In the former the load address of the executable is unknown, so some relocs are
turned to R_X86_64_RELATIVE by ld, and Glibc rcrt1.o is linked in to resolve
R_X86_64_RELATIVE at program startup.  

In the latter the load address is fixed, so all relocs are just resolved by ld,
nothing is turned to R_X86_64_RELATIVE.

Reply via email to