Page 1 of 1

linking 32/64 bit

Posted: Fri Jun 27, 2008 7:53 am
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...)

Re: linking 32/64 bit

Posted: Fri Jul 11, 2008 5:20 am
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).

Re: linking 32/64 bit

Posted: Fri Jul 11, 2008 12:35 pm
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?

Re: linking 32/64 bit

Posted: Sat Jul 12, 2008 3:51 am
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.

Re: linking 32/64 bit

Posted: Wed Jul 16, 2008 6:07 am
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.

Re: linking 32/64 bit

Posted: Wed Jul 16, 2008 10:16 am
by Kieran
Any chance of the source code?

Re: linking 32/64 bit

Posted: Sat Jul 19, 2008 4:28 pm
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.