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

Linker error when building executable with cabal, but not with GHC --make #80

Closed tcsavage closed 10 years ago

tcsavage commented 10 years ago

I have a simple single-file package using llvm-general which refuses to build with cabal or cabal-dev, but works fine when compiled with ghc --make Main.

The linker error is as follows:

...
Loading package llvm-general-3.3.8.2 ... 

GHCi runtime linker: fatal error: I found a duplicate definition for symbol
   __x86.get_pc_thunk.bx
whilst processing object file
   /usr/local/lib/libLLVMInstrumentation.a
This could be caused by:
   * Loading two different object files which export the same symbol
   * Specifying the same object file twice on the GHCi command line
   * An incorrect `package.conf' entry, causing some object to be
     loaded twice.
GHCi cannot safely continue in this situation.  Exiting now.  Sorry.

Failed to install simplelang-0.1.0.0
cabal: Error: some packages failed to install:
simplelang-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1

The .cabal file is as follows:

name:                simplelang
version:             0.1.0.0        
build-type:          Simple
cabal-version:       >=1.8

executable simplelang
  main-is:             Main.hs
  build-depends:       base ==4.6.*,
                       bound ==0.9.*,
                       lens ==3.10.*,
                       transformers ==0.3.*,
                       containers ==0.5.*,
                       llvm-general ==3.3.*,
                       llvm-general-pure ==3.3.*,
                       prelude-extras ==0.3.*,
                       process ==1.1.*,
                       mtl ==2.1.*
  hs-source-dirs:      src

To make sure it wasn't an issue with my slightly non-standard LLVM installation, I tested it in a freshly configured VM but got the same results.

Operating system: Mint 16 GHC: 7.6.3 Cabal-install: 1.16.0.2 LLVM: 3.3 (compiled from source) llvm-general: 3.3.8.2

bscarlet commented 10 years ago

Sorry to take so long getting back to you...

There are many factors which differ between your configuration and mine, but the thing that stands out most to me is that your error message comes from ghci. Since you say you see the error when building, your build process is likely trying to use ghci as part of ghc's compilation process. The only time that happens that I know of is in the use of template haskell. While in principle it ought to work, I don't test much with ghci.

Can you tell me if you're actually trying to use llvm-general during TH pre-processing? More likely either I'm completely wrong about what's going on, or TH is bringing in llvm-general because it's so heavy-handed about including dependencies. In the last case, you might be able to circumvent the problem by factoring your TH better.

Please let me know. I'd prefer not to bump up the priority of getting llvm-general working in ghci if I don't have to - it's on the list, but there are other projects I'd like to get done first.

Another approach you could take is digging down into the ghc execution with -v and figuring out which two objects are providing definitions of the multiply defined symbol, tracking back where those symbols came from, and so trying to figure out why we're getting the error in the first place.

Yet another (given the multiply-defined issue) would be to build llvm to produce shared libraries (pass --enable-shared to llvm's configure), llvm-general to use them (pass -fshared-llvm to llvm-general's cabal configure), and see if using that different approach to pulling in llvm works (i.e. dodges the problem).

bscarlet commented 10 years ago

Have you had a chance to look at your problem again?

tcsavage commented 10 years ago

My apologies. I was indeed using template Haskell (for creating lenses) and after removing it from the module it compiled fine. Thanks.