Page 1 of 1
64-bit flat binary [SOLVED]
Posted: Wed Jul 30, 2008 9:45 pm
by 01000101
is there any way to create 64-bit GCC compiled code into a link binary.
before, I was using
Code: Select all
gcc -m32 -ffreestanding -c "kernel.c" -o "kernel.o"
gcc -m32 -ffreestanding -c "file2.c" -o "file2.o"
ld -T link.ld -o kernel.bin kernel.o file2.o
but now that I am using long mode, is there a way for me to link files without having to use the elf format and just use a flat setup like before? basically, I just want to be able to launch from my bootloader which sets up long mode and jump directly to the beginning of the kernel binary and start executing instructions.
Re: 64-bit flat binary
Posted: Wed Jul 30, 2008 11:57 pm
by karloathian
Removing the -m32 option makes your compiler use your computer's set, IE: if you have a x86_64 compiler your compiler will compile your executable into the x86_64 format.
If you're compiling on a 32bit machine I think you have to use the -m64 option or a variation thereof
Re: 64-bit flat binary
Posted: Thu Jul 31, 2008 9:57 am
by 01000101
I know, what I'm saying is, that with the -m64 option, I cannot link the O files into a flat binary, it requires it be linked in 'elf' format which I don't want.
Re: 64-bit flat binary
Posted: Thu Jul 31, 2008 10:13 am
by froggey
Code: Select all
$ touch test.c
$ gcc -m64 test.c -c
$ ld -m elf_x86_64 --oformat binary test.o -o test
ld: warning: cannot find entry symbol _start; defaulting to 0000000000400000
Leaves me with a zero byte file "test".
Is your linker script correct?
OUTPUT_ARCH(i386:x86-64)
OUTPUT_FORMAT("binary")
Re: 64-bit flat binary
Posted: Thu Jul 31, 2008 2:46 pm
by 01000101
nope it wasn't correct. Thanks for that, my kernel compiles and links fine now.