简体   繁体   English

使用-fPIC支持编译ghc

[英]Compiling ghc with -fPIC support

I'm trying to install GHC with -fPIC support in Fedora. 我正在尝试在Fedora中安装带有-fPIC支持的GHC。 I've grabbed a source tarball since it seems no binary one has this. 我已经抓住了一个源tarball,因为它似乎没有二进制文件。

In Build.mk i've changed the quick build type to 在Build.mk中,我已将快速构建类型更改为

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 不幸的是,在编译时我仍然得到ld错误

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. 所以似乎GHC-prim仍然没有用-FPIC编译我也告诉cabal用-fPIC和共享构建任何包。

Anyone have any ideas? 有人有想法么?

EDIT: Thanks to dcouts I've been able to make some progress. 编辑:感谢dcouts,我已经取得了一些进展。 But now i'm at the point where I thnk libffi isn't compiled with -fPIC. 但是现在我正处于我没有使用-fPIC编译libffi的时候。 I've edited the makefile(.in) for it but so far, no luck. 我为它编辑了makefile(.in),但到目前为止,没有运气。

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. 其中dllmain.c和Hs2lib.hs都使用-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 collect2:ld返回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. 注意我在失败的ghc命令中添加了-fPIC。

Once the command succeeds, continue the compilation from within the tmp directory without cleaning already compiled files. 命令成功后,从tmp目录中继续编译,而不清除已编译的文件。 It should skip them and continue where it ended. 它应该跳过它们并在它结束的地方继续。

There's an FAQ entry on this topic on the Haskell Stack page. 在Haskell Stack页面上有关于此主题的FAQ条目

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). 该问题可能与在某些情况下使用强化标志有关,特别是与生成与位置无关的可执行文件(PIE)有关的标志。

There's also a work around suggestion for Arch Linux: 还有一个关于Arch Linux的建议:

On Arch Linux, installing the ncurses5-compat-libs package from AUR resolves this issue. 在Arch Linux上,从AUR安装ncurses5-compat-libs软件包解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM