https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116642
--- Comment #32 from Joshua <joshudson at gmail dot com> --- >> Build your program as a static PIE and use assembly >> (or a very limited C subset) to relocate itself on startup. > All other implementations (Glibc, Musl, and Linux kernel > with KASLR enabled on modern architectures like RISC-V) > do this, instead of urging the compiler to add some > feature to disable all relocs. Yeah, about that. Both glibc and musl do it with a restricted subset of C code. I actually looked at the build step of the relocation engine file (elf/dl-reloc-static-pie.c in glibc) for options to pass to the compiler. It looks to me very much like we're pushing up against a situation where further machine optimizations could start introducing a relocation in the middle of the relocation code. Say the top of elf/dl-reloc-static-pie.c might compile to to something like this and I see nothing stopping it: 29 struct link_map *main_map = _dl_get_dl_main_map (); leaq dl_main_map, %rdi 37 main_map->l_addr = elf_machine_load_address (); movabs .LC1, %xmm0 ;; .LC1: .quad load_address 40 main_map->l_ld = ((void *) main_map->l_addr + elf_machine_dynamic ()); leaq load_address, %rsi leaq dynamic_address(%rsi), %rsi movabs %rsi, %xmm1 punpcklqdq movabs %xmm0, (%rdi) And if you think this assembly is nonsensical; it's the same assembly that's causing the fault, for what looks like the same reasons. And that's reason enough.