什么是__gxx_personality_v0? [英] What is __gxx_personality_v0 for?

查看:728
本文介绍了什么是__gxx_personality_v0?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是来自操作系统开发网站的二手问题,但它让我很好奇,因为我在任何地方找不到一个合适的解释。

This is a second-hand question from an OS development site, but it made me curious since I couldn't find a decent explanation anywhere.

当编译和使用gcc链接一个独立的C ++程序,有时会出现这样的链接器错误:

When compiling and linking a free-standing C++ program using gcc, sometimes a linker error like this occurs:

out/kernel.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'

这显然是因为这个符号是在libstdc ++ ,这在自由站立的环境中缺失。修复问题只需要在这个地方定义这个符号:

This is apparently because this symbol is defined in libstdc++, which is missing in a free-standing environment. Fixing the problem simply requires defining this symbol somewhere:

void *__gxx_personality_v0;

这是很好,但我不喜欢只是神奇地工作的东西...所以问题是,这个符号的目的是什么?

Which is nice, but I don't like things that just magically work... So the question is, what is the purpose of this symbol?

推荐答案

它用于堆栈释放表,在我对另一个问题的回答

It is used in the stack unwiding tables, which you can see for instance in the assembly output of my answer to another question. As mentioned on that answer, its use is defined by the Itanium C++ ABI, where it is called the Personality Routine.

通过将它定义为全局NULL void指针,它工作的原因可能是因为没有什么是抛出异常。

The reason it "works" by defining it as a global NULL void pointer is probably because nothing is throwing an exception. When something tries to throw an exception, then you will see it misbehave.

当然,如果没有什么是使用异常,你可以用禁用异常, -fno-exceptions (如果没有什么是使用RTTI,你也可以添加 -fno-rtti )。如果你使用它们,你必须(如已经提到的其他答案)链接到 g ++ 而不是 gcc 将为您添加 -lstdc ++

Of course, if nothing is using exceptions, you can disable them with -fno-exceptions (and if nothing is using RTTI, you can also add -fno-rtti). If you are using them, you have to (as other answers already noted) link with g++ instead of gcc, which will add -lstdc++ for you.

这篇关于什么是__gxx_personality_v0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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