build error on FreeBSD

PHO pho at
Wed Mar 13 17:03:13 CET 2013

From: Kazu Yamamoto (山本和彦) <kazu at>
Subject: build error on FreeBSD
Date: Tue, 12 Mar 2013 12:03:20 +0900 (JST)

> When I build GHC head on FreeBSD, I got the following error. Is newSpark
> missing on FreeBSD?
> "inplace/bin/ghc-stage1" -fPIC -dynamic  -H32m -O    -package-name ghc-prim- -hide-all-packages -i -ilibraries/ghc-prim/. -ilibraries/ghc-prim/dist-install/build -ilibraries/ghc-prim/dist-install/build/autogen -Ilibraries/ghc-prim/dist-install/build -Ilibraries/ghc-prim/dist-install/build/autogen -Ilibraries/ghc-prim/.    -optP-include -optPlibraries/ghc-prim/dist-install/build/autogen/cabal_macros.h -package rts-1.0  -package-name ghc-prim -XHaskell98 -XCPP -XMagicHash -XForeignFunctionInterface -XUnliftedFFITypes -XUnboxedTuples -XEmptyDataDecls -XNoImplicitPrelude -O2  -no-user-package-db -rtsopts       -odir libraries/ghc-prim/dist-install/build -hidir libraries/ghc-prim/dist-install/build -stubdir libraries/ghc-prim/dist-install/build -hisuf dyn_hi -osuf  dyn_o -hcsuf dyn_hc  libraries/ghc-prim/dist-install/build/GHC/Classes.dyn_o libraries/ghc-prim/dist-install/build/GHC/CString.dyn_o libraries/ghc-prim/dist-install/build/GHC/Debug.dyn_o libraries/ghc-prim/dist-install/build/GHC/Magic.dyn_o libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.dyn_o libraries/ghc-prim/dist-install/build/GHC/IntWord64.dyn_o libraries/ghc-prim/dist-install/build/GHC/Tuple.dyn_o libraries/ghc-prim/dist-install/build/GHC/Types.dyn_o   libraries/ghc-prim/dist-install/build/cbits/debug.dyn_o libraries/ghc-prim/dist-install/build/cbits/longlong.dyn_o libraries/ghc-prim/dist-install/build/cbits/popcnt.dyn_o libraries/ghc-prim/dist-install/build/cbits/word2float.dyn_o    -shared -dynamic -dynload deploy   -no-auto-link-packages -o libraries/ghc-prim/dist-install/build/
> Warning: -rtsopts and -with-rtsopts have no effect with -shared.
>     Call hs_init_ghc() from your main() function to set these options.
> /usr/local/bin/ld: libraries/ghc-prim/dist-install/build/GHC/PrimopWrappers.dyn_o: relocation R_X86_64_PC32 against undefined symbol `newSpark' can not be used when making a shared object; recompile with -fPIC
> /usr/local/bin/ld: final link failed: Bad value
> collect2: error: ld returned 1 exit status
> gmake[1]: *** [libraries/ghc-prim/dist-install/build/] Error 1
> gmake: *** [all] Error 2

The same error occurs on NetBSD/amd64. PrimopWrappers.dyn_o has a
direct reference to newSpark but since it resides in the rts, not
ghc-prim, such references must be redirected through PLT. The problem
is that every *.dyn_o, not only PrimopWrappers.dyn_o, is compiled
without -fPIC for OSes other than Windows, Darwin and Linux.

I have no idea why -fPIC isn't enabled for all OSes in the first
place, but the attached patch works at least for me.

 - PHO -               
OpenPGP public key: 1024D/1A86EF72
Fpr: 5F3E 5B5F 535C CE27 8254  4D1A 14E7 9CA7 1A86 EF72

More information about the ghc-devs mailing list