64-bit flat binary [SOLVED]

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

64-bit flat binary [SOLVED]

Post 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.
Last edited by 01000101 on Thu Jul 31, 2008 2:46 pm, edited 1 time in total.
User avatar
karloathian
Posts: 22
Joined: Fri Mar 28, 2008 12:09 am

Re: 64-bit flat binary

Post 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
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: 64-bit flat binary

Post 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.
froggey
Member
Member
Posts: 38
Joined: Tue Oct 17, 2006 10:21 pm
Location: Hampshire, UK

Re: 64-bit flat binary

Post 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")
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: 64-bit flat binary

Post by 01000101 »

nope it wasn't correct. Thanks for that, my kernel compiles and links fine now.
Post Reply