C++ and void __cxa_pure_virtual()

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
bluecode

C++ and void __cxa_pure_virtual()

Post by bluecode »

hi,

I'm going to write my kernel in C++.
For now I'm testing which functions I need in order to support the basic C++ functionality (no exception handling, but perhaps rtti). Today I came across the function __cxa_pure_virtual() which gcc needs if have at least one pure virtual method in a class. But I can't figure out, when it is actually called. I wrote two small classes for testing purpose with one pure virtual function, but __cxa_pure_virtual() doesn't get called at all. Is it true that it's only called if the pure virtual function call fails? I'm not really sure. The only implementation I've came across is http://cvs.blackfin.uclinux.org/cgi-bin ... sroot=gcc3. Is this implementation complete?
thx

cu bluecode
AR

Re:C++ and void __cxa_pure_virtual()

Post by AR »

IIRC, __cxa_pure_virtual() is a crash function, it is only meant to be called when the linker made a broken binary, in user apps it prints to stderr and aborts, in the kernel you'll just want to print an error and panic.

(The actual mechanism is if a pure virtual function is called without being overridden in the class that inherited it)
bluecode

Re:C++ and void __cxa_pure_virtual()

Post by bluecode »

thanks for the very fast reply!
But how can a class that did not override the pure virtual function actually be instantiated? Is this possible?
AR

Re:C++ and void __cxa_pure_virtual()

Post by AR »

no it shouldn't be possible, you might be able to hack it with multiple header definitions of the same class though.
fraserjgordon

Re:C++ and void __cxa_pure_virtual()

Post by fraserjgordon »

Just wondering, do you know of a comprehensive reference of what functions G++ requires for each C++ feature (pure virtual, multiple inheritance, RTTI, exceptions, etc)? I was thinking about adding some of these to my kernel, but I don't know what G++ needs.

Thanks in advance,
Fraser
AR

Re:C++ and void __cxa_pure_virtual()

Post by AR »

You can use: /usr/src/gcc-4.0.1/libstdc++-v3/libsupc++
The header files declare most of this stuff
vurt

Re:C++ and void __cxa_pure_virtual()

Post by vurt »

bluecode wrote: thanks for the very fast reply!
But how can a class that did not override the pure virtual function actually be instantiated? Is this possible?
Here's one way: You have a parent class with pure virtual functions and a child class with the implementations. If during construction of a child object, the constructor takes .. oh.. for example ... 10 minutes to complete construction (maybe you have a sleep(600) in there).. and another thread uses the child object which is busy constructing, then the pure virtual methods on the parent object will actually be called.

The child object is actually an instantiated parent object until it's finished constructing - with pure virtual methods and everything else. Only once it's constructor returns, is it marked as an instantiated child class and only then can the implemented methods be used.
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:C++ and void __cxa_pure_virtual()

Post by nick8325 »

Fraser Gordon wrote: Just wondering, do you know of a comprehensive reference of what functions G++ requires for each C++ feature (pure virtual, multiple inheritance, RTTI, exceptions, etc)? I was thinking about adding some of these to my kernel, but I don't know what G++ needs.
http://www.codesourcery.com/cxx-abi/abi.html is the official IA-64 ABI. Apparently G++ follows that.
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:C++ and void __cxa_pure_virtual()

Post by nick8325 »

nick8325 wrote: http://www.codesourcery.com/cxx-abi/abi.html is the official IA-64 ABI. Apparently G++ follows that.
I forgot to mention: much of that is done by the compiler. Searching for __cxa on that page should tell you most of the functions the compiler might need (though I've never seen most of them before...some of them are only called in quite weird circumstances).
Post Reply