mixed linker?

Programming, for all ages and all languages.
Post Reply
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

mixed linker?

Post by nekros »

Would this even be possible to write a linker that could link 64bit and 32bit object files?

elf32 + elf64 -> elf32 || elf64
Working On:Bootloader, RWFS Image Program
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: mixed linker?

Post 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.
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

Re: mixed linker?

Post by nekros »

what linker do you use? ld won't do that...
Working On:Bootloader, RWFS Image Program
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: mixed linker?

Post 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).
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

Re: mixed linker?

Post 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...
Working On:Bootloader, RWFS Image Program
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: mixed linker?

Post 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.
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

Re: mixed linker?

Post by nekros »

My kernel is not higher half, so it works for me. :wink: I'm gonna attempt it right now so let's see what happens.
Working On:Bootloader, RWFS Image Program
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
User avatar
nekros
Member
Member
Posts: 391
Joined: Wed Mar 05, 2008 9:10 pm
Contact:

Re: mixed linker?

Post by nekros »

Oh, this is just converting a 64 bit to 32 bit elf not mixed linking?
Working On:Bootloader, RWFS Image Program
Leviathan: http://leviathanv.googlecode.com
Kernel:Working on Design Doc
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: mixed linker?

Post 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.
Post Reply