
#11829: C++ does not catch exceptions when used with Haskell-main and linked by ghc -------------------------------------+------------------------------------- Reporter: pl | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Runtime System | Version: 7.10.3 Resolution: | Keywords: c++ | exceptions Operating System: MacOS X | Architecture: | Unknown/Multiple Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mtolly): This is still the case on macOS 10.12.5 and GHC 8.0.2. By examining the `ld` call from `g++` and experimenting, I discovered the fix is a flag that Clang's linker needs. Place this in the cabal file executable section: {{{ ld-options: -lto_library }}} Or use the following flag for GHC: {{{ ghc (source files) -lstdc++ -optl-lto_library }}} In the cabal file this amusingly parses the flag wrong and produces the incorrect advice: {{{ Warning: Instead of 'ld-options: -lto_library' use 'extra-libraries: to_library' }}} and it also prints the message from #5019 for some reason: {{{ ld: warning: could not create compact unwind for _ffi_call_unix64: does not use RBP or RSP based frame }}} [http://llvm.org/docs/LinkTimeOptimization.html Here is some info on what the flag does], but I don't quite understand how it is connected to exceptions. And [https://reviews.llvm.org/D25932 this page] suggests that a newer Clang will supply the flag automatically. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/11829#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler