22

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

Phyx
  • 2,697
  • 1
  • 20
  • 35
  • which version of GHC do you try to compile? – fuz Oct 04 '11 at 19:08
  • Do you not need `-optc-fpic` or perhaps just `-fPIC` on the command line too? – Thomas M. DuBuisson Oct 04 '11 at 22:34
  • 1
    @Thomas `-fPIC` only works with the native backend - that's why `-fasm` is explicitly given. a `-optc` option has no effect if the C-backend is not in use. – fuz Oct 04 '11 at 22:42
  • You say you made some progress but don't mention how. I have same problem. Can you tell me what to do? – Kaiko Kaur Jan 17 '15 at 22:13
  • @KaikoKaur Sorry, I never got this to work and I am now back to mostly being a windows developer so I didn't really look much further into this. From what I remember, the progress was having to manually specify the Haskell RTS in the compile after adding -fPIC to the ghc makefile and recompiling. – Phyx Jan 27 '15 at 10:45

2 Answers2

1

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.

  • 1
    That alone unfortunately won't do it. It seems the version of the command i posted here lacked -fPIC, but that's already in the command. dllmain.c is also compiled with -fPIC. I've progressed somewhat since I posted this question, and I'm now up to the point where libFFI is the problem. I've been told that build.mk doesn't have an influence on it's compilation, so i'm trying to it's config file to support it, but so far no luck. – Phyx Dec 10 '11 at 10:00
  • What does the compiler say now? Can you post the new command and error message? –  Dec 11 '11 at 02:48
  • I can post it once i get back home in a few days – Phyx Dec 11 '11 at 18:53
  • Sorry, was out of the country for a while, I've updated the question with my progress so far. – Phyx Dec 23 '11 at 12:17
0

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.

Eduard Wirch
  • 9,785
  • 9
  • 61
  • 73