Haskell LLVM绑定链接器错误

时间:2011-06-20 01:05:17

标签: haskell linker llvm

更新

我现在使用的是LLVM 2.9,在ghc 7.0.4上运行绑定llvm-0.9.1.2而我只是其中一个错误:

/home/jfmiller28/.cabal/lib/llvm-0.9.1.2/ghc-7.0.4/libHSllvm-0.9.1.2.a(Scalar.o): In function `sm03_info':
(.text+0x24d): undefined reference to `LLVMAddLoopIndexSplitPass'
collect2: ld returned 1 exit status

我为haskell LLVM绑定收到以下链接器错误:

Linking llvm ...
/home/jfmiller28/.cabal/lib/llvm-0.9.0.1/ghc-6.12.3/libHSllvm-0.9.0.1.a(Core.o): In function `scZD_info':
(.text+0xf589): undefined reference to `LLVMBuildFNeg'
/home/jfmiller28/.cabal/lib/llvm-0.9.0.1/ghc-6.12.3/libHSllvm-0.9.0.1.a(Core.o): In function `sdRn_info':
(.text+0x114c5): undefined reference to `LLVMAddDestination'
/home/jfmiller28/.cabal/lib/llvm-0.9.0.1/ghc-6.12.3/libHSllvm-0.9.0.1.a(Core.o): In function `sdSb_info':
(.text+0x11545): undefined reference to `LLVMAddGlobalInAddressSpace'
...
collect2: ld returned 1 exit status

ghc --make hello.hs

module Main where

import Data.Word

import LLVM.Core
import LLVM.ExecutionEngine

bldGreet :: CodeGenModule (Function (IO ()))
bldGreet = withStringNul "Hello, JIT!" (\greetz -> do
    puts <- newNamedFunction ExternalLinkage "puts" :: TFunction (Ptr Word8 -> IO Word32)
    func <- createFunction ExternalLinkage $ do
      tmp <- getElementPtr0 greetz (0::Word32, ())
      _ <- call puts tmp -- Throw away return value.
      ret ()
    return func)

main :: IO ()
main = do
    initializeNativeTarget
    greet <- simpleFunction bldGreet
    -- greet

    return ()

LLVM与apt-get一起安装到/ usr / lib / llvm。

2 个答案:

答案 0 :(得分:2)

原始问题的答案是我有一个太旧的LLVM版本。撰写本文时,您需要LLVM 2.8或更高版本。

下一个问题与llvm绑定中的过时行有关。这次的解决方案是从git存储库编译llvm绑定。如果我错了,请纠正我,但我需要更新的cabal install llvm公开的0.9.1.2版本。

请参阅https://github.com/bos/llvm/issues/2https://github.com/bos/llvm/pull/3

答案 1 :(得分:1)

也许这个补丁可以使用LLVM 2.9运行,并在ghc 7.0.4上运行绑定llvm-0.9.1.2

diff -rupN llvm-0.9.1.2/LLVM/FFI/Transforms/Scalar.hsc llvm-0.9.1.2-modified/LLVM/FFI/Transforms/Scalar.hsc
--- llvm-0.9.1.2/LLVM/FFI/Transforms/Scalar.hsc 2011-05-20 02:20:56.000000000 +0800
+++ llvm-0.9.1.2-modified/LLVM/FFI/Transforms/Scalar.hsc    2011-06-20 20:59:27.455828891 +0800
@@ -30,8 +30,6 @@ foreign import ccall unsafe "LLVMAddLICM
     :: PassManagerRef -> IO ()
 foreign import ccall unsafe "LLVMAddLoopDeletionPass" addLoopDeletionPass
     :: PassManagerRef -> IO ()
-foreign import ccall unsafe "LLVMAddLoopIndexSplitPass" addLoopIndexSplitPass
-    :: PassManagerRef -> IO ()
 foreign import ccall unsafe "LLVMAddLoopRotatePass" addLoopRotatePass
     :: PassManagerRef -> IO ()
 foreign import ccall unsafe "LLVMAddLoopUnrollPass" addLoopUnrollPass
diff -rupN llvm-0.9.1.2/llvm.cabal llvm-0.9.1.2-modified/llvm.cabal
--- llvm-0.9.1.2/llvm.cabal 2011-05-20 02:20:56.000000000 +0800
+++ llvm-0.9.1.2-modified/llvm.cabal    2011-06-20 21:03:29.846828930 +0800
@@ -125,7 +125,6 @@ library
       LLVM.Target.MSP430
       LLVM.Target.Mips
       LLVM.Target.Native
-      LLVM.Target.PIC16
       LLVM.Target.PowerPC
       LLVM.Target.Sparc
       LLVM.Target.SystemZ