了解GCC 5的_GLIBCXX_USE_CXX11_ABI或新的ABI [英] Understanding GCC 5's _GLIBCXX_USE_CXX11_ABI or the new ABI

查看:5274
本文介绍了了解GCC 5的_GLIBCXX_USE_CXX11_ABI或新的ABI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

https://gcc.gnu.org/onlinedocs/libstdc++/manual/ using_dual_abi.html



我在gcc 5上使用std :: string遇到了crash / valgrind问题。上面的链接提示, ABI启动GCC 5.x. libstd ++的新的默认ABI是C ++ 11/14 ...这与旧的ABI不兼容。有一种方法使用define选择较旧的ABI。



我试图理解ABI之间的区别是什么,没有找到细节。我需要帮助理解:


  1. std :: string需要修复什么样的问题才能与新的ABI兼容?

  2. 在获得_GLIBCXX_USE_CXX11_ABI的工作中有什么提示吗?
  3. li>

有关我遇到的问题的更多详细信息( https://github.com/YasserAsmi/jvar/issues/21 )该项目在GCC 4.8和Clang工作得很好。使用GCC,同样的代码拒绝运行:

  x_misc(33112,0x7fff728c2000)malloc:***错误对象0x7fd639c034cc:指针正在释放未分配
***在malloc_error_break中设置断点以调试
中止陷阱:6

这里是一个部分Valgrind输出:
== 33027 ==无效读取大小1
== 33027 ==在0x1006F78BA:_platform_memmove $ VARIANT $ Nehalem(在/ usr /lib/system/libsystem_platform.dylib)
== 33027 == by 0x100009388:jvar :: Variant :: toStringabi:cxx11 const(in bin / ex_misc)
== 33027 == by 0x1000023A7:bugreport ()(in bin / ex_misc)
== 33027 == by 0x1000133B8:main(in bin / ex_misc)



项目使用std :: string和有一些自定义内存管理。它正在做一些非典型但有效的操作使用放置新的构造函数等。我想更好地了解什么样的代码受API和如何解决它 - 一个开始的地方。

解决方案


  1. 旧的 std :: string 与C ++ 11,因为该标准禁止写时复制实现。没有办法创建一个兼容的 std :: string ,而不会破坏ABI,所以他们这样做,返回到不兼容版本的ABI兼容性。


  2. 确认您程式中的所有翻译单元都使用相同的值 _GLIBCXX_USE_CXX11_ABI ,你应该没问题。如果你把它们混合在翻译单位,你一定会有问题。如果在不将 string 彼此沟通的不同翻译单元中具有不同的define值,则您可能 >



https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

I ran into crashing/valgrind issues with using std::string on GCC 5. The above link hints that there is a change in the ABI starting GCC 5.x. The new default ABI for libstd++ is C++11/14... which is not compatible with the older ABI. There is a way to select the older ABI using a define.

I am trying to understand what is the difference between the ABIs and haven't found details. I'd like help understanding:

  1. What kind of issues with std::string need to be fixed to be compatible with the new ABI? Are they copy-on-write related?
  2. Will those changes break it for older ABI?
  3. Any tips in getting _GLIBCXX_USE_CXX11_ABI to work?

More details on the issue I ran into (https://github.com/YasserAsmi/jvar/issues/21) The project worked fine in GCC 4.8 and Clang. With GCC, the same code refuses to run:

x_misc(33112,0x7fff728c2000) malloc: *** error for object 0x7fd639c034cc:    pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

And here is a partial Valgrind output: ==33027== Invalid read of size 1 ==33027== at 0x1006F78BA: _platform_memmove$VARIANT$Nehalem (in /usr/lib/system/libsystem_platform.dylib) ==33027== by 0x100009388: jvar::Variant::toStringabi:cxx11 const (in bin/ex_misc) ==33027== by 0x1000023A7: bugreport() (in bin/ex_misc) ==33027== by 0x1000133B8: main (in bin/ex_misc)

The project uses std::string and has some custom memory management. It is doing some non-typical but valid operations using placement new constructors etc. I am trying to understand better what kind of code is effected by the API and how to fix it--a place to start.

解决方案

  1. The old std::string was not compliant with C++11 because that standard prohibits a copy-on-write implementation. There was no way to create a compliant std::string without breaking ABI, so they did so with a way to return to the non-compliant version for ABI compatibility.

  2. Yes.

  3. Make sure all the translation units in your program use the same value of _GLIBCXX_USE_CXX11_ABI and you should be fine. If you mix them up across translation units you will definitely have problems. You might be ok if you have different values of the define in different translation units that don't communicate strings to each other.

这篇关于了解GCC 5的_GLIBCXX_USE_CXX11_ABI或新的ABI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆