linking 32/64 bit

Programming, for all ages and all languages.
Post Reply
Krox
Posts: 23
Joined: Fri Mar 21, 2008 3:52 am
Location: Germany

linking 32/64 bit

Post by Krox »

I'm currently developing a 64 bit Kernel with some success, but as complexity grows, more and more stuff have to be done before switching to longmode (especially memory management). So I decided to write some 32Bit C-Code instead of assembler for this, but now the linker complains, that it cannot link 32 with 64 bit code. There was no problem when writing 32/64bit assembler, even mixed in a single file, so I think it should be possible with C, too. Any solution is welcome, my guess is some kind of converting the 32bit object-file to 64bit, but I dont know how to do that. Any Ideas?

(System: Linux, GCC, ld... standard...)
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: linking 32/64 bit

Post by ru2aqare »

Krox wrote:I'm currently developing a 64 bit Kernel with some success, but as complexity grows, more and more stuff have to be done before switching to longmode (especially memory management). So I decided to write some 32Bit C-Code instead of assembler for this, but now the linker complains, that it cannot link 32 with 64 bit code. There was no problem when writing 32/64bit assembler, even mixed in a single file, so I think it should be possible with C, too. Any solution is welcome, my guess is some kind of converting the 32bit object-file to 64bit, but I dont know how to do that. Any Ideas?

(System: Linux, GCC, ld... standard...)

Hi,

I am currently developing a custom linker for exactly the same need - I need to mix 16, 32 and 64 bit code for my bootloader. I am on Windows, and the MS linker chokes on 16-bit object files that contain relocations, and also does not support cross-linking (ie. mixing 32-bit and 64-bit object files). I have tried the DJGPP toolchain as well to no avail (but that was a year ago, I dont know if support for mixing object files has changed since).
Krox
Posts: 23
Joined: Fri Mar 21, 2008 3:52 am
Location: Germany

Re: linking 32/64 bit

Post by Krox »

actually, I have found a solution at least for 32/64 bit. The following will convert 32 bit elf files (and possibly others) to 64 bit.

Code: Select all

objcopy -O elf64-x86-64 filename.obj
But anyway, a custom linker sounds interesting, cause there are several other little shortcomings with ld I think. Is there anything to show/test already?
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: linking 32/64 bit

Post by ru2aqare »

Krox wrote:actually, I have found a solution at least for 32/64 bit. The following will convert 32 bit elf files (and possibly others) to 64 bit.

Code: Select all

objcopy -O elf64-x86-64 filename.obj
But anyway, a custom linker sounds interesting, cause there are several other little shortcomings with ld I think. Is there anything to show/test already?
Actually, in a few days the linker should be ready. Far from complete, but functional. However in its current form it only handles COFF object files (and outputs PE images). I'm interested in making it work with ELF files as well, but that is not on top of the list.
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: linking 32/64 bit

Post by ru2aqare »

I have a working copy of the linker available (it is still a "beta version" though). If anyone wants to try it out, please feel free to. A more detailed description and howto is included in the archive file.

Summary:
- links COFF object files containing 16-bit, 32-bit and 64-bit code together
- generates PE/COFF image file, to get the raw image use some helper program (one such program is included in the archive).
- you need a .NET environment to run the linker
- intended at those who develop on Windows and use the MS toolchain

(edit) See files in later post.
Last edited by ru2aqare on Sat Jul 19, 2008 2:06 pm, edited 1 time in total.
Kieran
Member
Member
Posts: 54
Joined: Mon Apr 11, 2005 11:00 pm

Re: linking 32/64 bit

Post by Kieran »

Any chance of the source code?
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: linking 32/64 bit

Post by ru2aqare »

Kieran wrote:Any chance of the source code?
Here is the source (and also the updated binaries). The source is GPL - do whatever you want with it (some feedback would be nice though). You will need the helper dll if you want to compile it.
Attachments
Linker_b563.part03.rar
Source + binaries.
(13.83 KiB) Downloaded 142 times
Linker_b563.part02.rar
Source + binaries.
(63.48 KiB) Downloaded 106 times
Linker_b563.part01.rar
Source + binaries.
(63.48 KiB) Downloaded 103 times
Post Reply