Haskell: trying to build static library w/ LLVM throws "can't create dynamic relocation" despite -fPIC being used

Viewed 205

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

0 Answers
Related