Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling ghc with -fPIC support

Tags:

People also ask

How do I run a GHC file?

Open a command window and navigate to the directory where you want to keep your Haskell source files. Run Haskell by typing ghci or ghci MyFile. hs. (The "i" in "GHCi" stands for "interactive", as opposed to compiling and producing an executable file.)

What does Haskell compile to?

The compiler (written in Haskell), translates Haskell to C, assembly, LLVM bitcode and other formats. The strategy it uses is described best here: Implementing lazy functional languages on stock hardware:the Spineless Tagless G-machine.

How do I run a Haskell file in Terminal?

If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt. Alternatively, if you are on Windows, you may choose WinGHCi in the Start menu. And you are presented with a prompt. The Haskell system now attentively awaits your input.

Is ghci an interpreter?

This library offers interfaces which mediate interactions between the ghci interactive shell and iserv , GHC's out-of-process interpreter backend.


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