I'm trying to use llvm with haskell and I'm getting the error "illegal hardware instruction"
Details:
I'm compiling a simple hello world program just to test it out:
Code:
module Main where
main :: IO ()
main = putStrLn "Hello World"
GHC version 7.10.1, llvm version 3.4.2 (older version because haskell doesn't work at all with 3.6.1).
Command to compile: ghc -O2 --make firstProgram.hs -fllvm -fforce-recomp
Exact error with command ./firstProgram
[1] 23665 illegal hardware instruction ./firstProgram
Thanks for any help!
Related
I have this program Main.hs:
main :: IO ()
main = do
if False then undefined
else do
let x = 5
print x
When I compile it with ghc Main.hs it compils well generating a Main executable, but when (after initializing cabal with cabal init) I try to make a cabal new-run it gives an error:
$ cabal new-run
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
- ghc-vs-cabal-0.1.0.0 (exe:ghc-vs-cabal) (file Main.hs changed)
Preprocessing executable 'ghc-vs-cabal' for ghc-vs-cabal-0.1.0.0..
Building executable 'ghc-vs-cabal' for ghc-vs-cabal-0.1.0.0..
[1 of 1] Compiling Main ( Main.hs, /home/ivan/ghc_vs_cabal/dist-newstyle/build/x86_64-linux/ghc-8.6.5/ghc-vs-cabal-0.1.0.0/x/ghc-vs-cabal/build/ghc-vs-cabal/ghc-vs-cabal-tmp/Main.o )
Main.hs:4:10: error: Empty 'do' block
|
4 | else do
| ^^
With cabal run it also gives error.
I have cabal version 2.4.0.0:
$ cabal --version
cabal-install version 2.4.0.0
compiled using version 2.4.0.1 of the Cabal library
And ghc version 8.6.5:
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.6.5
Does somebody know what is happening?
I know that I can fix it if I add indentation:
main :: IO ()
main = do
if False then undefined
else do
let x = 5
print x
But I want to know why it compiles with ghc but not with cabal new-run
Your code requires a language extension to parse: NondecreasingIndentation. This extension exists to avoid the awkward runaway effect of nested dos
main :: IO ()
main = do
if False then undefined
else do -- next block should be indented in standard Haskell
let x = 5
print x -- ...but this can easily get out of hand if you do it multiple times
NondecreasingIndentation allows a nested do block to register as nested as long as it's indented as much as the containing block, instead of more than the container.
According to the GHC manual, NondecreasingIndentation is on by default but disabled in Haskell2010 mode (unless explicitly enabled again). I can't find the corresponding cabal documentation, but we can probably guess it defaults to specifying Haskell2010.
You can specify extensions in a source file to be enabled or disabled regardless of external options by adding a pragma like
{-# LANGUAGE NondecreasingIndentation #-}
to the very top of the file.
I am a beginner of Haskell and I have downloaded ghc-8.8.1 from the official site. I tried to compile my first Haskell program with it and failed. Here is my program helloworld.hs:
main = putStrLn "hello world"
Then I compiled it with cmd (Windows 10):
ghc --make helloworld
And it failed with these words:
[1 of 1] Compiling Main ( helloworld.hs, helloworld.o )
Linking helloworld.exe ...
C:\Users\蔡XX\AppData\Local\Temp\ghc92756_0\ghc_6.rsp: commitBuffer: invalid argument (invalid character)
(蔡XX is my name)
Why is it not working? How can I solve this problem?
BTW, my ghci is working.
Edit: I created a new user in my computer with English name and copied my ghc, and this time it worked. It turns out that this problem was due to the character 蔡 in my path, as the comments said. Thanks guys!
As I know Text.ParserCombinators.Parsec is replaced by Text.Parsec
Here, it is my environment
4.9.73-1-MANJARO
The Glorious Glasgow Haskell Compilation System, version 8.2.2
cabal-install version 2.0.0.1
compiled using version 2.0.1.0 of the Cabal library
The following source code is my main.hs
module Main where
import System.Environment
import Text.Parsec
main :: IO ()
main = do
args <- getArgs
putStrLn (readExpr (args !! 0))
and then I compile it
$ ghc -package parsec -o main main.hs
It occurs the following error messages
[1 of 1] Compiling Main ( main.hs, main.o )
main.hs:3:1: error:
Could not find module ‘Text.Parsec’
There are files missing in the ‘parsec-3.1.11’ package,
try running 'ghc-pkg check'.
Use -v to see a list of the files searched for.
|
3 | import Text.Parsec
| ^^^^^^^^^^^^^^^^^^
rm: cannot remove '*.hi': No such file or directory
./run.sh: line 11: ./TestProj: No such file or directory
I make sure I have installed parsec. So I want to ask any mistake I've done?
$ cabal install parsec
Resolving dependencies...
All the requested packages are already installed:
parsec-3.1.11
Use --reinstall if you want to reinstall anyway.
Manjaro might have inherited from Arch's issues with Haskell.
What is going on
Arch installs dynamic libraries, but ghc links statically by default. This is also what the error message "There are files missing in the ... package", indicating that the package exists but does not contain what ghc is looking for.
If I try compiling with the -v verbose flag on, the error message expands to:
ghc -v main.hs
(...)
Locations searched:
Text/Parsec.hs
Text/Parsec.lhs
Text/Parsec.hsig
Text/Parsec.lhsig
/usr/lib/ghc-8.2.2/site-local/parsec-3.1.11/Text/Parsec.hi
(...)
In particular, look into the last reported location, which may be different on your system; if my guess is correct, ghc is looking for a static interface file .hi as the message indicates but there is only a dynamic one .dyn_hi.
Fix
Compile with the -dynamic flag.
ghc -dynamic main.hs
And if that works read this to fix the setup:
https://wiki.archlinux.org/index.php/Haskell
You will have to choose between static and dynamic linking; I don't actually understand the trade-off here.
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.
On my Windows 7 Home Premium box, why does the following Haskell program hang?
main = do
putStrLn "Hello, World"
The script is compiled (using GHC) like this:
C:\>ghc --make my_script
[1 of 1] Compiling Main ( my_script.hs, my_script.o )
Linking my_script.exe ...
The program is then executed like this:
C:\>my_script.exe
Even after several minutes, there is no output in the Command Prompt window.
GHC version is:
C:\>ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.2
(Haskell compiler obtained from https://www.haskell.org/platform/windows.html.)
Update Loading and executing in GHCi yields the following:
C:\>ghci my_script.hs
GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( my_script.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
Hello, World
*Main> :quit
Leaving GHCi.