Search code examples
linuxgccg++gnusysv

How can I force gcc/g++ to create SYSV exectables instead of GNU/Linux?


I'm trying to build executables (both programs and shared objects) on a relatively modern Linux distro (A) and wanting to run those on a fairly old one (B). A can build SYSV but sometimes it falls back to GNU/Linux, causing problems when running such executables on B (B refuses to run as such).

How can I force gcc/g++ (or the linker) to build SYSV only executables? If not possible a follow-up question would be what is triggering/forcing gcc/g++ to adopt GNU/Linux convention instead of SYSV (expanded on this question)? How can I prevent such linkage from happening?

Thanks


Solution

  • Apparently there is no formal way to do so (even passing the linker flag -Wl,--hash-style=sysv may not work depending on the code one has compiled).

    The linker will try to default to SYSV but then use GNU/Linux when necessary. Conditions that trigger this behaviour are (at least)

    1. STT_GNU_IFUNC - Basically having functions with such attributes: __attribute__(ifunc(...)) - This code has to go unfortunately
    2. The compiler flag gnu-unique-object has to be disabled (i.e. the compiler you're using has to be configured and built with flag --disable-gnu-unique-object)

    By performing the above, the linker should use SYSV hash style table when producing executables.


    Bonus: if you then want to compile your code to be runnable on on older Linux distros, you may want to force include during your compile stages these headers. You would also want to build your custom libstdc++ with such headers and then ship it with your binaries.