[GHC] #13576: Runtime crashes on arm64 (iOS)

#13576: Runtime crashes on arm64 (iOS) ----------------------------------------+---------------------------------- Reporter: jp.rider63 | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: Keywords: | Operating System: MacOS X Architecture: Unknown/Multiple | Type of failure: Runtime crash Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: ----------------------------------------+---------------------------------- I compiled GHC from source (ff84d052850b637b0) with a few modifications to create a cross-compiler for arm64. This was the configuration: {{{ CC=aarch64-apple-darwin14-clang ./configure --prefix=/usr/local/ghc-ios --target=aarch64-apple-darwin14 --disable-large-address-space --enable- bootstrap-with-devel-snapshot }}} Here's my "mk/build.mk": {{{ HADDOCK_DOCS=NO WITH_TERMINFO=NO DYNAMIC_BY_DEFAULT=NO DYNAMIC_GHC_PROGRAMS=NO DYNAMIC_TOO=NO }}} I used the stage1 compiler to export an arm64 library. The application (which links the library) crashes when run on my device (iOS 10.2.1). The application runs without issue on x86 and arm32. When I initialize with -DS, I get the following error: {{{ internal error: ASSERTION FAILED: file rts/sm/Sanity.c, line 88 (GHC version 8.3.20170408 for aarch64_apple_ios) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug // SIGABRT at line 182 in RtsMessages.c }}} To narrow down the offending code, I replaced all my functions with print statements and slowly added the functionality back until I could reproduce the crash. It looks like the crash happens around a call to this function: {{{ foreign export ccall hs_AAPublicKeyAlgorithm :: StablePtr AA.PublicKey -> IO CString hs_AAPublicKeyAlgorithm :: StablePtr AA.PublicKey -> IO CString hs_AAPublicKeyAlgorithm = hs_toAlgorithmIdentifier hs_toAlgorithmIdentifier :: (ToAlgorithm t a, AlgorithmId a) => StablePtr t -> IO CString hs_toAlgorithmIdentifier ptr = do algId <- fmap (toAlgorithmId . toAlgorithm) $ deRefStablePtr ptr newCString algId }}} Oddly, when I add print statements around this call, I get a EXC_BREAKPOINT instead of a SIGABRT. Here's the output for this case: {{{ ****************TEST************ ****************TEST************ ****************TEST************ ****************TEST************ v1K_FZuskg6Bkm-whFvkQ8IzHxnXDSGibCwbqZpM0fk= here ****************TEST************ here1 here2 }}} I've disabled dead code stripping. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13576 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13576: Runtime crashes on arm64 (iOS) ----------------------------------+------------------------------- Reporter: jp.rider63 | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: Compiler | Version: Resolution: | Keywords: Operating System: MacOS X | Architecture: aarch64 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------- Changes (by bgamari): * priority: normal => high * cc: angerman (added) * architecture: Unknown/Multiple => aarch64 * milestone: => 8.4.1 @@ -12,1 +12,1 @@ - {{{ + {{{#!make @@ -39,1 +39,1 @@ - {{{ + {{{#!hs New description: I compiled GHC from source (ff84d052850b637b0) with a few modifications to create a cross-compiler for arm64. This was the configuration: {{{ CC=aarch64-apple-darwin14-clang ./configure --prefix=/usr/local/ghc-ios --target=aarch64-apple-darwin14 --disable-large-address-space --enable- bootstrap-with-devel-snapshot }}} Here's my "mk/build.mk": {{{#!make HADDOCK_DOCS=NO WITH_TERMINFO=NO DYNAMIC_BY_DEFAULT=NO DYNAMIC_GHC_PROGRAMS=NO DYNAMIC_TOO=NO }}} I used the stage1 compiler to export an arm64 library. The application (which links the library) crashes when run on my device (iOS 10.2.1). The application runs without issue on x86 and arm32. When I initialize with -DS, I get the following error: {{{ internal error: ASSERTION FAILED: file rts/sm/Sanity.c, line 88 (GHC version 8.3.20170408 for aarch64_apple_ios) Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug // SIGABRT at line 182 in RtsMessages.c }}} To narrow down the offending code, I replaced all my functions with print statements and slowly added the functionality back until I could reproduce the crash. It looks like the crash happens around a call to this function: {{{#!hs foreign export ccall hs_AAPublicKeyAlgorithm :: StablePtr AA.PublicKey -> IO CString hs_AAPublicKeyAlgorithm :: StablePtr AA.PublicKey -> IO CString hs_AAPublicKeyAlgorithm = hs_toAlgorithmIdentifier hs_toAlgorithmIdentifier :: (ToAlgorithm t a, AlgorithmId a) => StablePtr t -> IO CString hs_toAlgorithmIdentifier ptr = do algId <- fmap (toAlgorithmId . toAlgorithm) $ deRefStablePtr ptr newCString algId }}} Oddly, when I add print statements around this call, I get a EXC_BREAKPOINT instead of a SIGABRT. Here's the output for this case: {{{ ****************TEST************ ****************TEST************ ****************TEST************ ****************TEST************ v1K_FZuskg6Bkm-whFvkQ8IzHxnXDSGibCwbqZpM0fk= here ****************TEST************ here1 here2 }}} I've disabled dead code stripping. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13576#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13576: Runtime crashes on arm64 (iOS) ----------------------------------+------------------------------- Reporter: jp.rider63 | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: Compiler | Version: Resolution: | Keywords: Operating System: MacOS X | Architecture: aarch64 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------- Comment (by angerman): Does this happen when applying https://phabricator.haskell.org/D3290 prior to building the cross compiler, as well? {{{ 82 static void 83 checkClosureShallow( const StgClosure* p ) 84 { 85 const StgClosure *q; 86 87 q = UNTAG_CONST_CLOSURE(p); 88 ASSERT(LOOKS_LIKE_CLOSURE_PTR(q)); 89 } 90 }}} The crash indicates that q doesn't look like a closure. One of the cases where this happens is `-dead_strip`. However as noted in the ticket, dead_strip is disabled. This is basically a shot in the dark, e.g. if the addition of dead_strip prevention markers retains the symbol. could you try to see if `nm` lists different symbols for the crashing and the not crashing binary? `nm -j` should list the symbols without the address. `sort` should straighten them and `diff` could potentially be helpful. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13576#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13576: Runtime crashes on arm64 (iOS) ----------------------------------+------------------------------- Reporter: jp.rider63 | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: Compiler | Version: Resolution: | Keywords: Operating System: MacOS X | Architecture: aarch64 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------- Comment (by jp.rider63): As mentioned on irc, applying D3290 before building the cross-compiler did not work. The diff of nm is ~800k lines so I don't think it will be much help (the x86 library was built with a different version of ghc so there are different library versions and different symbols). I've been trying to create a minimal example to demonstrate the crash. So far I have had mixed results. Calling `hs_AAPublicKeyAlgorithm` by itself does cause the crash. Oddly, when I call `hs_testf` (defined below) before `hs_AAPublicKeyAlgorithm`, the crash goes away. {{{ class Test a b | a -> b where testF :: a -> b instance Test String String where testF = id foreign export ccall hs_astr :: IO (StablePtr String) hs_astr :: IO (StablePtr String) hs_astr = newStablePtr "a string" foreign export ccall hs_testf :: StablePtr String -> IO (StablePtr String) hs_testf :: StablePtr String -> IO (StablePtr String) hs_testf s = do s' <- deRefStablePtr s newStablePtr $ testF s' }}} I was thinking that maybe the functional dependency from `ToAlgorithm t a | t -> a` is causing the crash, but I'm not really sure. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13576#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13576: Runtime crashes on arm64 (iOS) ----------------------------------+------------------------------- Reporter: jp.rider63 | Owner: (none) Type: bug | Status: new Priority: high | Milestone: 8.4.1 Component: Compiler | Version: Resolution: | Keywords: Operating System: MacOS X | Architecture: aarch64 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+------------------------------- Comment (by angerman): jp.rider63, do you have a full example that crashes? I'd be willing to take a look at this. But as I underhand without `hs_AAPublicKeyAlgorithm`, this won't crash :-/ -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13576#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13576: Runtime crashes on arm64 (iOS) ----------------------------------+---------------------------------- Reporter: jp.rider63 | Owner: (none) Type: bug | Status: infoneeded Priority: high | Milestone: 8.6.1 Component: Compiler | Version: Resolution: | Keywords: Operating System: MacOS X | Architecture: aarch64 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+---------------------------------- Changes (by bgamari): * status: new => infoneeded * milestone: 8.4.1 => 8.6.1 Comment: This won't be fixed for 8.4.1. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13576#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13576: Runtime crashes on arm64 (iOS) ----------------------------------+---------------------------------- Reporter: jp.rider63 | Owner: (none) Type: bug | Status: infoneeded Priority: high | Milestone: 8.8.1 Component: Compiler | Version: Resolution: | Keywords: Operating System: MacOS X | Architecture: aarch64 Type of failure: Runtime crash | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | ----------------------------------+---------------------------------- Comment (by jp.rider63): angerman, I can give you read access to the required repositories if you send me your bitbucket username. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13576#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC