[GHC] #9278: GHCi crash:
#9278: GHCi crash: ------------------------------------------+------------------------------- Reporter: mietek | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Keywords: crash, dynamic linking | Operating System: MacOS X Architecture: x86_64 (amd64) | Type of failure: GHCi crash Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9277 | ------------------------------------------+------------------------------- Given an Objective-C object file referencing a symbol available in a system framework, interactive GHCi 7.6.3 crashes in an odd fashion. Start with an Objective-C source file, defining a function to be used via the FFI: {{{ $ cat >foo.m <<EOF #import <Foundation/Foundation.h> BOOL is_main_thread() { return [NSThread isMainThread]; } EOF }}} {{{ $ cat >Main.hs <<EOF module Main where foreign import ccall "is_main_thread" isMainThread :: IO Bool main :: IO () main = do mt <- isMainThread print mt EOF }}} Non-interactive GHC 7.6.3 works as expected: {{{ $ clang -c -o foo.o foo.m }}} {{{ $ ghc -framework Foundation -o foo foo.o Main.hs [1 of 1] Compiling Main ( Main.hs, Main.o ) Linking foo ... }}} {{{ $ ./foo True }}} Interactive GHCi 7.6.3 crashes: {{{ $ ghci -framework Foundation foo.o Main.hs GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading object (static) foo.o ... done Loading object (framework) Foundation ... done final link ... done Ok, modules loaded: Main.
main 2014-07-07 12:28:21.811 ghc[37395:1103] *** NSForwarding: warning: selector (0x10ddef328) for message 'isMainThread' does not match selector known to Objective C runtime (0x7fff8ea15881)-- abort 2014-07-07 12:28:21.813 ghc[37395:1103] +[NSThread isMainThread]: unrecognized selector sent to class 0x7fff75535280 2014-07-07 12:28:21.814 ghc[37395:1103] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSThread isMainThread]: unrecognized selector sent to class 0x7fff75535280' *** First throw call stack: ( 0 CoreFoundation 0x00007fff8bb4825c __exceptionPreprocess + 172 1 libobjc.A.dylib 0x00007fff85029e75 objc_exception_throw + 43 2 CoreFoundation 0x00007fff8bb4b02d +[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x00007fff8baa6322 ___forwarding___ + 1010 4 CoreFoundation 0x00007fff8baa5ea8 _CF_forwarding_prep_0 + 120 5 ??? 0x000000010ddef31a 0x0 + 4527682330 6 ??? 0x000000010ddf02f5 0x0 + 4527686389 ) libc++abi.dylib: terminating with uncaught exception of type NSException Abort trap: 6 }}}
-- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9278> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9278: GHCi crash: selector _ for message _ does not match selector known to Objective C runtime -------------------------------+------------------------------------------ Reporter: mietek | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: crash, dynamic linking Operating System: MacOS X | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #9277 -------------------------------+------------------------------------------ -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9278#comment:1> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9278: GHCi crash: selector _ for message _ does not match selector known to Objective C runtime -------------------------------+------------------------------------------ Reporter: mietek | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: crash, dynamic linking Operating System: MacOS X | Architecture: x86_64 (amd64) Type of failure: GHCi crash | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #9277 -------------------------------+------------------------------------------ Comment (by mietek): There is a similar issue in GHC 7.8.2: #9277 -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9278#comment:2> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
#9278: GHCi crash: selector _ for message _ does not match selector known to Objective C runtime -------------------------------------+------------------------------------- Reporter: mietek | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 7.6.3 Resolution: | Keywords: crash, dynamic Differential Revisions: | linking Architecture: x86_64 | Operating System: MacOS X (amd64) | Type of failure: GHCi crash Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #9277 | -------------------------------------+------------------------------------- Changes (by chak): * cc: chak@… (added) Comment: AFAIK, the Objective-C runtime executes some initialisation code to set up Objective-C classes. The system linker produces executables that ensure that this initialisation is performed before any application code is being run. GHC's runtime doesn't know anything about that, though, and will just load the Objective-C binary code without performing the required runtime initialisation. Based on that, I believe, the error message you are seeing is a consequence of the selectors for the classes not being registered in the data structures used by `objc_msgSend()`. Here is a description of the internals of the ObjC runtime: http://cocoasamurai.blogspot.com.au/2010/01/understanding- objective-c-runtime.html -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9278#comment:3> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler
participants (1)
-
GHC