HASKELL:尝试构建静态库,w/ llvm throws“可以创建动态重新定位”尽管使用了-fpic

发布于 2025-02-06 08:39:05 字数 1212 浏览 2 评论 0 原文

我正在尝试使用GHC生成静态库的LLVM比特码,遵循其他SO答案和指南在线,我到达了:

FILE = lib

compile:
    ghc -fllvm -keep-llvm-files -fforce-recomp -static -shared -flink-rts -fPIC $(FILE).hs
    llvm-as $(FILE).ll -o $(FILE).bc
-- lib.hs
module Lib where

add x y = x + y

但是运行此操作给出了:

$ ghc -fllvm -keep-llvm-files -fforce-recomp -static -shared -flink-rts -fPIC lib.hs

[1 of 1] Compiling Lib              ( lib.hs, lib.o )
You are using an unsupported version of LLVM!
Currently only 9 to 13 is supported. System LLVM version: 13.0.0
We will try though...
Linking a.out ...

ld.lld: error: cant create dynamic relocation R_X86_64_32S against symbol: 
stg_bh_upd_frame_info in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
>>> defined in /home/user/.ghcup/ghc/9.2.1/lib/ghc-9.2.1/rts/libHSrts.a(Updates.o)
>>> referenced by Base.o:(.text+0x3A) in archive /home/user/.ghcup/ghc/9.2.1/lib/ghc-9.2.1/base-4.16.0.0/libHSbase-4.16.0.0.a

我应该注意:使用 no-pie的GHC选项设置中启用文件

I'm trying to generate LLVM bitcode for a static library with GHC, following other SO answers and guides online, I've arrived at:

FILE = lib

compile:
    ghc -fllvm -keep-llvm-files -fforce-recomp -static -shared -flink-rts -fPIC $(FILE).hs
    llvm-as $(FILE).ll -o $(FILE).bc
-- lib.hs
module Lib where

add x y = x + y

However running this gives:

$ ghc -fllvm -keep-llvm-files -fforce-recomp -static -shared -flink-rts -fPIC lib.hs

[1 of 1] Compiling Lib              ( lib.hs, lib.o )
You are using an unsupported version of LLVM!
Currently only 9 to 13 is supported. System LLVM version: 13.0.0
We will try though...
Linking a.out ...

ld.lld: error: cant create dynamic relocation R_X86_64_32S against symbol: 
stg_bh_upd_frame_info in readonly segment; recompile object files with -fPIC or pass '-Wl,-z,notext' to allow text relocations in the output
>>> defined in /home/user/.ghcup/ghc/9.2.1/lib/ghc-9.2.1/rts/libHSrts.a(Updates.o)
>>> referenced by Base.o:(.text+0x3A) in archive /home/user/.ghcup/ghc/9.2.1/lib/ghc-9.2.1/base-4.16.0.0/libHSbase-4.16.0.0.a

I should note that the GHC option to use -no-pie is enabled in settings file

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文