Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid STT_GNU_IFUNC symbols in your binary?

Tags:

linux

gcc

abi

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.

like image 522
samwise Avatar asked Jan 12 '12 20:01

samwise


2 Answers

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).

like image 152
Employed Russian Avatar answered Sep 20 '22 22:09

Employed Russian


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.

like image 1
JSchmitty Avatar answered Sep 22 '22 22:09

JSchmitty