llvm-hs / llvm-hs-examples

Examples for Haskell bindings to LLVM
MIT License
70 stars 20 forks source link

`stack exec basic` won't work after following llvm-hs installation #12

Open skasyn opened 4 years ago

skasyn commented 4 years ago

What I wanted

Install LLVM-9 and test it.

What I did

What I expected

What it did

Insight

Hi ! Sorry to bother, it's probably a mistake from my part but I don't find any documentation about this issue.

I followed llvm-hs install directions for mac OS (brew install llvm-hs/llvm/llvm-9). It installed a bunch of binaries such as llvm-...-9.

First of all, I don't have any llvm-config as you asked in the README. However, I do have a llvm-config-9. When I run it, it prints 9.0.0. Is that an issue I should be aware of ? (if you feel that I asked on the wrong repository, don't bother with this issue).

Second of all, I ran stack exec basic. After a lot of installation, it printed me this error :

Executable named basic not found on path: ["/Users/skaas/tek3/llvm-hs-examples/.stack-work/install/x86_64-osx/d9d41a784075cf372862fbb26cc4c250326d7cca4e792a350578331a3c35bb78/8.6.5/bin","/Users/skaas/.stack/snapshots/x86_64-osx/d9d41a784075cf372862fbb26cc4c250326d7cca4e792a350578331a3c35bb78/8.6.5/bin","/Users/skaas/.stack/compiler-tools/x86_64-osx/ghc-8.6.5/bin","/Users/skaas/.sta
ck/programs/x86_64-osx/ghc-8.6.5/bin","/usr/local/bin","/Users/skaas/installer/flutter/bin","/usr/bin","/Users/skaas/installer/flutter/bin","/bin","/Users/skaas/installer/flutter/bin","/us
r/sbin","/Users/skaas/installer/flutter/bin","/sbin","/Users/skaas/installer/flutter/bin"]

I suppose I have to stack build even if it's now written in the README but when I do it, it gives me this error :

llvm-hs             > [ 93 of 114] Compiling LLVM.Internal.OrcJIT.LinkingLayer
llvm-hs             > [ 94 of 114] Compiling LLVM.OrcJIT.LinkingLayer
llvm-hs             > [ 95 of 114] Compiling LLVM.Internal.Linking
llvm-hs             > [ 96 of 114] Compiling LLVM.Linking
llvm-hs             > [ 97 of 114] Compiling LLVM.Internal.Module
llvm-hs             > [ 98 of 114] Compiling LLVM.Module
llvm-hs             > [ 99 of 114] Compiling LLVM
llvm-hs             > [100 of 114] Compiling LLVM.Internal.OrcJIT.CompileLayer
llvm-hs             > [101 of 114] Compiling LLVM.OrcJIT.CompileLayer
llvm-hs             > [102 of 114] Compiling LLVM.Internal.OrcJIT.IRTransformLayer
llvm-hs             > [103 of 114] Compiling LLVM.Internal.OrcJIT.IRCompileLayer
llvm-hs             > [104 of 114] Compiling LLVM.Internal.OrcJIT.CompileOnDemandLayer
llvm-hs             > [105 of 114] Compiling LLVM.OrcJIT
llvm-hs             > [106 of 114] Compiling LLVM.Internal.Analysis
llvm-hs             > [107 of 114] Compiling LLVM.Analysis
llvm-hs             > [108 of 114] Compiling LLVM.Internal.ExecutionEngine
llvm-hs             > [109 of 114] Compiling LLVM.ExecutionEngine
llvm-hs             > [110 of 114] Compiling LLVM.Threading
llvm-hs             > [111 of 114] Compiling LLVM.Transforms
llvm-hs             > [112 of 114] Compiling LLVM.Internal.FFI.PassManager
llvm-hs             > [113 of 114] Compiling LLVM.Internal.PassManager
llvm-hs             > [114 of 114] Compiling LLVM.PassManager
llvm-hs             >
llvm-hs             > /private/var/folders/qk/_jpn3vwx4674p04cbtgf3k4m0000gn/T/stack7306/llvm-hs-9.0.0/src/LLVM/Internal/FFI/PassManagerC.cpp:159:69: error:
llvm-hs             >      error: non-constant-expression cannot be narrowed from type 'LLVMBool' (aka 'int') to 'bool' in initializer list [-Wc++11-narrowing]
llvm-hs             >             unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >                                                                                ^~~~~~~
llvm-hs             >     |
llvm-hs             > 159 |         unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >     |                                                                     ^
llvm-hs             >
llvm-hs             > /private/var/folders/qk/_jpn3vwx4674p04cbtgf3k4m0000gn/T/stack7306/llvm-hs-9.0.0/src/LLVM/Internal/FFI/PassManagerC.cpp:159:69: error:
llvm-hs             >      note: insert an explicit cast to silence this issue
llvm-hs             >             unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >                                                                                ^~~~~~~
llvm-hs             >                                                                                static_cast<bool>( )
llvm-hs             >     |
llvm-hs             > 159 |         unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >     |                                                                     ^
llvm-hs             >
llvm-hs             > /private/var/folders/qk/_jpn3vwx4674p04cbtgf3k4m0000gn/T/stack7306/llvm-hs-9.0.0/src/LLVM/Internal/FFI/PassManagerC.cpp:159:78: error:
llvm-hs             >      error: non-constant-expression cannot be narrowed from type 'LLVMBool' (aka 'int') to 'bool' in initializer list [-Wc++11-narrowing]
llvm-hs             >             unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >                                                                                         ^~~~~~
llvm-hs             >     |
llvm-hs             > 159 |         unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >     |                                                                              ^
llvm-hs             >
llvm-hs             > /private/var/folders/qk/_jpn3vwx4674p04cbtgf3k4m0000gn/T/stack7306/llvm-hs-9.0.0/src/LLVM/Internal/FFI/PassManagerC.cpp:159:78: error:
llvm-hs             >      note: insert an explicit cast to silence this issue
llvm-hs             >             unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >                                                                                         ^~~~~~
llvm-hs             >                                                                                         static_cast<bool>( )
llvm-hs             >     |
llvm-hs             > 159 |         unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >     |                                                                              ^
llvm-hs             > 2 errors generated.
llvm-hs             > `gcc' failed in phase `C Compiler'. (Exit code: 1)

--  While building package llvm-hs-9.0.0 using:
      /private/var/folders/qk/_jpn3vwx4674p04cbtgf3k4m0000gn/T/stack7306/llvm-hs-9.0.0/.stack-work/dist/x86_64-osx/Cabal-2.4.0.1/setup/setup --builddir=.stack-work/dist/x86_64-osx/Cabal-2.4.0.1 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
Progress 30/31

I never met this issue before and I don't understand where installation could have failed, I literally just ran brew install.

Do you have any idea of what could be wrong ? Should I post the issue on the llvm-hs repository ?

Thank for your attention.

4dam7 commented 4 years ago

When I run with cabal : cabal run basic, I got the expected output I think :

; ModuleID = 'basic'
source_filename = "<string>"

define i32 @add(i32 %a, i32 %b) {
entry:
  %result = add i32 %a, %b
  ret i32 %result
}
sdiehl commented 4 years ago

This is almost certainly a MacOS issue building the LLVM library itself, I would post on the homebrew-llvm tracker to see if anyone has encountered this before. Our support of Mac is best effort as most of the maintainers are Linux-only.

tmcdonell commented 4 years ago

@sdiehl this is definitely an llvm-hs problem; it won't get to trying to build llvm-hs until LLVM itself is installed.

llvm-hs             > /private/var/folders/qk/_jpn3vwx4674p04cbtgf3k4m0000gn/T/stack7306/llvm-hs-9.0.0/src/LLVM/Internal/FFI/PassManagerC.cpp:159:69: error:
llvm-hs             >      error: non-constant-expression cannot be narrowed from type 'LLVMBool' (aka 'int') to 'bool' in initializer list [-Wc++11-narrowing]
llvm-hs             >             unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >                                                                                ^~~~~~~
llvm-hs             >     |
llvm-hs             > 159 |         unwrap(PM)->add(createMemorySanitizerLegacyPassPass({trackOrigins, recover, kernel}));
llvm-hs             >     |                                                                     ^
llvm-hs             >

@skasyn what is your Xcode / clang version?

skasyn commented 4 years ago

Thanks for replying . Everything should be up to date since I had to install Xcode in order to build llvm (brew install llvm-hs/llvm/llvm-9 won't run if Xcode is not fully installed)

Xcode 11.3.1
Build version 11C504
Apple clang version 11.0.0 (clang-1100.0.33.17)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I must stress that using cabal install or cabal run links with LLVM just fine. I can use LLVM on my computer and I can build ir, .o and .s files.

delreluca commented 3 years ago

I encountered the same issue and the fix was to bump llvm-hs-9.0.0 to llvm-hs-9.0.1 in the stack.yaml extra dependencies. Sorry for commenting on an old issue but maybe it helps someone else.