Failure to catch C++ exception in Haskell on OS X

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Failure to catch C++ exception in Haskell on OS X

Bas van Dijk-2
Dear GHC Devs,

I'm debugging an issue in our haskell-opencv library where a C++ exception that is thrown by the OpenCV C++ library isn't caught by the C++ try...catch block we have inlined in our Haskell code using inline-c-cpp. This results in the process terminating by SIGABRT.

Note that this only happens on OS X. In Linux the exception is caught correctly.

I wrote a minimal isolated test case (which doesn't use OpenCV) at:


I wrote some instructions in the README on how to reproduce this and included some debugging notes.

I'm not sure the bug is caused by a mis-configuration in my code or if it's a bug in nixpkgs, Cabal or GHC. Any idea what could be causing this?

Bas


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Failure to catch C++ exception in Haskell on OS X

Gabor Greif-2
Hi Bas,

maybe some DWARF unwind tables are not correctly installed in OS X?

Do intra-C++ exception catching work in your example?

Cheers,

    Gabor

On 1/4/19, Bas van Dijk <[hidden email]> wrote:

> Dear GHC Devs,
>
> I'm debugging an issue in our haskell-opencv library where a C++ exception
> that is thrown by the OpenCV C++ library isn't caught by the C++
> try...catch block we have inlined in our Haskell code using inline-c-cpp.
> This results in the process terminating by SIGABRT.
>
> Note that this only happens on OS X. In Linux the exception is caught
> correctly.
>
> I wrote a minimal isolated test case (which doesn't use OpenCV) at:
>
>   https://github.com/basvandijk/darwin-cxx-exception-bug
>
> I wrote some instructions in the README on how to reproduce this and
> included some debugging notes.
>
> I'm not sure the bug is caused by a mis-configuration in my code or if it's
> a bug in nixpkgs, Cabal or GHC. Any idea what could be causing this?
>
> Bas
>
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Failure to catch C++ exception in Haskell on OS X

Bas van Dijk-2
On Fri, 4 Jan 2019 at 14:15, Gabor Greif <[hidden email]> wrote:
> maybe some DWARF unwind tables are not correctly installed in OS X?

Hi Gabor, thanks, I will look into that.

> Do intra-C++ exception catching work in your example?

Yes, I have a C++ executable foo[1] that links with libfoo that
correctly catches the exception:

  > $(nix-build --no-link -A foo)/bin/test
  ...
  Whoops!

Since it's working in pure C++ I suspect it has something to do with
how GHC calls either the C++ compiler or linker.

Bas

[1] https://github.com/basvandijk/darwin-cxx-exception-bug/blob/master/foo/test.cpp
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Failure to catch C++ exception in Haskell on OS X

Adam Sandberg Eriksson
A ticket which seems to cover the same problem: https://ghc.haskell.org/trac/ghc/ticket/11829


—Adam

> On 4 Jan 2019, at 16:50, Bas van Dijk <[hidden email]> wrote:
>
> On Fri, 4 Jan 2019 at 14:15, Gabor Greif <[hidden email]> wrote:
>> maybe some DWARF unwind tables are not correctly installed in OS X?
>
> Hi Gabor, thanks, I will look into that.
>
>> Do intra-C++ exception catching work in your example?
>
> Yes, I have a C++ executable foo[1] that links with libfoo that
> correctly catches the exception:
>
>> $(nix-build --no-link -A foo)/bin/test
>  ...
>  Whoops!
>
> Since it's working in pure C++ I suspect it has something to do with
> how GHC calls either the C++ compiler or linker.
>
> Bas
>
> [1] https://github.com/basvandijk/darwin-cxx-exception-bug/blob/master/foo/test.cpp
> _______________________________________________
> ghc-devs mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Failure to catch C++ exception in Haskell on OS X

Bas van Dijk-2
On Fri, 4 Jan 2019 at 23:46, Adam Sandberg Eriksson
<[hidden email]> wrote:
> A ticket which seems to cover the same problem: https://ghc.haskell.org/trac/ghc/ticket/11829

Wonderful! I can confirm[1] that adding the following to the cabal
file fixes the problem:

  if os(darwin)
    ld-options: -Wl,-keep_dwarf_unwind

Shouldn't GHC do this by default when linking on OS X?

Bas

[1] https://github.com/basvandijk/darwin-cxx-exception-bug/commit/9b48441606d2fe364c2a21a4ca8ba6b7ff735fe5
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Failure to catch C++ exception in Haskell on OS X

Carter Schonwald
Are we talking about Haskell or linking/ calling c plus plus? If the latter, that’s more of a cabal issue I think?


If you mean ghc build wise 
No. The unwind library only supports elf format. Which OS X does not use. 

Even that issue aside : ghc currently can’t build with any level of dwarf enabled on OS X, eg the system linker complains about exceeding some system section object format limit.  

I guess my point is : dwarf data for Haskell libraries on OS X have a few challenges between here and there. 

On Fri, Jan 4, 2019 at 9:29 PM Bas van Dijk <[hidden email]> wrote:
On Fri, 4 Jan 2019 at 23:46, Adam Sandberg Eriksson
<[hidden email]> wrote:
> A ticket which seems to cover the same problem: https://ghc.haskell.org/trac/ghc/ticket/11829

Wonderful! I can confirm[1] that adding the following to the cabal
file fixes the problem:

  if os(darwin)
    ld-options: -Wl,-keep_dwarf_unwind

Shouldn't GHC do this by default when linking on OS X?

Bas

[1] https://github.com/basvandijk/darwin-cxx-exception-bug/commit/9b48441606d2fe364c2a21a4ca8ba6b7ff735fe5
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs