如何使用-fPIC重新编译GHC?

时间:2017-12-26 12:48:29

标签: haskell shared-libraries dockerfile ghc

简介:我实际上正在尝试构建一个用Haskell编写的与C兼容的共享库(可以在不知道它的情况下使用C代码在Haskell中编写),但我想要所有Haskell依赖项静态链接,现在我只能动态链接所有依赖项(包括" base"和" ghc-prim"包。这个实验提供了here

我尝试通过编写Dockerfile来解决这个问题,我从头开始构建GHC 8.2.2,将{em> mk / build.mk 文件替换为this contents(我刚才有点我在this one)等不同的堆栈溢出问题中看到了同样的情况,但是当我尝试与--make -static -shared -fPIC链接时,我遇到了很多关于链接" ghc-prim"的相似错误。最后一个:

/usr/bin/ld.gold: error: /ghc-8.2.2-fpic/lib/ghc-8.2.2/ghc-prim-0.5.1.1/libHSghc-prim-0.5.1.1.a(Classes.o): requires dynamic R_X86_64_PC32 reloc against 'stg_ap_0_fast' which may overflow at runtime; recompile with -fPIC

我应该用-fPIC构建GHC并将我的库与静态Haskell依赖关系链接起来?

Dockerfile来自debian:stretch,这里引用最后一个最重要的部分:

# ... apt-get update ... installing build-essential and other stuff ...

# see https://stackoverflow.com/a/28131655/774228
# for info about customizations in 'build.mk'
COPY my-build.mk /my-build.mk

RUN mkdir /compile && cd /compile \
    && wget https://downloads.haskell.org/~ghc/8.2.2/ghc-8.2.2-src.tar.xz \
    && tar -xvf ghc-8.2.2-src.tar.xz \
    && rm ghc-8.2.2-src.tar.xz \
    && cd ghc-8.2.2/ \
    && ./configure --prefix=/ghc-8.2.2-fpic --disable-library-profiling --enable-shared \
    && cp /my-build.mk mk/build.mk \
    && make install \
    && cd /usr/local/bin \
    && ls /ghc-8.2.2-fpic/bin/ | xargs -I{} ln -s /ghc-8.2.2-fpic/bin/{}

这是整个my-build.mk文件:

SRC_HC_OPTS          = -H64m -O
EXTRA_HC_OPTS        = -fPIC
SRC_CC_OPTS          = -fPIC -O
GhcStage1HcOpts      = -fasm -O0
GhcStage2HcOpts      = -fasm -O0
GhcLibHcOpts         = -fasm -O2
GhcLibWays           = v dyn
DYNAMIC_GHC_PROGRAMS = YES
DYNAMIC_BY_DEFAULT   = NO
SplitObjs            = NO
HADDOCK_DOCS         = NO
BUILD_DOCBOOK_HTML   = NO
BUILD_DOCBOOK_PS     = NO
BUILD_DOCBOOK_PDF    = NO
V                    = 1
LATEX_DOCS           = NO
HSCOLOUR_SRCS        = NO
BeConservative       = YES

0 个答案:

没有答案