Still trying to build unregisterised for FreeBSD/amd64

Gregory Wright gwright at comcast.net
Thu Mar 8 11:25:39 EST 2007


Hi,

I have made some progress in compiling ghc-6.6 unregisterised for  
freebsd/amd64,
but I am stuck again.

To get the build on the host (freebsd/i386) to go through, I had to  
fix up Linker.c so
that it would build.   (Linker.c seems to define at least one utility  
function required
by the rts, markRootPtrTable.)  The instruction on the wiki to,  
"Don't worry if the build falls
over in the RTS, we don't need the RTS yet," seems incorrect for  
ghc-6.6 at least.
If the build fails in the rts, trying to proceed further just leads  
to more errors.

I fixed up Linker.c by replacing the calls to mmap (which will need  
fixing up anyway
on FreeBSD/amd64) with MAP_FAILED and copying the definitions of four  
relocation
types for X86_64 from machine/elf.h on the target into  
do_Elf_Rela_relocations. (The
build on the host complained that R_X86_64_64, R_X86_64_PC32,   
R_X86_64_32
and R_X86_64_32S were undefined.)

With this change, the build on the host was able to complete.   
Collecting the .hc files
works too, but the Makefile is out of date and references a few files  
that no longer
exist.  With a little hand editing, this is fixed and I have what I  
believe is a good set
of .hc files.

Over on the target, I unpack the fresh ghc-6.6-src.tar.bz2 and drop  
the .hc files on top
of it.  On FreeBSD, gmp is usually installed by the ports system in / 
usr/local/lib,
so I preface invocations of configure in distrib/hc-build by

CFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib"

so that the installed gmp is picked up in the configuration.  I also  
edit mk/bootstrap.mk
to add -L/usr/local/lib to HC_LD_BOOT_OPTS, and also add

-lHSregex-compat -lHSregex-posix -lHSregex-base

to HC_BOOT_LIBS.  The directories to find the regex libraries also  
get added to
HC_BOOT_LD_OPTS (-L$(FPTOOLS_TOP_ABS)/libraries/regex-*).

I also have to delete cabal-setup from the SUBDIRS in libraries/Cabal/ 
Makefile.
Otherwise the build fails complaining that there is no rule to make  
Cabal-setup.o.

I also have to change libraries/base/Makefile to not try to build  
Prim.hs.  It seems
that when booting from .hc files, PrimopWrappers.hs does not in fact  
depend
on Prim.hs; instead, PrimopWrappers.hs is not really used since we have
PrimopWrappers.hc copied over from the host.  (Without this change  
the Makefile
tries to invoke the yet unbuilt genprimopcode program to build Prim.hs.)

With these changes, distrib/hc-build is ready to roll.  It chugs  
along happily until
it tries to build Linker.c (which I have copied over from the host,  
so it has
the changes that I made there) and then ghc-inplace segfaults:

../compiler/ghc-inplace -optc-O -optc-Wall -optc-W -optc-Wstrict- 
prototypes -optc-Wmissing-prototypes -optc-Wmissing-declarations - 
optc-Winline -optc-Waggregate-return -optc-Wbad-function-cast -optc- 
I../includes -optc-I. -optc-Iparallel -optc-DCOMPILING_RTS -optc- 
fomit-frame-pointer -optc-fno-strict-aliasing -H16m -O -optc-O2 - 
static -I. -#include HCIncludes.h -fvia-C -dcmm-lint     -c Linker.c - 
o Linker.o
Segmentation fault (core dumped)
gmake: *** [Linker.o] Error 139
gmake: Leaving directory `/tmp/ghc-6.6/rts'


I noticed that a year and a half ago when Wilhelm Kloke was porting  
ghc-6.4.1 to
freebsd/amd64 he remarked that Linker.c had to be deleted.  If I  
delete it
from the target, the build just fails earlier, when genapply is being  
built, because
of missing symbols:

------------------------------------------------------------------------
== gmake all -wr;
in /tmp/ghc-6.6/utils/genapply
------------------------------------------------------------------------
gcc -x c GenApply.hc -o GenApply.o -c -O  -fomit-frame-pointer -fno- 
asynchronous-unwind-tables -fno-unit-at-a-time -fno-builtin -DNO_REGS  
-DUSE_MINIINTERPRETER  -D__GLASGOW_HASKELL__=606  -O -I/tmp/ghc-6.6/ 
includes -I/tmp/ghc-6.6/libraries/base/include -I/tmp/ghc-6.6/ 
libraries/unix/include -I/tmp/ghc-6.6/libraries/parsec/include  -I/ 
tmp/ghc-6.6/libraries/readline/include    -I.  `echo  | sed 's/^$/- 
DSTOLEN_X86_REGS=4/'`
gcc -o genapply  -fomit-frame-pointer -fno-asynchronous-unwind-tables  
-fno-unit-at-a-time -fno-builtin -DNO_REGS -DUSE_MINIINTERPRETER  - 
D__GLASGOW_HASKELL__=606  -O -I/tmp/ghc-6.6/includes -I/tmp/ghc-6.6/ 
libraries/base/include -I/tmp/ghc-6.6/libraries/unix/include -I/tmp/ 
ghc-6.6/libraries/parsec/include  -I/tmp/ghc-6.6/libraries/readline/ 
include    -L/tmp/ghc-6.6/rts  -L/tmp/ghc-6.6/libraries/base -L/tmp/ 
ghc-6.6/libraries/base/cbits -L/tmp/ghc-6.6/libraries/haskell98 -L/ 
tmp/ghc-6.6/libraries/parsec -L/tmp/ghc-6.6/libraries/regex-base -L/ 
tmp/ghc-6.6/libraries/regex-compat -L/tmp/ghc-6.6/libraries/regex- 
posix -L/tmp/ghc-6.6/libraries/Cabal -L/usr/local/lib -L/tmp/ghc-6.6/ 
libraries/template-haskell -L/tmp/ghc-6.6/libraries/readline -L/tmp/ 
ghc-6.6/libraries/unix -L/tmp/ghc-6.6/libraries/unix/cbits -u  
"GHCziBase_Izh_static_info" -u "GHCziBase_Czh_static_info" -u  
"GHCziFloat_Fzh_static_info" -u "GHCziFloat_Dzh_static_info" -u  
"GHCziPtr_Ptr_static_info" -u "GHCziWord_Wzh_static_info" -u  
"GHCziInt_I8zh_static_info" -u "GHCziInt_I16zh_static_info" -u  
"GHCziInt_I32zh_static_info" -u "GHCziInt_I64zh_static_info" -u  
"GHCziWord_W8zh_static_info" -u "GHCziWord_W16zh_static_info" -u  
"GHCziWord_W32zh_static_info" -u "GHCziWord_W64zh_static_info" -u  
"GHCziStable_StablePtr_static_info" -u "GHCziBase_Izh_con_info" -u  
"GHCziBase_Czh_con_info" -u "GHCziFloat_Fzh_con_info" -u  
"GHCziFloat_Dzh_con_info" -u "GHCziPtr_Ptr_con_info" -u  
"GHCziStable_StablePtr_con_info" -u "GHCziBase_False_closure" -u  
"GHCziBase_True_closure" -u "GHCziPack_unpackCString_closure" -u  
"GHCziIOBase_stackOverflow_closure" -u  
"GHCziIOBase_heapOverflow_closure" -u  
"GHCziIOBase_NonTermination_closure" -u  
"GHCziIOBase_BlockedOnDeadMVar_closure" -u  
"GHCziIOBase_Deadlock_closure" -u  
"GHCziWeak_runFinalizzerBatch_closure" -u "__stginit_Prelude"  
GenApply.o     -lHSreadline -lHStemplate-haskell -lHSunix - 
lHSunix_cbits -lHSCabal -lHSregex-compat -lHSregex-posix -lHSregex- 
base -lHShaskell98 -lHSrts -lHSbase -lHSbase_cbits -lHSparsec -lgmp -lm
/tmp/ghc-6.6/rts/libHSrts.a(GC.o)(.text+0x779): In function  
`GarbageCollect':
: undefined reference to `markRootPtrTable'
/tmp/ghc-6.6/libraries/base/libHSbase.a(Stable.o)(.text+0x360): In  
function `sxz_ret':
: undefined reference to `hs_free_stable_ptr'
/tmp/ghc-6.6/libraries/base/libHSbase.a(Typeable.o)(.text+0x2b85): In  
function `s4SA_ret':
: undefined reference to `hs_free_stable_ptr'
/tmp/ghc-6.6/libraries/base/libHSbase.a(Conc.o)(.text+0x3f7b): In  
function `base_GHCziConc_par_entry':
: undefined reference to `newSpark'
gmake[1]: *** [genapply] Error 1
gmake: *** [all] Error 1
gmake: Leaving directory `/tmp/ghc-6.6/utils'



I am wondering what to try next.  Could ghc-inplace on the target be  
crashing because
of differences in say, ptr sizes on the host versus the target?    
Could I fool the host build into
using 64 bit pointers by replacing explicit pointers with "long long"  
integers?   Or should
I try building a set of .hc files on a 64 bit linux host and use  
those to bootstrap the freebsd/amd64
target?

Any help would be appreciated.  Especially useful would be any  
comments on which parts
of the instructions can be trusted and which may be bitrotted and  
needing revision.

Best Wishes,
Greg



More information about the Glasgow-haskell-users mailing list