Sunday, October 22, 2006

C++ in the kernel

Welcome again, it have been a long time since i wrote here, cuz my pc was damaged and etc... a long story.
Anyway, I wanna write a little about my adventure for enabling C++ in the kernel. C++ isn't like C, it needs some runtime support, for calling constructors and destructors of static and global objects, also for exceptions, RTTI, thus dynamic_cast (which is btw is like the 'as' operator in C#) , and new and delete. Just compiling C++ without giving support you will end up only having namespaces, classes and templates and other features I don't remember now.

You have 2 options either ignore those features, or integrate a standard C++ library in your kernel. Sure you won't create your own. You can use newlib, or libgcc along with libsupc++. You still have to support several functions for them, like malloc and free and abort etc. This won't call constructors for you. I found a trick but I don't know yet if it will work. To make GCC generate the _init function that does that, which is supposed to get called b4 main, and call it myself. I will try it after recompiling those libs to allow them to have weak pthread symbols so I don't have to implement pthreads now.