I've implemented a microkernel in C++. All my programs are by now elf binaries that are loaded from the ramdisk. I'm compiling these userspace programs as explained in the following, but I've now come to the point where I need the global constructors called and well, this lead to further questions
At the moment I'm compiling all the userspace programs with my normal i686-elf-gcc, and I've built an API library with the follwing contents:
- libgcc and its headers, precompiled for my i686-elf-target
- newlib and its headers, also precompiled
- a copy of the kernels system call definition header
- some higher-level interface util to use the system calls easier in userspace
- my own "crt0.asm" that by now only calls main and exit
- the "glue" functions that newlib needs, like C version of exit and so on
So the outcome when compiling this is that I have libgcc, newlib and my libghostapi ready for linking with my userspace programs. Compiling a program then looks like this (my vfs as an example):
Code: Select all
// Compiling...
i686-elf-g++ -c -fno-exceptions -fno-rtti -o "src/VFS.o" "../src/VFS.cpp"
-I"/Applications/eclipse/workspace/GhostApps/GhostApp-VFS/src"
-I"/Applications/eclipse/workspace/GhostAPI/libgcc/include"
-I"/Applications/eclipse/workspace/GhostAPI/libnewlib/include"
-I"/Applications/eclipse/workspace/GhostAPI/src"
// Linking...
i686-elf-g++ -nostdlib -o "vfs.bin" ./src/VFS.o -lgcc -lc -lghostapi
-L"/Applications/eclipse/workspace/GhostAPI/libgcc"
-L"/Applications/eclipse/workspace/GhostAPI/libnewlib"
-L"/Applications/eclipse/workspace/GhostAPI/bin"
My question is basically, how can I get my global constructors called? I've already tried finding out where GCC links the ctor section in its default linker script by using the verbose flag. I tried using "extern "C" crtbegin" and "extern "C" crtend" to get the linker symbols linked there and then call the constructors from my CRT0 before calling the main, but these symbols didn't work out.. How do I achieve this, or what is the recommended way? Should I write a crtbegin.asm that does the constructor calling and crtend.asm that does the destruction? Do I need a custom linker script, or do I need to build a completely new toolchain (as suggested in the wiki - also, whats the advantage)?
Thank you a lot in advance =)