GCC 目标特异性和二进制兼容性
初始说明:该问题提到了 AIX,因为它是初始上下文,但问题实际上与 gcc 本身有关,很可能与平台无关。
AIX 应该向后二进制兼容:编译的 C 程序AIX 5.1 将按原样在 5.2、5.3、6.1 和 7.1 上运行。
根据我的理解,gcc 应该针对特定系统而构建(无论是当前系统还是交叉编译情况下的另一个系统)。因此,基于 AIX 6.1 构建的 gcc 面向 AIX 6.1,并且由于二进制兼容性而生成可在 6.1 和 7.1 上使用的二进制文件。
然而,基于 AIX 6.1 构建的 gcc 本身是一个 6.1 程序,因此它应该按原样在 7.1 上执行。当然,如果我在 7.1 上使用它编译一个程序,该程序可能会被链接或使用特定于 7.1 的标头,从而使生成的二进制文件需要 7.1。据我了解,我应该能够在 7.1 机器上运行基于 AIX 6.1 构建的 gcc,并生成可能不是最佳但完全有效的二进制文件,尽管它们需要 7.1 作为链接的副作用。
这看起来太像彩虹和独角兽在闪闪发光的天空中跳舞。我闻到了一股腥味,但对海湾合作委员会的内脏一无所知。请各位大佬赐教。
tl;dr:基于操作系统/平台版本 N 构建的 gcc 能否凭借平台二进制兼容性在版本 N+1 上运行和使用,以生成在版本 N+1 上运行的二进制文件?如果不是,什么机制可以阻止它?
Initial note: The question mentions AIX because it is the initial context but the question really pertains to gcc itself, most probably regardless of the platform.
AIX is supposed to be backwards binary compatible: a C program compiled on AIX 5.1 will run as is on 5.2, 5.3, 6.1 and 7.1.
In my understanding gcc should be built to target a specific system (whether the current one or another one in the case of cross-compiling). So, gcc built on AIX 6.1 targets AIX 6.1, and produces binaries usable on both 6.1 and 7.1 thanks to binary compatibility.
Yet gcc itself built on AIX 6.1 is a 6.1 program, so it should execute on 7.1 as is. Of course if I compile a program with it on 7.1, this program might get linked or use headers specific to 7.1, thus making the resulting binary requiring 7.1. So as far as I understand it, I should be able to run gcc built on AIX 6.1 onto a 7.1 machine, and produce maybe non-optimal yet perfectly valid binaries, although they would require 7.1 as a side effect of linking.
This looks too much like rainbows and unicorns dancing in glittery skies. I smell something fishy but lack any knowledge of gcc innards. Please mighty crowd, enlighten me.
tl;dr: Can gcc built on and targeting a version N of an OS/platform be run and used on version N+1 by virtue of platform binary compatibility to produce binaries running on version N+1? If not, what mechanism would prevent it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是启示:您的问题太笼统。为了回答这个问题,有人必须了解
,然后研究这个三维矩阵中的二进制兼容性。
阻止二进制兼容性的机制太多,并且与操作系统和编译器供应商破坏它的独创性直接相关。更常见和有记录的方法之一是官方弃用 API 调用、删除附带的兼容性库以及烧毁桥梁,例如从 a.out 到 ELF。
Here's enlightenment: your question is way too general. In order to answer it, someone would have to have knowledge of
and then research the binary compatibility in this three dimensional matrix.
Mechanisms preventing binary compatibility are too numerous and directly correlate to your OS and compiler vendor's ingenuity at breaking it. One of the more common and documented ways being official deprecation of API calls, removal of compatibility libraries shipped, and bridges being burnt, like going from a.out to ELF.