[GHC] #13093: Runtime linker chokes on LLVM function on Windows

#13093: Runtime linker chokes on LLVM function on Windows -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime | Version: 8.0.1 System (Linker) | Keywords: | Operating System: Windows Architecture: | Type of failure: GHCi crash Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- This error prevents the [http://hackage.haskell.org/package/llvm-general llvm-general] library from loading in GHCi on Windows. I don't know how to reproduce this error without using LLVM. First, you need to install LLVM. On Windows, you can install it with MSYS2: {{{ pacman -S mingw-w64-x86_64-llvm }}} Currently, this gives you LLVM-3.9, although I've reproduced it with LLVM-3.8 as well. Now define this Haskell file: {{{#!hs module Main (main) where import Foreign.C.Types newtype LLVMBool = LLVMBool CUInt deriving Show foreign import ccall unsafe "LLVMIsMultithreaded" isMultithreaded :: IO LLVMBool main :: IO () main = isMultithreaded >>= print }}} If you compile it, it works OK: {{{ $ ghc LLVM.hs -fforce-recomp $(llvm-config --libs) $(llvm-config --system- libs) -lstdc++-6 -lgcc_s_seh-1 [1 of 1] Compiling Main ( LLVM.hs, LLVM.o ) Linking LLVM.exe ... $ ./LLVM LLVMBool 1 }}} Or, if you're allergic to `llvm-config`: {{{ $ ghc LLVM.hs -fforce-recomp -lLLVMLTO -lLLVMObjCARCOpts -lLLVMSymbolize -lLLVMDebugInfoPDB -lLLVMDebugInfoDWARF -lLLVMGlobalISel -lLLVMCoverage -lLLVMTableGen -lLLVMLineEditor -lLLVMOrcJIT -lLLVMMIRParser -lLLVMARMDisassembler -lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMObjectYAML -lLLVMLibDriver -lLLVMOption -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter -lLLVMDebugInfoCodeView -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMPasses -lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMInterpreter -lLLVMExecutionEngine -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser -lLLVMCodeGen -lLLVMTarget -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMTransformUtils -lLLVMMC -lLLVMBitWriter -lLLVMBitReader -lLLVMAnalysis -lLLVMProfileData -lLLVMCore -lLLVMSupport -lpsapi -lshell32 -lole32 -luuid -lstdc++-6 -lgcc_s_seh-1 [1 of 1] Compiling Main ( LLVM.hs, LLVM.o ) Linking LLVM.exe ... $ ./LLVM LLVMBool 1 }}} If you load it into GHCi, however, things go awry: {{{ $ ghci $(llvm-config --libs) $(llvm-config --system-libs) -lgcc_s_seh-1 GHCi, version 8.0.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from C:\Users\RyanGlScott\AppData\Roaming\ghc\ghci.conf Ok, modules loaded: Main (LLVM.o).
main ghc.exe: LLVM.o: unknown symbol `LLVMIsMultithreaded' }}}
On GHC 8.0.1 and HEAD, it's a slightly different error: {{{
main
ByteCodeLink: can't find label During interactive linking, GHCi couldn't find the following symbol: LLVMIsMultithreaded This may be due to you not asking GHCi to load extra object files, archives or DLLs needed by your current session. Restart GHCi, specifying the missing library using the -L/path/to/object/dir and -lmissinglibname flags, or simply by naming the relevant files on the GHCi command line. Alternatively, this link failure might indicate a bug in GHCi. If you suspect the latter, please send a bug report to: glasgow-haskell-bugs@haskell.org }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on LLVM function on Windows -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): It's worth noting that this is a statically linked LLVM build, not a shared (dynamically linked) build. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on LLVM function on Windows -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Phyx-): * owner: => Phyx- Comment: Hmm, Interesting, thanks for the report. I think the error message is also a bit of a regression. It seems we currently abort inside the `rts` while we used to return and let the Haskell code resolve it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on LLVM function on Windows -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by Phyx-): * related: => #13103 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103, #13093 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: #13103 => #13103, #13093 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103, #13093 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by awson): I have my custom ''shared libraries'' build of llvm on MinGW-w64 and `llvm-general` works just fine with it. Thus `-fshared-llvm` requirement is important. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: #13103, #13093 => #13103 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: Phyx-
Type: bug | Status: new
Priority: normal | Milestone: 8.2.1
Component: Runtime System | Version: 8.0.1
(Linker) |
Resolution: | Keywords:
Operating System: Windows | Architecture:
| Unknown/Multiple
Type of failure: GHCi crash | Test Case:
Blocked By: | Blocking:
Related Tickets: #13103 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13093: Runtime linker chokes on object files created by MSVC++
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: Phyx-
Type: bug | Status: new
Priority: normal | Milestone: 8.2.1
Component: Runtime System | Version: 8.0.1
(Linker) |
Resolution: | Keywords:
Operating System: Windows | Architecture:
| Unknown/Multiple
Type of failure: GHCi crash | Test Case:
Blocked By: | Blocking:
Related Tickets: #13103 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by bgamari):
Merged 2f1017b924740e66f093b0baba62ac0b1528abf8,
{{{
commit 2f1017b924740e66f093b0baba62ac0b1528abf8
Author: Tamar Christina

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by Phyx-): No, this one requires a final fix. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103 | Differential Rev(s): Phab:D3026 Wiki Page: | Phab:D3027 Phab:D3082 Phab:D3028 -------------------------------------+------------------------------------- Changes (by Phyx-): * differential: => Phab:D3026 Phab:D3027 Phab:D3082 Phab:D3028 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: Phyx-
Type: bug | Status: new
Priority: normal | Milestone: 8.2.1
Component: Runtime System | Version: 8.0.1
(Linker) |
Resolution: | Keywords:
Operating System: Windows | Architecture:
| Unknown/Multiple
Type of failure: GHCi crash | Test Case:
Blocked By: | Blocking:
Related Tickets: #13103 | Differential Rev(s): Phab:D3026
Wiki Page: | Phab:D3027 Phab:D3082 Phab:D3028
-------------------------------------+-------------------------------------
Comment (by Ben Gamari

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: closed Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: fixed | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103 | Differential Rev(s): Phab:D3026 Wiki Page: | Phab:D3027 Phab:D3082 Phab:D3028 -------------------------------------+------------------------------------- Changes (by bgamari): * status: new => closed * resolution: => fixed Comment: If I'm not mistaken this is now resolved by Phab:D3028. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103 | Differential Rev(s): Phab:D3026 Wiki Page: | Phab:D3027 Phab:D3082 Phab:D3028 -------------------------------------+------------------------------------- Changes (by Phyx-): * owner: Phyx- => (none) * status: closed => new * resolution: fixed => Comment: No it requires Phab:D3082 (msvc generates files with extension .obj). But also requires a final patch that I have yet to write. That's what I meant in comment:10 :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.2.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103 | Differential Rev(s): Phab:D3026 Wiki Page: | Phab:D3027 Phab:D3082 Phab:D3028 -------------------------------------+------------------------------------- Changes (by Phyx-): * owner: (none) => Phyx- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++ -------------------------------------+------------------------------------- Reporter: RyanGlScott | Owner: Phyx- Type: bug | Status: new Priority: normal | Milestone: 8.4.1 Component: Runtime System | Version: 8.0.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: GHCi crash | Test Case: Blocked By: | Blocking: Related Tickets: #13103 | Differential Rev(s): Phab:D3026 Wiki Page: | Phab:D3027 Phab:D3082 Phab:D3028 -------------------------------------+------------------------------------- Comment (by Phyx-): New linker is making some significant progress here as well {{{ Tamar@Destiny MINGW64 /e/temp $ echo "main" | ~/ghc/inplace/bin/ghc-stage2.exe --interactive LLVM.hs $(llvm-config --libs --link-static) $(llvm-config --system-libs --link- static) -L/mingw64/lib/ -lstdc++ -lgcc GHCi, version 8.3.20170812: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( LLVM.hs, interpreted ) Ok, 1 module loaded. *Main> Access violation in generated code when reading ffffffffffffffff }}} The LLVM libraries require the new `big-obj` support and also require proper section alignment support which now works. The remaining problem is that it's C++ and requires proper support for Constructors and Destructors via `__DTOR_LIST__` and `__CTOR_LIST__`. However I lack some knowledge of how the C++ ABI and linking work so I'll need to read up before I can add this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13093#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13093: Runtime linker chokes on object files created by MSVC++
-------------------------------------+-------------------------------------
Reporter: RyanGlScott | Owner: Phyx-
Type: bug | Status: new
Priority: normal | Milestone: 8.4.1
Component: Runtime System | Version: 8.0.1
(Linker) |
Resolution: | Keywords:
Operating System: Windows | Architecture:
| Unknown/Multiple
Type of failure: GHCi crash | Test Case:
Blocked By: | Blocking:
Related Tickets: #13103 | Differential Rev(s): Phab:D3026
Wiki Page: | Phab:D3027 Phab:D3082 Phab:D3028
-------------------------------------+-------------------------------------
Comment (by Tamar Christina
participants (1)
-
GHC