bscarlet / llvm-general

Rich LLVM bindings for Haskell (with transfer of LLVM IR to and from C++, detailed compilation pass control, etc.)
http://hackage.haskell.org/package/llvm-general
132 stars 38 forks source link

JIT not linked correctly when built statically (as by default) #99

Closed peddie closed 10 years ago

peddie commented 10 years ago

Hi,

I'm having a problem with GHC 7.8.2 where code using the default (static) build of llvm-general versions 3.4.2.2 and 3.4.1.0 fails at runtime, the first time I try to use MCJIT in a program:

user error (JIT has not been linked in.)

This problem does not occur if I build llvm-general with --flags="shared-llvm". It also does not occur with the default build flags on GHC 7.6.3. My system is Debian i386, and I'm building against the llvm-3.4 packages from apt.

The easiest way to see this issue is by building and running Chapter 4 of Stephen Diehl's LLVM tutorial. To reproduce, clone that repository, install dependencies in a sandbox, then do

make chapter4
./chapter4

You should see the tutorial interpreter prompt ready>, at which point you can define some trivial function

def foo(a b) a * b;

and see the error. Blowing away the cabal sandbox and reinstalling llvm-general with shared flags fixes the problem.

sdiehl commented 10 years ago

Which version of llvm-general are you installing in the tutorial's sandbox? The tutorial currently is written against an explicit version of llvm-general == 3.4.1.0 in it's cabal file, which is a little behind Hackage and may not have some recent changes.

peddie commented 10 years ago

I used 3.4.1.0 originally, but I also experience the problem on the latest (3.4.2.2) llvm-general.

bscarlet commented 10 years ago

I haven't tackled supporting ghc 7.8 support yet - I'm still on 7.6.3. Thanks for the report.

bscarlet commented 10 years ago

Okay, I've finally had time to upgrade everything to work appropriately with ghc-7.8. Now I can take a look at this issue.

bscarlet commented 10 years ago

Looks like the new ghc is better at optimizing out unreferenced symbols. I'd been erroneously relying on just the presence of an FFI reference to the LinkInJIT/LinkInMCJIT symbols that pull in the rest of the JIT systems. Fix forthcoming.

victoredwardocallaghan commented 10 years ago

Just a note that I am also suffering from this problem.

victoredwardocallaghan commented 10 years ago

Oh and 'cabal install llvm-general -fshared-llvm --reinstall' is the workaround I am using.

bscarlet commented 10 years ago

Fixed (finally) in llvm-general-3.3.13.1 and llvm-general-3.4.4.1.