OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 8:03 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: mixed linker?
PostPosted: Mon Apr 13, 2009 12:18 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 05, 2008 9:10 pm
Posts: 391
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


Top
 Profile  
 
 Post subject: Re: mixed linker?
PostPosted: Mon Apr 13, 2009 1:36 pm 
Offline
Member
Member

Joined: Sun Nov 09, 2008 2:55 am
Posts: 524
Location: Pennsylvania, USA
Not sure... but I do link my elf64 object files into an elf32 for my multiboot bootloader. It hasn't given me any trouble.


Top
 Profile  
 
 Post subject: Re: mixed linker?
PostPosted: Mon Apr 13, 2009 1:51 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 05, 2008 9:10 pm
Posts: 391
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


Top
 Profile  
 
 Post subject: Re: mixed linker?
PostPosted: Mon Apr 13, 2009 4:05 pm 
Offline
Member
Member

Joined: Sun Nov 09, 2008 2:55 am
Posts: 524
Location: Pennsylvania, USA
GNU ld. Works fine with a linker script.

Here's an excerpt from mine:

Quote:
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).


Top
 Profile  
 
 Post subject: Re: mixed linker?
PostPosted: Mon Apr 13, 2009 5:10 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 05, 2008 9:10 pm
Posts: 391
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


Top
 Profile  
 
 Post subject: Re: mixed linker?
PostPosted: Mon Apr 13, 2009 5:19 pm 
Offline
Member
Member

Joined: Sun Nov 09, 2008 2:55 am
Posts: 524
Location: Pennsylvania, USA
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.


Top
 Profile  
 
 Post subject: Re: mixed linker?
PostPosted: Mon Apr 13, 2009 5:24 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 05, 2008 9:10 pm
Posts: 391
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


Top
 Profile  
 
 Post subject: Re: mixed linker?
PostPosted: Mon Apr 13, 2009 6:25 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 05, 2008 9:10 pm
Posts: 391
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


Top
 Profile  
 
 Post subject: Re: mixed linker?
PostPosted: Mon Apr 13, 2009 8:10 pm 
Offline
Member
Member

Joined: Sun Nov 09, 2008 2:55 am
Posts: 524
Location: Pennsylvania, USA
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 54 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group