【发布时间】:2016-07-09 15:02:02
【问题描述】:
我们最近因为GCC 5.1, libstdc++ and Dual ABI 收到了一份报告。看起来Clang is not aware of the GCC inline namespace changes,所以它基于一组命名空间或符号生成代码,而GCC使用另一组命名空间或符号。在链接时,由于缺少符号而出现问题。
如果我正确解析了Dual ABI 页面,看起来就像是在_GLIBCXX_USE_CXX11_ABI 和abi::cxx11 上进行了一些额外的困难。在 Red Hat 的博客 GCC5 and the C++11 ABI 和 The Case of GCC-5.1 and the Two C++ ABIs 上可以阅读更多内容。
以下来自 Ubuntu 15 机器。本机提供GCC 5.2.1。
$ cat test.cxx
#include <string>
std::string foo __attribute__ ((visibility ("default")));
std::string bar __attribute__ ((visibility ("default")));
$ g++ -g3 -O2 -shared test.cxx -o test.so
$ nm test.so | grep _Z3
...
0000201c B _Z3barB5cxx11
00002034 B _Z3fooB5cxx11
$ echo _Z3fooB5cxx11 _Z3barB5cxx11 | c++filt
foo[abi:cxx11] bar[abi:cxx11]
如何使用两种装饰生成带有符号的二进制文件(Red Hat 博客称之为“共存”)?
或者,我们有哪些选择?
我正在努力为用户实现“它只是工作”。我不在乎是否有两个具有两种不同行为的弱符号(std::string 缺少写时复制,而std::string[abi:cxx11] 提供写时复制)。或者,一个可以是另一个的别名。
Debian 在Debian Bug report logs: Bugs tagged libstdc++-cxx11 有大量类似的错误。他们的解决方案是在新的 ABI 下重建所有内容,但它没有处理混合/匹配编译器以 ABI 更改为模的极端情况。
在 Apple 世界中,我认为这接近于一个胖二进制文件。但我不确定在 Linux/GCC 世界中该做什么。最后,我们不控制发行版如何构建库,也不控制使用哪些编译器将应用程序与库链接。
【问题讨论】:
-
你的产品是什么?库还是程序?
-
@n.m. - 产品是魏岱的Crypto++。它是一个 C++ 库。它由 Debian 构建并作为发行版的一部分提供。