Building binutils for Linux with PE output format

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
mutex
Member
Member
Posts: 131
Joined: Sat Jul 07, 2007 7:49 pm

Building binutils for Linux with PE output format

Post by mutex »

Hi,

Is it possible/(anyone had luck) to build binutils for i386 plattform outputing PE format on a Linux/BSD/MacOS ELF plattform?

The output format should not have any ties to what plattform it runs on, but i cant find where to enable it in the Makefiles..

LD in mingw and cygwin of course outputs PE, but is that a patched version of LD that adds this or is PE a part of LD ?

The background is;

I moved from a PC to a MAC laptop and want my mac to be able to output PE files as well as ELF.. I installed mac ports and have gcc and binutils working fine, but i miss PE output.

Really need it because my kernel needs kernel+modules in a supported format, and for now only PE loading is complete in my kernel. Elf still have some coding todo before it can load both formats.

Using grub and multiboot loading to load image + modules.. My kernel detects the image formats and load them accordingly into memory and fixes up relocs etc.

best regards
Thomas
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Building binutils for Linux with PE output format

Post by Firestryke31 »

IIRC you can configure a build of GCC with a target of MinGW. I've done this (or something very close) before under Linux, and it should work on Mac as well. It's a bit complicated to explain, but basically I just followed the cross-compiler wiki tutorial and substituted i686-pc-mingw instead of i686-pc-elf or whatever.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
mutex
Member
Member
Posts: 131
Joined: Sat Jul 07, 2007 7:49 pm

Re: Building binutils for Linux with PE output format

Post by mutex »

Hi,

Thanks for you replies. For sure i have searched the wiki for building LD and more specific outputting PE but could not find any specific.

Could not find anything usefull on binutils docs online either.

Im pretty familiar with building a binutils+gcc cross, but building with mingw would need some additional sources (mingw) wouldn´t it?

If it was as easy as setting TARGET before configuring and compiling that would be nice, but are you sure this works?

But hey, i will give it a shot.. Will post back any results :)
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Building binutils for Linux with PE output format

Post by gerryg400 »

This wiki article http://wiki.osdev.org/OS_Specific_Toolchain has more information than any I have ever found on the 'net. it seems this part of binutils is not well documented. You can create your own target with a bit of experimentation.

However, it would be easier to make an ELF loader (read 60 page doc and write 10 lines of c code) than to create a new binutils target (no documents, horrible scripts, unknown dependancies, difficult verification) etc. I've done both these things. The ELF loader took an evening. My first port of binutils took more than a week.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Building binutils for Linux with PE output format

Post by Owen »

mutex wrote:I moved from a PC to a MAC laptop and want my mac to be able to output PE files as well as ELF.. I installed mac ports and have gcc and binutils working fine, but i miss PE output.
You are aware that Macs don't use ELF?

(Otherwise people have answered your question: Pick an appropriate target)
User avatar
mutex
Member
Member
Posts: 131
Joined: Sat Jul 07, 2007 7:49 pm

Re: Building binutils for Linux with PE output format

Post by mutex »

Does not really matter in this case.

The only thing i want is ld to be able to output PE format..
User avatar
mutex
Member
Member
Posts: 131
Joined: Sat Jul 07, 2007 7:49 pm

Re: Building binutils for Linux with PE output format

Post by mutex »

I have tried to compile various versions of binutils now, but different errors on compilation. Googling the error codes shows alot of people have same issues on Mac. Problems mostly due to issues with the gcc toolchain on MacOSX.

I found one other thing though;

Code: Select all

port install i386-mingw32-gcc
:D :D :D

That solved the whole deal.. They had ALOT of other "ports" for other architectures aswell...

http://www.macports.org/ports.php?by=name&substr=gcc
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Building binutils for Linux with PE output format

Post by gerryg400 »

I have tried to compile various versions of binutils now, but different errors on compilation. Googling the error codes shows alot of people have same issues on Mac. Problems mostly due to issues with the gcc toolchain on MacOSX.
I never had any problem building binutils on macosx. What problems do you have ?
If a trainstation is where trains stop, what is a workstation ?
User avatar
mutex
Member
Member
Posts: 131
Joined: Sat Jul 07, 2007 7:49 pm

Re: Building binutils for Linux with PE output format

Post by mutex »

Hi,

The problems was different;

2.20.1 complained about missing stat64_s struct or something and there was serveral warnings treated as errors when using "deprecated features".
2.19 complained that compiler was not able to produce executable files. I checked ld/cc/gcc/cpp but could not find anything. Found a few articles on the web mentioning the same.
2.14 same as 2.14

etc.. probably issues that could be easily resolved, but i was not in the mood for using hours on getting it to work. Not familiar enough with MacOSX yet.. :)

It might be that the xcode i have installed are missing something. Im not sure, but i did a full install.

Ports install of gcc worked well. Could proably use that toolchain to compile binutils, but found that it was in ports already so i used that.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Building binutils for Linux with PE output format

Post by gerryg400 »

mutex wrote:Hi,

The problems was different;

2.20.1 complained about missing stat64_s struct or something and there was serveral warnings treated as errors when using "deprecated features".
2.19 complained that compiler was not able to produce executable files. I checked ld/cc/gcc/cpp but could not find anything. Found a few articles on the web mentioning the same.
2.14 same as 2.14

etc.. probably issues that could be easily resolved, but i was not in the mood for using hours on getting it to work. Not familiar enough with MacOSX yet.. :)

It might be that the xcode i have installed are missing something. Im not sure, but i did a full install.

Ports install of gcc worked well. Could proably use that toolchain to compile binutils, but found that it was in ports already so i used that.
2.20.1 does build. I think that you'll find that the 'warning: ‘stat64’ is deprecated ' is only a warning, not an error. If you add

Code: Select all

--disable-werror
to the configure command line, it should work.

By the way, the 'config.guess' in old versions of binutils fails on recent versions of MacOSX so configure does not run. I guess that's what's happening with version 2.14
If a trainstation is where trains stop, what is a workstation ?
Post Reply