[Haskell-cafe] Porting GHC to OSX86?

Reilly Hayes rfh at reillyhayes.com
Sat May 6 14:05:04 EDT 2006

You'll get a better response to this on the glasgow-haskell-users  
list.  I'm cross-posting my reply.

I'm brand new to hacking on GHC, but I've been working on this in my  
pitifully meagre spare time.  The actual expert is Wolfgang Thaller,  
but he doesn't seem to be around the lists lately.  I was able to  
generate hc files on a 386 linux box (actually on a Parallels virtual  
machine on my mac, as my linux boxen all run 64 bit linuces).    I'll  
share my findings so far:

1) STABLE does not have the appropriate code in the Mangler to deal  
with Darwin/86.  I've been playing with various versions of HEAD.

2) HEAD has gone through a major revision to the directory  
structure.  The documentation and some of the build processes have  
not caught up.  Simon Marlow sent a helpful e-mail to the ghc users  
list a few days ago that you should look at.

3) Building the .hc files mostly requires the appropriate settings in  
mk/build.mk on the Host (linux) machine.  I'll include my build.mk  
below.  There is a target in the top level makefile called hc-file- 
bundle (which needs to be invoked with the parameter  
ProjectNameShort=ghc in HEAD and Project=ghc in STABLE).  This target  
packages up the .hc files, but does not build them.  Some of the .hc  
files in utils (genapply, genprimopcode, & ghc-pkg) don't get built.   
I just cd to the directories and make them by hand (be sure to use  
the in-place compiler).  A GhcUtilsHcOpts variable in the make  
structure would be nice (in order to pass -keep-hc-files to ghc when  
building these on the host).

4) I have been working with Registerised hc files.  This may have  
been a mistake, as registerised code seems to present some unique  
challenges on Darwin/86.  See the items below for a discussion.

5) If I understand correctly (somebody with better knowledge please  
correct me), there is a register allocation conflict between ghc and  
relocatable code generated by gcc on the 386 (gcc flag -fPIC).  This  
limits ghc to producing static binaries.  The gcc in Xcode builds  
relocatable code by default and requires -static to build static  

I think this conflict is limited to code that goes through the  
Mangler (registerized code).

6) If I understand correctly, there is code in the RTS that cannot be  
built using the native code generator.  Which suggests that we're  
stuck with static binaries.  There is a ticket to fix this in HEAD.

7) Mac OS X really doesn't like static binaries.  In fact, in order  
to link a static binary, you have to go to opendarwin and download  
the Csu package to build crt0.o.  It's not included in any of the  
development tools.  Apple warns that static binaries are likely to  
fail to operate in O/S version changes.

Curently I'm fighting with the Makefiles to figure out how to get the  
-static flag stuffed into all of the invocations of gcc.  Some of the  
invocations in rts components don't seem to obey the normal variables  
used in the makefile structure.  I haven't had time to puzzle this  
out and won't for a few days.

mk/build.mk used to generate hc files:

GhcLibHcOpts = -O -fasm -keep-hc-files
GhcRtsHcOpts = -fasm -keep-hc-files
GhcWithInterpreter = NO
GhcStage1HcOpts = -O
GhcStage2HcOpts = -O -fasm -keep-hc-files
SRC_HC_OPTS += -H32m

-reilly hayes

On May 5, 2006, at 7:34 PM, Scott Weeks wrote:

> Hi All,
> Does anyone know if there's been any headway on this? If there's not
> a port available, where do I go about finding the hc files? Could I
> compile on a windows or linux x86 box and use the generated hc files
> to bootstrap?
> Cheers,
> Scott
> On 22/03/2006, at 7:09 AM, Deling Ren wrote:
>> Hi there,
>> Has anyone made any attempt to port GHC to Mac OS X on x86?
>> Wolfgang Thaller’s binary package runs over Rosetta but slow (not
>> surprising). It can not be used to compile a native version either
>> (I got some errors related to machine registers).
>> I tried to do a bootstrap but can't find the ".HC" files mentioned
>> in the manual. They don't seem to be on the download page of GHC.
>> Any ideas?
>> Thanks.
>> Deling_______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

Reilly Hayes
rfh at reillyhayes.com

More information about the Haskell-Cafe mailing list