使用 -fPIC 支持编译 ghc

发布于 2024-12-08 07:26:49 字数 1694 浏览 0 评论 0原文

我正在尝试在 Fedora 中安装带有 -fPIC 支持的 GHC。 我已经获取了源代码 tarball,因为似乎没有二进制文件具有此功能。

在 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

不幸的是,编译时我仍然收到 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

所以看来 GHC-prim 仍然没有使用 -FPIC 进行编译 我还告诉 cabal 使用 -fPIC 构建任何软件包并共享。

有人有什么想法吗?

编辑: 感谢 dcout,我已经取得了一些进展。但现在我认为 libffi 不是用 -fPIC 编译的。我已经为其编辑了 makefile(.in),但到目前为止,还没有成功。

新命令是:

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

其中 dllmain.c 和 Hs2lib.hs 均已使用 -fPIC 进行编译。 我得到的错误是:

/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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

双手揣兜 2024-12-15 07:26:49

看到此错误后,请执行以下操作:

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

注意我将 -fPIC 添加到失败的 ghc 命令中。

命令成功后,从 tmp 目录中继续编译,而不清除已编译的文件。它应该跳过它们并从结束的地方继续。

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.

阳光下慵懒的猫 2024-12-15 07:26:49

有一个 常见问题解答Haskell Stack 页面上有关此主题的条目

它基本上表示问题与环境相关,有时是不确定的。

该问题可能与在某些情况下使用强化标志有关,特别是与生成位置无关的可执行文件 (PIE) 相关的情况。

还有一个针对 Arch Linux 的解决建议:

在 Arch Linux 上,从 AUR 安装 ncurses5-compat-libs 软件包可以解决此问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文