What is __gxx_personality_v0 for?
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.
It's part of the exception handling. The gcc EH mechanism allows to mix various EH models, and a personality routine is invoked to determine if an exception match, what finalization to invoke, etc. This specific personality routine is for C++ exception handling (as opposed to, say, gcj/Java exception handling).