midonator1305 wrote:
nullplan wrote:
So I'll have to look into the gas and gcc source codes. Fun times ahead!
Haha I wish you luck
Here’s an update I decided to compile everything again. I set some environmental variables this time to make sure I didn’t miss something. I set “CFLAGS” “CXXFLAGS” “CFLAGS_FOR_TARGET” and “CXXFLAGS_FOR_TARGET” all to “-mcmodel=large -mno-red-zone”. Large is a bit excessive as you said but it should link to any address. I built binutils, gcc but without doing “make all-target-libstdc++-v3”, newlib and finally rebuilt gcc but included the “libstdc++-v3” and it built
Man, if you could hear me swearing right now. These source codes are like staring into the sun. Now I need my eyes looked at...
Anyway, I suppose the CXXFLAGS_FOR_TARGET thing was what you were missing. Explains why the linker only complained about libsupc++, and not libgcc.
midonator1305 wrote:
It finally links but than it calls abort. It attempted to call malloc in the global construction which was not initiated yet. After fixing that it ran correctly. I read on the wiki (
https://wiki.osdev.org/Libsupcxx#Full_C.2B.2B_Runtime_Support_Using_libgcc_And_libsupc.2B.2B)
Quote:
To make use of exception handling, you also have to tell libsupc++ where the .eh_frame section begins. Before you throw any exception: <verbatim>__register_frame(address_of_eh_frames); </verbatim>.
Quote:
You also need to provide __register_frame() (or call the function provided by libgcc with the start of your .eh_frame section), void *__dso_handle;, __cxa_atexit() and __cxa_finalize (again see C++).
I do not understand this. It says call the function provided by libgcc. Which one is it? I’ve seen __register_frame_info and __register_frame so are those it? also what are those last 3 functions?
__register_frame() is indeed provided by libgcc. It wraps __register_frame_info(). If you have a working malloc(), I would just call __register_frame().
Those last three implement the atexit() stuff for a dynamic shared object. What they're supposed to do is: __dso_handle is supposed to point to the most recently loaded module, __cxa_atexit() is supposed to register exit handlers for a DSO, and __cxa_finalize() is supposed to run all the exit handlers for a certain DSO.
Since a kernel never exits, and you probably don't have loadable modules right at the start, I would just declare __dso_handle, set it to 0 and never touch it again. __cxa_atexit() is a dummy function that always returns success, in order not to disturb the C++ compiler, and __cxa_finalize() panics, because you should never get there.