In the barebones tutorial, it states:
Code: Select all
i686-elf-gcc -T linker.ld -o myos.bin -ffreestanding -O2 -nostdlib boot.o kernel.o -lgcc
Note: Some tutorials suggest linking with i686-elf-ld rather than the compiler, however this prevents the compiler from performing various tasks during linking. Note: that we are linking against libgcc, which implements various runtime routines that your cross-compiler depends on. Leaving it out will give you problems in the future. If you did not build and install libgcc as part of your cross-compiler, you should go back now and build a cross-compiler with libgcc. The compiler depends on this library and will use it regardless of whether you provide it or not.
If I also supply the -nostdlib option without -lgcc as Clang / LLVM uses compiler-rt (replacement for libgcc), I don’t get any warnings and can compile the code just fine. If I leave both out, then it cant find any of the libgcc/crt.*/start files which makes sense since were freestanding. If I pass the path of the LIBGCC file to LD it finds LIBGCC just fine as well but seems like a hack as -lgcc should work just fine without it but it doesn’t.
Whats the best way to get this to work, right now i'm using Clang to compile and then using cross-compiled LD to link with no LIBGCC added and it works just fine but feels like a hack. Also, is adding -lgcc (libgcc) necessary when the underlaying libs are there?