Compiling ghc with -fPIC support

99封情书 提交于 2019-12-03 20:37:04

问题


I'm trying to install GHC with -fPIC support in Fedora. I've grabbed a source tarball since it seems no binary one has this.

In Build.mk i've changed the quick build type to

ifeq "$(BuildFlavour)" "quick"

SRC_HC_OPTS        = -H64m -O0 -fasm -fPIC
GhcStage1HcOpts    = -O -fasm -fPIC
GhcStage2HcOpts    = -O0 -fasm -fPIC
GhcLibHcOpts       = -O -fasm -fPIC
SplitObjs          = NO
HADDOCK_DOCS       = NO
BUILD_DOCBOOK_HTML = NO
BUILD_DOCBOOK_PS   = NO
BUILD_DOCBOOK_PDF  = NO

endif

unfortunately, when compiling i still get the ld error

ghc -fglasgow-exts --make -shared -oHs2lib.a /tmp/Hs2lib924498/Hs2lib.hs dllmain.o -static -fno-warn-deprecated-flags -O2 -package ghc -package Hs2lib -i/home/phyx/Documents/Haskell/Hs2lib -optl-Wl,-s -funfolding-use-threshold=16 -optc-O3 -optc-ffast-math
Linking a.out ...
/usr/bin/ld: /tmp/Hs2lib924498/Hs2lib.o: relocation R_X86_64_32 against `ghczmprim_GHCziUnit_Z0T_closure' can not be used when making a shared object; recompile with -fPIC
/tmp/Hs2lib924498/Hs2lib.o: could not read symbols: Bad value

So it seems that GHC-prim still isn't compiled with -FPIC I've also told cabal to build any packages with -fPIC and shared.

Anyone have any ideas?

EDIT: Thanks to dcouts I've been able to make some progress. But now i'm at the point where I thnk libffi isn't compiled with -fPIC. I've edited the makefile(.in) for it but so far, no luck.

The new command is:

 ghc -fPIC -shared dllmain.o Hs2lib.o /usr/local/lib/ghc-7.0.3/libHSrts.a -o Hs2lib.so

where dllmain.c and Hs2lib.hs have both been compiled using -fPIC. The error I get is:

/usr/bin/ld: /usr/local/lib/ghc-7.0.3/libHSffi.a(closures.o): relocation R_X86_64_32 
against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/ghc-7.0.3/libHSffi.a: could not read symbols: Bad value

collect2: ld returned 1 exit status


回答1:


After you see this error, do the following:

cd /tmp/Hs2lib924498/
ghc -fglasgow-exts --make -shared -oHs2lib.a /tmp/Hs2lib924498/Hs2lib.hs dllmain.o -static -fno-warn-deprecated-flags -fPIC -O2 -package ghc -package Hs2lib -i/home/phyx/Documents/Haskell/Hs2lib -optl-Wl,-s -funfolding-use-threshold=16 -optc-O3 -optc-ffast-math

Note I added -fPIC to the failed ghc command.

Once the command succeeds, continue the compilation from within the tmp directory without cleaning already compiled files. It should skip them and continue where it ended.




回答2:


There's an FAQ entry on this topic on the Haskell Stack page.

It basically says the problem is environment related and sometimes non-deterministic.

The issue may be related to the use of hardening flags in some cases, specifically those related to producing position independent executables (PIE).

There's also a work around suggestion for Arch Linux:

On Arch Linux, installing the ncurses5-compat-libs package from AUR resolves this issue.



来源:https://stackoverflow.com/questions/7652799/compiling-ghc-with-fpic-support

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!