LLVM-2.5 running GHCi

First I can load, say, Array.hs in ghci.
When running 'main' I get the error that LLVMSystem.so cannot be found.
No LLVM*.so file on my machine, cannot be found in a Suse package.
Building .so file manually using gcc as in ./make-so.sh.

Then I get a problem with pthread.so not being a shared object file
but a script.
However, we do not need pthread anyway,
thus removing it from ~/.ghc/i386-linux-6.10.4/package.conf solves that problem.
This is a known issue:
   http://hackage.haskell.org/trac/ghc/ticket/2615#comment:16

In GHC-6.12.3 you must also run
   ghc-pkg recache --user
  after removing pthread from ~/.ghc/i386-linux-6.12.3/package.conf.d/llvm-*.conf

Now when running 'main' I get the error,
that something about CurrentEngine cannot be found.
It means, we must also include /usr/lib/llvm/LLVM*.o files.
But in what order?
Seems there is no working order,
but the one given by
   llvm-config --libs
is close to what we need.
Problem: GHCi cannot cope with weak symbol _ZTIN4llvm12X86SubtargetE ("V" in nm)

This is a known issue due to
  http://hackage.haskell.org/trac/ghc/ticket/3333#comment:3

I have used gcc to build a monolithic libLLVM.so
containing all libLLVM*.a and libLLVM*.o files of /usr/lib/llvm/.
Then I reduced the occurrences of LLVM in package.conf
in the extraLibraries field to "LLVM"
and the ldOptions to -lLLVM.


Now I can call LLVM in GHCi - but only until I do :reload.
After reload the next attempt to play something will let GHCi quit with:

ghci: JITEmitter.cpp:110: <unnamed>::JITResolver::JITResolver(llvm::JIT&): Assertion `TheJITResolver == 0 && "Multiple JIT resolvers?"' failed.

Maybe this can be handled in LLVM-2.6
where the JIT must be initialized explicitly.


LLVM-2.6:

If I do as described above,
then when linking the Array example
I get errors for undefined symbols like
/usr/local/lib/libLLVM.so: undefined reference to `AutoGeneratedSwitch_emit_dash_llvm'
/usr/local/lib/libLLVM.so: undefined reference to `AutoGeneratedList_Wl_comma_'
...

These can be avoided by excluding libplugin_llvmc_Base.a
and libplugin_llvmc_Clang.a from the libLLVM.so conglomerate.
Then the example can be compiled but it aborts with PassRegistrar error as below.

I GHCi I get «unknown symbol `LLVMGetBitcodeModuleProviderInContext'»
when running 'main' in GHCi.
Additionally to -lLLVM for our custom libLLVM.so
I have to add -lLTO to ldOptions.
Then all symbols can be found.
However, when running LLVM.initializeNativeTarget
GHCi quits with
ghci: Pass.cpp:152: void<unnamed>::PassRegistrar::RegisterPass(const llvm::PassInfo&): Assertion `Inserted && "Pass registered multiple times!"' failed.
Also running LLVM.Target.X86.initializeTarget or Array.renderRamp
leads to this error.


LLVM-2.8

If I remove 'pthread' from Extra-Libraries and add 'LLVM-2.8rc' to Extra-GHCi-Libraries in
  $HOME/.ghc/i386-linux-6.12.3/package.conf.d/llvm-0.9.*-*.conf
 and run
  ghc-pkg recache --user
 I am even able to run 'llvm' example programs from within GHCi!

Sometimes it happends that llvm.buildinfo contains
ld-options: /usr/local/lib/libLLVM-2.8rc.so
and then llvm-0.9.*-*.conf contains this as well.
This leads to a failure of a LLVM runtime assertion:

llvm/examples$ DotProd.exe
Two passes with the same argument (-preverify) attempted to be registered!
UNREACHABLE executed!
Aborted

ld-options field must be empty!
