问题
I need to deploy to a Red Hat 4.1.2 box (which has gcc 4.1.2). I use GCC 4.6.1 on Ubuntu 11.10 for development. Unfortunately some of the binaries that my build process creates are not usable on the RedHat machine. The reason seems to be an ABI change, which according to another Stackoverflow question resulted from the introduction of STT_GNU_IFUNC symbols. Is there a way to prevent exporting any such symbols so that my binary can use the old ABI? I used nm to look for any symbols of "i" type on my binary but found none.
I ask this because some of my other binaries as well as some 3rd party libs I build (tbb, boost) are not using the new ABI and so run fine on the RedHat machine.
Hope that is clear. Thanks in advance.
回答1:
In general, UNIX systems support backward binary compatibility (a binary built on an old machine continues to run on a newer one), but not the reverse. You can't expect a binary built on a new system to run on an older one. STT_GNU_IFUNC
is only the first of many problems you'll encounter.
If you need to build a binary on a newer machine that will run on an older one, see this document.
There used to be "apgcc: A GCC wrapper to make portable binaries" that made this easy (it's referenced from above), but it appears to be gone ;-(
The easiest option is to build on an old machine (I used to build on RedHat 6.2, and the resulting binary ran everywhere). You don't have to actually run RH-6.2 on a physical machine, just bring it up in a VM.
The other relatively easy option is to build in a chroot
, again using tools and libraries from an old distribution (e.g. RH-6.2).
回答2:
As APGCC does not seem available anymore (except perhaps here and here). These glibc headers seem to currently be the most convenient way to generate portable Linux binaries from a C code by including one of the older header files.
回答3:
Cross-compiling to an older linux can be very difficult, and this is only one of many problems you will encounter.
That said, the ABI compatibility problem can be solved by adding -Wl,-fno-jump-tables
.
来源:https://stackoverflow.com/questions/54532815/downgrade-libc6-version