2

I want to run klee on the .bc file generated by compiling haskell file with ghc frontend and llvm backend.

I have following code in my haskell hello.hs file:

main = putStrLn "Hello World!"

I compile hello.hs with ghc using following command

ghc -fllvm -keep-llvm-files -force-recomp -hello.hs

which generate a hello.ll file along with other files. I then try to compile this .ll file into a .bc file.

llvm-as hello.ll -o hello.bc

The problem is when I try to run klee or try to run lli on the the .bc file I get following error

main function not found in module error

I am running ghc and llvm on docker. I have version 3.4 of llvm and version 7.6.3 of ghc.

user7235699
  • 431
  • 2
  • 13
  • Like many modern languages, definitions in the language do not translate to identical declarations in bitcode or object files. Read the .ll and see. – Thomas M. DuBuisson Oct 02 '17 at 05:29
  • try adding `module Main where` as the first line of your Haskell file. – ja. Oct 02 '17 at 08:04
  • @ja Adding module Main did not work – user7235699 Oct 02 '17 at 09:47
  • Most likely Haskell links the `main` function into your program when you run it normally. Find a way to either link it in manually or find a way to create your own custom main function. See also: similar problems people had with Rust: https://stackoverflow.com/a/45860092/598057. – Stanislav Pankevich Oct 02 '17 at 10:59
  • Also see this: https://stackoverflow.com/questions/9427535/main-function-not-found-in-module-when-using-llvm-bindings-with-haskell?rq=1 – Stanislav Pankevich Oct 02 '17 at 11:26
  • `ghc` complains `unrecognised flag: -force-recomp`. It should be replaced by `-fforce-recomp`. – palik Oct 02 '17 at 12:32

0 Answers0