link 32bit .o with 64bit .o
Ian Lance Taylor
iant@google.com
Mon Apr 11 20:48:00 GMT 2011
GuoMinskey <minskey_guo@hotmail.com> writes:
> On x86 platform, is there any means to link 32 bit ELF output into 64 bit ?
> In Linux kernel, arch/x86/boot/compressed/head_64.S, starts from32-bit code and enables CPU to jump into 64-bit. So, that file is assembled into 64 bit ELF object with mixed 32/64 bit code.
> Now, I want to call a routine from somewhere in the 32bit code part of head_64.S. And I write the routine by C language, say test.c and compile it with "gcc -m32 -c -o test.o". How can I link mytest.o to head_64.o ? Or I have to use assembly language to rewritemy routine and embed it directly into head_64.S source code ?
On x86, 32-bit code can not call 64-bit code, nor vice-versa. The Linux
kernel uses some tricks to start up in 32-bit mode, convert to 64-bit
mode, and branch to 64-bit code as it converts. You can't do the same
tricks yourself; only the kernel can do them.
So, the answer is that you can link 32-bit and 64-bit code together
easily enough, using the linker's -b option as the kernel build does,
but you can't do anything useful with the result.
Ian
More information about the Gcc-help
mailing list