davmac314 wrote:
Techflash wrote:
Code:
cc1: error: code model kernel does not support PIC mode
Well that's the error (and it's due to the compilation command line having both -fpic and -mcmodel=kernel).
From
the wiki page that Octonobrass linked:
Quote:
This may require a workaround. First compile binutils as usual, then add the binaries to the PATH, and start to compile gcc. When compiling libgcc with -mcmodel=kernel, it will fail. Then patch the Makefile to disable PIC, repeat and continue:
You need to follow those instructions (or find some other way to prevent libgcc being built as PIC; you could try configuring with --disable-shared, if not doing that already). It's not clear to me whether you are currently building libgcc separately or as part of GCC as a whole, but It may be necessary to build it separately as per that page.
That's exactly what I did, I ran that command, then I ran the sed command to modify the makefile for libgcc, then I ran it again and it still gave the error.
UPDATE: Ran it again again with a clean install (backed up my current opt/cross folder) and started from scratch, building binutils according to "GCC Cross Compiler", and GCC according to "Building GCC for mcmodel=kernel", and now it compiled!
UPDATE 2: Welp, closer, now I have a bunch or relocation errors from kernel.c???
Code:
/opt/cross/lib/gcc/x86_64-elf/13.0.0/../../../../x86_64-elf/bin/ld: warning: tfos.elf has a LOAD segment with RWX permissions
kernel/kernel.o: in function `kernelMain':
/TFOS/kernel/kernel/kernel.c:33:(.text+0x84): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.8'
/TFOS/kernel/kernel/kernel.c:37:(.text+0xad): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.8'
/TFOS/kernel/kernel/kernel.c:38:(.text+0xbc): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.1'
/TFOS/kernel/kernel/kernel.c:55:(.text+0xf7): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.1'
/TFOS/kernel/kernel/kernel.c:55:(.text+0xfc): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.1'
/TFOS/kernel/kernel/kernel.c:57:(.text+0x11c): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.1'
/TFOS/kernel/kernel/kernel.c:95:(.text+0x205): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.8'
/TFOS/kernel/kernel/kernel.c:102:(.text+0x23e): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.8'
/TFOS/kernel/kernel/kernel.c:109:(.text+0x268): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.8'
/TFOS/kernel/kernel/kernel.c:118:(.text+0x29b): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.8'
/TFOS/kernel/kernel/kernel.c:122:(.text+0x2b6): additional relocation overflows omitted from the output
Basically every function call for some reason. I'm gonna try shifting some files around in the linking order and see what I can get.
UPDATE 3: Fixed it, now I'm just left with:
Code:
/opt/cross/lib/gcc/x86_64-elf/13.0.0/../../../../x86_64-elf/bin/ld: warning: tfos.elf has a LOAD segment with RWX permissions
And I have no idea how to fix it. I know what it means, it means the segment LOAD has Read Write and Execute permissions (which is bad because it leaves the kernel open to memory corruption), but I'm not really sure what to do about it. I'm guessing probably something in the linkerscript?