Linux 如何避免二进制文件中的 STT_GNU_IFUNC 符号?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8842194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to avoid STT_GNU_IFUNC symbols in your binary?
提问by samwise
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 questionresulted 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.
我需要部署到 Red Hat 4.1.2 机器(有 gcc 4.1.2)。我在 Ubuntu 11.10 上使用 GCC 4.6.1 进行开发。不幸的是,我的构建过程创建的一些二进制文件在 RedHat 机器上无法使用。原因似乎是 ABI 更改,根据另一个 Stackoverflow 问题,这是由于引入 STT_GNU_IFUNC 符号导致的。有没有办法防止导出任何此类符号,以便我的二进制文件可以使用旧的 ABI?我使用 nm 在我的二进制文件中查找任何“i”类型的符号,但没有找到。
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.
我问这个是因为我的其他一些二进制文件以及我构建的一些 3rd 方库(tbb、boost)没有使用新的 ABI,因此在 RedHat 机器上运行良好。
Hope that is clear. Thanks in advance.
希望这很清楚。提前致谢。
采纳答案by Employed Russian
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 firstof many problems you'll encounter.
通常,UNIX 系统支持向后二进制兼容性(在旧机器上构建的二进制文件继续在新机器上运行),但不支持反向兼容。您不能指望在新系统上构建的二进制文件在旧系统上运行。STT_GNU_IFUNC
这只是您会遇到的许多问题中的第一个。
If you need to build a binary on a newer machine that will run on an older one, see thisdocument.
如果您需要在较旧的机器上运行的较新机器上构建二进制文件,请参阅此文档。
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 ;-(
曾经有“apgcc:一个用于制作可移植二进制文件的 GCC 包装器”使这变得容易(从上面引用),但它似乎已经消失了;-(
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.
最简单的选择是在旧机器上构建(我曾经在 RedHat 6.2 上构建,生成的二进制文件随处可见)。您不必在物理机上实际运行 RH-6.2,只需在 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).
另一个相对简单的选择是构建一个chroot
,再次使用来自旧发行版(例如 RH-6.2)的工具和库。
回答by Adam Azarchs
Cross-compiling to an older linux can be very difficult, and this is only one of many problems you will encounter.
交叉编译到较旧的 linux 可能非常困难,这只是您会遇到的众多问题之一。
That said, the ABI compatibility problem can be solved by adding -Wl,-fno-jump-tables
.
也就是说,ABI 兼容性问题可以通过添加-Wl,-fno-jump-tables
.
回答by JSchmitty
As APGCCdoes not seem available anymore (except perhaps hereand here). These glibc headersseem to currently be the most convenient way to generate portable Linux binaries from a C code by including one of the older header files.
因为APGCC似乎不再可用(除了这里和这里)。这些glibc 头文件似乎是目前通过包含一个较旧的头文件从 C 代码生成可移植 Linux 二进制文件的最方便的方法。