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
C++ and void __cxa_pure_virtual()
Re:C++ and void __cxa_pure_virtual()
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)
(The actual mechanism is if a pure virtual function is called without being overridden in the class that inherited it)
Re:C++ and void __cxa_pure_virtual()
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?
But how can a class that did not override the pure virtual function actually be instantiated? Is this possible?
Re:C++ and void __cxa_pure_virtual()
no it shouldn't be possible, you might be able to hack it with multiple header definitions of the same class though.
Re:C++ and void __cxa_pure_virtual()
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
Thanks in advance,
Fraser
Re:C++ and void __cxa_pure_virtual()
You can use: /usr/src/gcc-4.0.1/libstdc++-v3/libsupc++
The header files declare most of this stuff
The header files declare most of this stuff
Re:C++ and void __cxa_pure_virtual()
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.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?
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.
Re:C++ and void __cxa_pure_virtual()
http://www.codesourcery.com/cxx-abi/abi.html is the official IA-64 ABI. Apparently G++ follows that.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.
Re:C++ and void __cxa_pure_virtual()
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).nick8325 wrote: http://www.codesourcery.com/cxx-abi/abi.html is the official IA-64 ABI. Apparently G++ follows that.