Hi,
The GNU C Compiler in freestanding mode requires the existence of the symbols memset, memcpy, memmove and memcmp. You *must* supply these functions yourself as described in the C standard. You cannot and should not (if you could) prevent the compiler from assuming these functions exist as the compiler uses them for important optimizations. Fortunately these functions are really easy to write. Note that if you are writing C++ you must export them with C linkage, for instance:
Code: Select all
extern "C" void* memcpy(void* dst, const void* src, size_t size)
{
for ( size_t i = 0; i < size; i++ )
((uint8_t*) dst)[i] = ((const uint8_t*) src)[i];
return dst;
}
Code: Select all
$ x86_64-elf-g++ -c kernel.c -o kernel.o -ffreestanding -mcmodel=large -mno-red-zone -Ofast -Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m64 -std=c++11 -mno-3dnow
$ x86_64-elf-g++ -T linker.ld -o kernel.lkr -Ofast -nostdlib kernel.o -lgcc -fno-use-linker-plugin
Please note that passing -nostdlib is the same as pasing both -nostartfiles and -nodefaultlibs. For that reason, you should simply only pass -nostdlib and delete all references to -nostartfiles and -nodefaultlibs where they are passed. Additionally, these options
make no sense when compiling, only when linking, so you should delete them from all gcc invocations containing -c. You also don't have to pass -m64 at any times when using the x86_64-* toolchain because -m64 is the default. Likewise, optimization options doesn't really make sense when you link the kernel and have no effect (or am I wrong there?). I'm not sure why you pass -fno-use-linker-plugin - it seems to work around a problem that shouldn't exist. I recommend that you don't pass an option unless you have researched whether you need to pass it in the first place - there is a *lot* of misinformation out there.