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.
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'
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:
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.
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.
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.
Exception handling is included in free standing implementations.
The reason of this is that you possibly use
gcc to compile your code. If you compile with the option
-### you will notice it is missing the linker-option
-lstdc++ when it invokes the linker process . Compiling with
g++ will include that library, and thus the symbols defined in it.