https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116642
--- Comment #27 from Xi Ruoyao <xry111 at gcc dot gnu.org> --- Build your program as a static PIE and use assembly (or a very limited C subset) to relocate itself on startup. In a static PIE there are only relative relocs, and it's fairly easy to handle relative relocs even in assembly.