GCC ABI 兼容性
据我所知,不可能链接使用不同版本的 GCC 应用程序二进制接口 (ABI) 的库。 GCC 的每个版本都有 ABI 更改吗?如果我使用 GCC 4.3.2,是否可以链接使用 4.3.1 构建的库?是否有某种矩阵列出了我可以组合 GCC 版本的所有方式?
As far as I've understood, it is not possible to link libraries that use different versions of GCC's Application Binary Interface (ABI). Are there ABI changes to every version of GCC? Is it possible to link a library built with 4.3.1 if I use, say, GCC 4.3.2? Is there a matrix of some sort that lists all the ways I can combine GCC versions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 gcc-3.4.0 开始,ABI 向前兼容。 IE 使用旧版本制作的库可以与新版本链接,并且它应该可以工作(反之则不能)。显然,可能存在错误,但文档中只提到了一个:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33678
Since gcc-3.4.0, the ABI is forward compatible. I.E. a library made using an older release can be linked with a newer one and it should work (the reverse doesn't). Obviously, there could be bugs, but there is only one mentionned in the documentation: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33678
官方 ABI 页面 指向 ABIcheck。这个工具可以做你想要的。
The official ABI page points to an ABIcheck. This tool may do, what you want.
呃,哎呀。
如何判断哪个 gcc 编译了给定的二进制文件?这是
来自 gcc-4.7.2-1-mingw32.README.txt 的死亡通知:
二进制不兼容通知!
GCC 4.7.0 中的 C 和 C++ ABI 发生了变化,这意味着通常您不能
将使用此版本的编译器编译的二进制文件链接在一起
GCC 4.7.0 之前的版本。特别是:
默认情况下启用选项 -mms-bitfields,这意味着位域布局
遵循 Microsoft 编译器的约定。
C++ 类成员函数现在遵循 __thiscall 调用约定。
编译器现在假设调用者弹出堆栈
指向聚合返回值的隐式参数。这影响
按值返回结构的函数,如复杂的数学类型。
Ugh, yikes.
How can you tell which gcc compiled a given binary? Here is the
death notice from gcc-4.7.2-1-mingw32.README.txt :
Binary incompatibility notice!
The C and C++ ABI changed in GCC 4.7.0, which means in general you can't
link together binaries compiled with this version of the compiler and
with versions before GCC 4.7.0. In particular:
The option -mms-bitfields is enabled by default, which means the bitfield layout
follows the convention of the Microsoft compiler.
C++ class-member functions now follow the __thiscall calling convention.
The compiler now assumes that the caller pops the stack for the
implicit arguments pointing to an aggregate return value. This affects
functions returning structs by value, like the complex math type.