[GHC] #10672: checkProddableBlock crash during Template Haskell linking

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 7.10.1 Keywords: | Operating System: Windows Architecture: | Type of failure: Compile-time Unknown/Multiple | crash Test Case: | Blocked By: Blocking: | Related Tickets: #9297 #10563 Differential Revisions: | #8237 -------------------------------------+------------------------------------- When compiling an executable that uses Template Haskell against a library that contains C++ code, GHC crashes: {{{ [2 of 2] Compiling Main ( app\Main.hs, dist\build\main\main- tmp\Main.o ) ghc.exe: internal error: checkProddableBlock: invalid fixup in runtime linker: 0000000000360564 (GHC version 7.10.1 for x86_64_unknown_mingw32) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} I've boiled this down into a minimal reproduction of a library that includes a .cpp file, and an executable that depends on it. To test: {{{ git clone https://github.com/lukexi/cxx-link-fail-repro cabal run }}} The crash does not occur in the repro unless I use C++ exceptions in the library, and use Template Haskell in the executable, but in the project I boiled this down from (http://github.com/lukexi/bullet-mini) the problem occurs even with {{{cc-options: -fno-exceptions}}}. Some more details are at https://github.com/lukexi/cxx-link-fail-repro The platform is Windows 8.1 under MSYS2 (GHC is still using its inbuilt mingw). I've also tried 7.10.2-RC1 with the same result. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Changes (by lukexi): * related: #9297 #10563 #8237 => #9297 #10563 #8237 #9907 Comment: I've tested on GHC 7.8.4 now and get this error instead: {{{ Loading package cxxylib-0.1.0.0 ... ghc.exe: Unknown PEi386 section name `.gcc_except_table' (while processing: C:\msys64\home\lukex_000\cxx-link- fail-repro\dist\build\HScxxylib-0.1.0.0.o) <no location info>: ghc.exe: panic! (the 'impossible' happened) (GHC version 7.8.4 for x86_64-unknown-mingw32): loadObj "C:\\msys64\\home\\lukex_000\\cxx-link-fail- repro\\dist\\build\\HScxxylib-0.1.0.0.o": failed Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} so it looks like this is related to #9907 and friends. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Changes (by lukexi): * cc: thoughtpolice (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Comment (by lukexi): Results of 7.8.4 with {{{bullet-mini}}}, which is using {{{-fno- exceptions}}} to avoid linking {{{libgcc_s_sjlj-1.dll}}} {{{ Loading package bullet-mini-0.1.0.0 ... ghc.exe: Unknown PEi386 section name `.text$_ZN21btBroadphaseInterfaceD1Ev' (while processing: C:\msys64\home\lukex_000\Projects\bullet-mini\dist\build\HSbullet- mini-0.1.0.0.o) <no location info>: ghc.exe: panic! (the 'impossible' happened) (GHC version 7.8.4 for x86_64-unknown-mingw32): loadObj "C:\\msys64\\home\\lukex_000\\Projects\\bullet- mini\\dist\\build\\HSbullet-mini-0.1.0.0.o": failed Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Comment (by lukexi): I'm able to get by the crash by commenting out the first call to {{{checkProddableBlock}}} in {{{ocResolve_PEi386}}} https://github.com/ghc/ghc/blob/master/rts/Linker.c#L4696. I'm not sure how to translate that into a proper fix yet — does that give anyone familiar with the linker any clues? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Changes (by lukexi): * milestone: => 7.10.3 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Changes (by lukexi): * cc: igloo (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Comment (by lukexi): To anyone else bitten by this: While this is figured out, I'm just stripping out all uses of Template Haskell in my software since I'm only using it for generating lenses. I put up a simple preprocessor here to do that during the build phase https://github.com/lukexi/strip-ths, designed to work with stack or cabal. (this workaround works because, as I mention in the README for the repro,
Everything also works [...] if I just call cabal exec -- ghc app/Main.hs. This is presumably because GHC doesn't try to link cxxylib when it is just compiling the Template Haskell splices, whereas Cabal asks it to. )
-- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Changes (by JohnWiegley): * cc: JohnWiegley (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Changes (by Phyx-): * cc: Phyx- (added) Comment: Hmm, this seems to happen because in `checkProddableBlock` the `oc->proddables` is NULL. So it has no blocks to check and it errors out. Don't know why it errors out and doesn't skip that ObjectCode and continue when there are no `proddables`. I'm pretty new at the linker so hopefully someone who knows more about this part can explain it. Also it won't work on anything prior to 7.10.x since you'll get the Unknown PE section error fixed in #9907 I don't think #9297 is related either, which seems to have more to do with the name manglings. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Comment (by ezyang): Hello lukexi, The problem is that your binary contains a section which (1) is pointed to by relocations, and (2) GHC doesn't understand. The pre-7.10.x error is better because it looks like to make your code work we really do need to understand the relocation. (We could paper over the problem by simply skipping relocations in sections we don't understand, but it is quite likely that you will get some even more bizarre error.) Can you run your test program with `+RTS -Dl` (debug RTS) and tell us exactly what section is unknown? Edward -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Comment (by lukexi): Hi Edward, thanks for the reply! Just to be sure, do you mean compiling a GHC with GhcDebugged=YES and then using cabal build --ghc-options="+RTS -Dl"? Luke -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: checkProddableBlock crash during Template Haskell linking -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Compiler | Version: 7.10.1 Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Comment (by ezyang): Yeah, something like `make re2 GhcDebugged=YES`. But it looks like the sections in question are `.gcc_except_table` and `.text$_ZN21btBroadphaseInterfaceD1Ev`. So two things we need to do: 1. Handle the exception table correctly 2. Match against the PREFIX so that anything starting with `.text` is loaded as a text segment. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: GHCi linker does not understand C++ exception tables on Windows -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Runtime System | Version: 7.10.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Changes (by ezyang): * component: Compiler => Runtime System (Linker) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: GHCi linker does not understand C++ exception tables on Windows -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Phyx- Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Runtime System | Version: 7.10.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Changes (by Phyx-): * owner: => Phyx- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:14 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: GHCi linker does not understand C++ exception tables on Windows -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Phyx- Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Runtime System | Version: 7.10.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Comment (by lukexi): Hi Phyx-/all — let me know if there are any public repos with work-in- progress on this; I'd love to help out! Planning on giving it some time later this week. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:15 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: GHCi linker does not understand C++ exception tables on Windows -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Phyx- Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Runtime System | Version: 7.10.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Comment (by Phyx-): @lukexi You can find the work in progress code at https://github.com/Mistuke/ghc/tree/rework-windows-pe-linker it should already fix the problem reported here (at least the code compiles and runs and prints three lines). I've only tested it for x86_64 so far. I'll be making a few other changes and test x86 before sending this out for review :) I will keep the branch on GitHub up-to-date. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:16 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: GHCi linker does not understand C++ exception tables on Windows -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Phyx- Type: bug | Status: new Priority: high | Milestone: 7.10.3 Component: Runtime System | Version: 7.10.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: #8237 #9907 | -------------------------------------+------------------------------------- Comment (by lukexi): Awesome stuff Tamar!! I confirmed your branch works on my test case and also backported the patches to 7.10.2 at https://github.com/lukexi/ghc/tree/ghc-7.10.2 -release-plus-rework-windows-pe-linker (git did 99% of the work, they mostly applied cleanly) and was able to build all of `bullet-mini` flawlessly, hurray! Thanks so much for your hard work. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:17 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: GHCi linker does not understand C++ exception tables on Windows -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Phyx- Type: bug | Status: patch Priority: high | Milestone: 7.10.3 Component: Runtime System | Version: 7.10.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: Type of failure: Compile-time | Unknown/Multiple crash | Test Case: Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Revisions: Phab:D1244 #8237 #9907 | -------------------------------------+------------------------------------- Changes (by Phyx-): * status: new => patch * differential: => Phab:D1244 Comment: Thanks for verifying @lukexi!. Good to hear that it worked for your test cases as well. Patch has been submitted for review :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:18 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: GHCi linker does not understand C++ exception tables on Windows
-------------------------------------+-------------------------------------
Reporter: lukexi | Owner: Phyx-
Type: bug | Status: patch
Priority: high | Milestone: 7.10.3
Component: Runtime System | Version: 7.10.1
(Linker) |
Resolution: | Keywords:
Operating System: Windows | Architecture:
Type of failure: Compile-time | Unknown/Multiple
crash | Test Case:
Blocked By: | Blocking:
Related Tickets: #9297 #10563 | Differential Rev(s): Phab:D1244
#8237 #9907 |
-------------------------------------+-------------------------------------
Comment (by Thomas Miedema

#10672: GHCi linker does not understand C++ exception tables on Windows -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Phyx- Type: bug | Status: merge Priority: high | Milestone: 7.10.3 Component: Runtime System | Version: 7.10.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: crash | rts/T10672/T10672_x86 T10672_x64 Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Rev(s): Phab:D1244 #8237 #9907 | -------------------------------------+------------------------------------- Changes (by thomie): * status: patch => merge * testcase: => rts/T10672/T10672_x86 T10672_x64 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:20 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: GHCi linker does not understand C++ exception tables on Windows -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Phyx- Type: bug | Status: merge Priority: high | Milestone: 7.10.3 Component: Runtime System | Version: 7.10.1 (Linker) | Resolution: | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: crash | rts/T10672/T10672_x86 T10672_x64 Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Rev(s): Phab:D1244 #8237 #9907 | -------------------------------------+------------------------------------- Comment (by thomie): If #10726 is going to be merged, a path of without merge conflicts is: * 9f7cdfee3e9f9ca6fbfa27d3b2dc2d86ac4ee226 (#10705) * a442800fd27952bff9bf9773f514ee062f4b55d0 (#10705) * 54b7dc5537f8b871e655752bace1ad6f5e6fe89a * 7b211b4e5a38efca437d76ea442495370da7cc9a (#10726) * 620fc6f909cd6e51b5613454097ec1c9f323839a (this ticket) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:21 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10672: GHCi linker does not understand C++ exception tables on Windows -------------------------------------+------------------------------------- Reporter: lukexi | Owner: Phyx- Type: bug | Status: closed Priority: high | Milestone: 7.10.3 Component: Runtime System | Version: 7.10.1 (Linker) | Resolution: fixed | Keywords: Operating System: Windows | Architecture: | Unknown/Multiple Type of failure: Compile-time | Test Case: crash | rts/T10672/T10672_x86 T10672_x64 Blocked By: | Blocking: Related Tickets: #9297 #10563 | Differential Rev(s): Phab:D1244 #8237 #9907 | Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * status: merge => closed * resolution: => fixed -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10672#comment:22 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC