How to recompile GHC with -fPIC?

Introduction I'm actually trying to create a shared library written in Haskell that is compatible with C (can be used from C code without knowing that it is written in Haskell), but I want all Haskell dependencies to be statically linked, now I can dynamically bind all dependencies (for each package, including the base and ghc-prim packages. In this experiment, see here .

I tried to solve this by writing a Dockerfile where I build GHC 8.2.2 from scratch with the replaced mk / build.mk file with this content (I just did the same thing I saw in different problems like this ), but when I trying to establish a connection with --make -static -shared -fPIC , I get a lot of similar errors about combining "ghc-prim", an example of the latter:

 /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 

What should I do to build GHC with -fPIC and link my library with Haskell static dependencies?

Dockerfile deployed from debian:stretch , here is a quote from the last most important part of it:

 # ... 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/{} 

And here is the whole my-build.mk file:

 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 
+5
source share

Source: https://habr.com/ru/post/1274324/


All Articles