Page 1 of 1

Mixing 32 Bit and 64 Bit Assembler

Posted: Tue Jan 12, 2016 2:19 am
by nilres
Hey,

I'm working on porting my operating system to the x64 architecture. I'm following the articles in the wiki for switching to long mode. I use gas for assembly code. The cross compile tool chain is set-up correctly. I compile the 32 bit bootstrap with the following command:
x86_64-elf-as --32 -o CMakeFiles/myOS.elf.dir/src/arch/x64/pc/boot.S.o /home/nils/code/osdev/myOS/src/arch/x64/pc/boot.S
But then the linkage fails with the following error:
/usr/bin/cc -T ../././src//arch/x64/pc/layout.ld -N -ffreestanding -nostdlib CMakeFiles/schlemmiOS.elf.dir/src/arch/x64/pc/boot.S.o -o schlemmiOS.elf
/usr/bin/ld: i386 architecture of input file `CMakeFiles/schlemmiOS.elf.dir/src/arch/x64/pc/boot.S.o' is incompatible with i386:x86-64 output
Obviously the linker complains that it can't build 32bit code into my the binary... How can I fix this? And why is this a problem?

Thanks.

Re: Mixing 32 Bit and 64 Bit Assembler

Posted: Tue Jan 12, 2016 5:33 am
by Combuster
/usr/bin/cc (...)
/usr/bin/ld (...)
You might want to start with making sure you use the cross-compiler all the way
it can't build 32bit code into my the binary
Actually, it can't mix architectures. Instead you should tell the assembler that certain chunks are to be assembled in 32-bits (and some as 64-bits) using .code32 and .code64, instead of passing the 32-bit architecture flag on the command line

Re: Mixing 32 Bit and 64 Bit Assembler

Posted: Wed Jan 13, 2016 2:39 am
by nilres
Combuster wrote:You might want to start with making sure you use the cross-compiler all the way
Actually these are symlinks to the cross compiler. Ubuntu is doing some magic with the update-alternatives there. Probably not the greatest way for an operating system. But it's working for me and I haven't figured out a better way to say cmake which linker it should use.
Combuster wrote:Actually, it can't mix architectures. Instead you should tell the assembler that certain chunks are to be assembled in 32-bits (and some as 64-bits) using .code32 and .code64, instead of passing the 32-bit architecture flag on the command line
Ah ok. Is working now.Thanks.