__cxa_deangle在使用devtoolset-4 gcc-5.2的rhel6(centos6)上失败
__cxa_demangle fails on rhel6 (centos6) with devtoolset-4 gcc-5.2
我尝试了一个最小的测试用例。这个案例通过了devtoolset-4(gcc-5.2)中的rhel-7,但在rhel-6中失败了。状态-2表示"mangled_name不是C++ABI mangling规则下的有效名称。"https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a01696.html
如果我想在RHEL-6上使用gcc-5.2,这是我做错了吗?还是我必须以某种方式解决这个错误?如果是,有什么建议吗?到目前为止,我最好的想法是将损坏名称中的"IJ"正则化为"II",然后再将其赋给__cxa_demangle()。如果这可能是相对可靠的,我可以接受它
#include <iostream>
#include <string>
#include <tuple>
#include <typeinfo>
#include <cxxabi.h>
#define DUMP(x) std::cout << #x << " is " << x << std::endl
template<typename T>
void print_type(T t)
{
int status;
auto name = typeid(t).name();
DUMP(name);
auto thing2 = abi::__cxa_demangle(name, 0, 0, &status);
if(status == 0)
{
DUMP(thing2);
}
else
{
std::cout << typeid(t).name() << " failed to demanglen";
DUMP(status);
}
}
typedef std::tuple<foo_t, foo_t> b_t;
int main(int argc, char **argv)
{
std::tuple<bool, bool> t;
print_type(t);
}
Centos-6输出
name is St5tupleIJbbEE
St5tupleIJbbEE failed to demangle
status is -2
Centos-7输出
name is St5tupleIJbbEE
thing2 is std::tuple<bool, bool>
带有devtoolset-3(gcc-4.9)的Centos-6输出
name is St5tupleIIbbEE
thing2 is std::tuple<bool, bool>
std::string typestring(typeid(T).name());
auto pos = typestring.find("IJ");
if(pos != std::string::npos)
{
// gcc-5.2 uses IJ in typestring where
// gcc-4.9 used II - this fugly hack makes
// cxa_demangle work on centos/rhel-6 with gcc-5.2
// eg std::tuple<bool, bool>
typestring[pos + 1] = 'I';
}
rv = abi::__cxa_demangle(typestring.c_str(), 0, 0, &status);
相关文章:
- 在RHEL6上使用最近的gcc进行编译:如何分发软件?
- _GLIBCXX_USE_CXX11_ABI RHEL6 和 RHEL7 上禁用了吗?
- Centos6 gcc6:编译简单的 c++11 测试文件时,默认的 ABI 不拾取
- 如何在 RHEL6.4 中安装 GCC 7.1.0
- 我是否应该期望在 CentOS6 和 CentOS7 之间处理 fstream 异常时有不同的行为
- __cxa_deangle在使用devtoolset-4 gcc-5.2的rhel6(centos6)上失败
- 如何使用 GCC 4.4.6 从 RHEL6 机器编译 RHEL5 兼容的共享库
- RHEL6 上的自定义 GCC 4.8.2 给出了 std::shared_ptr 的构建错误
- 在RHEL6上构建GCC 5.2
- C++将用RHEL4 32位编写的应用程序迁移到RHEL6 64位