Opened 10 months ago

Last modified 3 months ago

#9277 new bug

GHCi panic: Loading temp shared object failed: Symbol not found

Reported by: mietek Owned by:
Priority: normal Milestone:
Component: GHCi Version: 7.8.2
Keywords: panic, dynamic linking Cc: hvr, tulcod, george
Operating System: MacOS X Architecture: x86_64 (amd64)
Type of failure: GHCi crash Test Case:
Blocked By: Blocking:
Related Tickets: #8935, #9034, #9074, #9278 Differential Revisions:

Description (last modified by mietek)

When given a Objective-C object file referencing a symbol available in a system framework, interactive GHCi 7.8.2 panics saying it can't find the symbol the object file relies on.

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.8.2 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.8.2 panics:

$ ghci -v -framework Foundation foo.o Main.hs
GHCi, version 7.8.2: http://www.haskell.org/ghc/  :? for help
Glasgow Haskell Compiler, Version 7.8.2, stage 2 booted by GHC version 7.6.3
Using binary package database: /opt/ghc-7.8.2/lib/ghc-7.8.2/package.conf.d/package.cache
wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-948744e1f99cc8bcc7c7d3ba60c7c2d8
wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-dc47f6b546fc171f67a7f7d311684a99
wired-in package base mapped to base-4.7.0.0-a333addb6892f3cc2e6baa5ec782bd04
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.9.0.0-ed6ecfb467e6936688bb20f968f702e1
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: 
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
*** gcc:
/usr/bin/gcc -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -L/opt/ghc-7.8.2/lib/ghc-7.8.2/base-4.7.0.0 --print-file-name libiconv.dylib
Loading package base ... linking ... done.
Loading object (static) foo.o ... Created temporary directory: /var/folders/26/0tzj1txn0vb_0061l4z4rsmr0000gn/T/ghc37622_0
*** Linker:
/usr/bin/gcc -m64 -fno-stack-protector -DTABLES_NEXT_TO_CODE -m64 -dynamiclib -o /var/folders/26/0tzj1txn0vb_0061l4z4rsmr0000gn/T/ghc37622_0/ghc37622_1.dylib foo.o -undefined dynamic_lookup -single_module -install_name '@rpath/ghc37622_1.dylib' -L/opt/ghc-7.8.2/lib/ghc-7.8.2/base-4.7.0.0 -Wl,-rpath -Wl,/opt/ghc-7.8.2/lib/ghc-7.8.2/base-4.7.0.0 -L/opt/ghc-7.8.2/lib/ghc-7.8.2/integer-gmp-0.5.1.0 -Wl,-rpath -Wl,/opt/ghc-7.8.2/lib/ghc-7.8.2/integer-gmp-0.5.1.0 -L/opt/ghc-7.8.2/lib/ghc-7.8.2/ghc-prim-0.3.1.0 -Wl,-rpath -Wl,/opt/ghc-7.8.2/lib/ghc-7.8.2/ghc-prim-0.3.1.0 -L/opt/ghc-7.8.2/lib/ghc-7.8.2/rts-1.0 -Wl,-rpath -Wl,/opt/ghc-7.8.2/lib/ghc-7.8.2/rts-1.0 -lHSbase-4.7.0.0-ghc7.8.2 -lHSinteger-gmp-0.5.1.0-ghc7.8.2 -lHSghc-prim-0.3.1.0-ghc7.8.2 -liconv
*** Deleting temp files:
Deleting: /var/folders/26/0tzj1txn0vb_0061l4z4rsmr0000gn/T/ghc37622_0/ghc37622_1.dylib
*** Deleting temp dirs:
Deleting: /var/folders/26/0tzj1txn0vb_0061l4z4rsmr0000gn/T/ghc37622_0
ghc: panic! (the 'impossible' happened)
  (GHC version 7.8.2 for x86_64-apple-darwin):
	Loading temp shared object failed: dlopen(/var/folders/26/0tzj1txn0vb_0061l4z4rsmr0000gn/T/ghc37622_0/ghc37622_1.dylib, 9): Symbol not found: _OBJC_CLASS_$_NSThread
  Referenced from: /var/folders/26/0tzj1txn0vb_0061l4z4rsmr0000gn/T/ghc37622_0/ghc37622_1.dylib
  Expected in: flat namespace
 in /var/folders/26/0tzj1txn0vb_0061l4z4rsmr0000gn/T/ghc37622_0/ghc37622_1.dylib

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

Omitting -framework Foundation makes no difference to the output.

Change History (8)

comment:1 Changed 10 months ago by mietek

  • Keywords panic dynamic linking added
  • Type of failure changed from None/Unknown to GHCi crash

comment:2 Changed 10 months ago by mietek

comment:3 Changed 10 months ago by mietek

There is a similar issue in GHC 7.6.3: #9278.

Last edited 10 months ago by mietek (previous) (diff)

comment:4 Changed 10 months ago by mietek

  • Description modified (diff)

comment:5 Changed 10 months ago by mietek

comment:6 Changed 9 months ago by tulcod

  • Cc tulcod added

comment:7 Changed 3 months ago by George

  • Cc george added

comment:8 Changed 3 months ago by George

I am seeing this on 7.10.1 RC1 when calling main:

ghc: panic! (the 'impossible' happened)

(GHC version 7.10.0.20141222 for x86_64-apple-darwin):

Loading temp shared object failed: dlopen(/var/folders/9b/rh4y2gy92hgdb6ktv4df1jv00000gn/T/ghc40460_0/ghc40460_6.dylib, 5): Symbol not found: _dataozu00S6JfeF9UMKB9yah5AkcN_DataziListziOrdered_minus_closure

Referenced from: /var/folders/9b/rh4y2gy92hgdb6ktv4df1jv00000gn/T/ghc40460_0/ghc40460_6.dylib
Expected in: flat namespace

in /var/folders/9b/rh4y2gy92hgdb6ktv4df1jv00000gn/T/ghc40460_0/ghc40460_6.dylib

ghc --info

[("Project name","The Glorious Glasgow Haskell Compilation System")
,("GCC extra via C opts"," -fwrapv")
,("C compiler command","/usr/bin/gcc")
,("C compiler flags"," -m64 -fno-stack-protector")
,("C compiler link flags"," -m64")
,("Haskell CPP command","/usr/bin/gcc")
,("Haskell CPP flags","-E -undef -traditional -Wno-invalid-pp-token -Wno-unicode -Wno-trigraphs ")
,("ld command","/usr/bin/ld")
,("ld flags"," -arch x86_64")
,("ld supports compact unwind","YES")
,("ld supports build-id","NO")
,("ld supports filelist","YES")
,("ld is GNU ld","NO")
,("ar command","/usr/bin/ar")
,("ar flags","clqs")
,("ar supports at file","NO")
,("touch command","touch")
,("dllwrap command","/bin/false")
,("windres command","/bin/false")
,("libtool command","libtool")
,("perl command","/usr/bin/perl")
,("target os","OSDarwin")
,("target arch","ArchX86_64")
,("target word size","8")
,("target has GNU nonexec stack","False")
,("target has .ident directive","True")
,("target has subsections via symbols","True")
,("Unregisterised","NO")
,("LLVM llc command","/usr/local/bin/llc")
,("LLVM opt command","/usr/local/bin/opt")
,("Project version","7.10.0.20141222")
,("Project Git commit id","a8c556dfca3eca5277615cc2bf9d6c8f1f143c9a")
,("Booter version","7.8.3")
,("Stage","2")
,("Build platform","x86_64-apple-darwin")
,("Host platform","x86_64-apple-darwin")
,("Target platform","x86_64-apple-darwin")
,("Have interpreter","YES")
,("Object splitting supported","YES")
,("Have native code generator","YES")
,("Support SMP","YES")
,("Tables next to code","YES")
,("RTS ways","l debug thr thr_debug thr_l thr_p dyn debug_dyn thr_dyn thr_debug_dyn l_dyn thr_l_dyn")
,("Support dynamic-too","YES")
,("Support parallel --make","YES")
,("Support reexported-modules","YES")
,("Support thinning and renaming package flags","YES")
,("Uses package keys","YES")
,("Dynamic by default","NO")
,("GHC Dynamic","YES")
,("Leading underscore","YES")
,("Debug on","False")
,("LibDir","/usr/local/lib/ghc-7.10.0.20141222")
,("Global Package DB","/usr/local/lib/ghc-7.10.0.20141222/package.conf.d")
]

OS 10.10.1

gcc --version
gcc (Homebrew gcc 4.9.2_1) 4.9.2

Last edited 3 months ago by George (previous) (diff)
Note: See TracTickets for help on using tickets.