__cxa_demangle在rhel6(centos6)上使用devtoolset-4时失败gcc-5.2
问题描述:
我在最小的测试用例上做了一个尝试。这个案例在devhelolset-4(gcc-5.2)上传递rhel-7,并在rhel-6下失败。状态-2表示“mangled_name不是C++ ABI调整规则下的有效名称”。 https://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a01696.html__cxa_demangle在rhel6(centos6)上使用devtoolset-4时失败gcc-5.2
我在做这一切都是错误的,或者这是一个错误,我将不得不四处工作,如果我想在RHEL-6上使用gcc-5.2?如果有,任何建议?到目前为止,我的最好想法是在将它改为__cxa_demangle()之前,将“IJ”重名为“II”。如果这可能相对可靠,我可以忍受它。
#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 demangle\n";
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>
的Centos-6输出与devtoolset-3(GCC-4.9)
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);
gcc 4和5之间没有ABI更改吗?我不是专家,但我记得我的同事在谈论它。 –