Page 1 of 1
mixed linker?
Posted: Mon Apr 13, 2009 12:18 pm
by nekros
Would this even be possible to write a linker that could link 64bit and 32bit object files?
elf32 + elf64 -> elf32 || elf64
Re: mixed linker?
Posted: Mon Apr 13, 2009 1:36 pm
by JohnnyTheDon
Not sure... but I do link my elf64 object files into an elf32 for my multiboot bootloader. It hasn't given me any trouble.
Re: mixed linker?
Posted: Mon Apr 13, 2009 1:51 pm
by nekros
what linker do you use? ld won't do that...
Re: mixed linker?
Posted: Mon Apr 13, 2009 4:05 pm
by JohnnyTheDon
GNU ld. Works fine with a linker script.
Here's an excerpt from mine:
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:x86-64)
I can even put 32-bit assembly code in there (and 16-bit with some tweaks).
Re: mixed linker?
Posted: Mon Apr 13, 2009 5:10 pm
by nekros
Awesome, could this be used as a technique to do boot a kernel with grub? I might want to add this to add this to the wiki...
Re: mixed linker?
Posted: Mon Apr 13, 2009 5:19 pm
by JohnnyTheDon
I guess so. The one problem I can see is that everything has to be identity mapped. This isn't a problem for a bootloader, but a long mode kernel would usually be loaded in the higher half, and grub won't be about to do that (unless you have memory up to 0xFFFF800000000000). The only reason I bother with elf64 -> elf32 instead of elf32 -> elf32 in my bootloader is that 64-bit C code needs to be compiled to elf64.
Re: mixed linker?
Posted: Mon Apr 13, 2009 5:24 pm
by nekros
My kernel is not higher half, so it works for me.
I'm gonna attempt it right now so let's see what happens.
Re: mixed linker?
Posted: Mon Apr 13, 2009 6:25 pm
by nekros
Oh, this is just converting a 64 bit to 32 bit elf not mixed linking?
Re: mixed linker?
Posted: Mon Apr 13, 2009 8:10 pm
by JohnnyTheDon
I was linking a series of elf64 files into an elf32 using ld. No objcopy or anything like that. You might be able to link elf64 and elf32 files together by doing it in 3 stages: link the elf32s into one relocatable elf32 file, link the elf64s into one relocatable elf32 file, then link the two relocatable elf32s into another elf32.