1

I'm trying to run LLVM bitcode generated from Haskell source code instead of compiling the code to a native binary on macOS.

I have following file:

$ cat hello_world.hs
main =
  putStrLn "Hello world!"

And I'm using following steps to create the .bc file:

$ brew install stack
$ brew install llvm@6

$ stack ghc -- -keep-llvm-files hello_world.hs
$ clang -c -emit-llvm hello_world.ll -o hello_world.bc

When I now try to run it, I get following error:

$ lli hello_world.bc
'main' function not found in module.

When I set -fllvm to compile to a native binary via LLVM it all works, so it doesn't seem to be a problem with my LLVM setup. How can this be fixed?

adius
  • 13,685
  • 7
  • 45
  • 46
  • 1
    I think the LLVM code generated in this way assumes that the GHC runtime system (RTS) was properly initialized, providing the GC data structures, threads, and many primitive operations. Further, GHC LLVM function use a custom call convention `cc 10`, which differs from the standard C one. To actually run that LLVM code you have to provide the RTS, probably linking it in (I don't know how, exactly), and make a suitable call to your Haskell code. – chi May 27 '19 at 09:24

0 Answers0