Opened 5 years ago

Last modified 7 months ago

#9277 new bug

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

Reported by: mietek Owned by:
Priority: normal Milestone:
Component: Runtime System (Linker) Version: 7.8.2
Keywords: panic, dynamic linking Cc: hvr, tulcod, george, trommler
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 Rev(s):
Wiki Page:

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];
$ cat >Main.hs <<EOF
module Main where

foreign import ccall "is_main_thread" isMainThread :: IO Bool

main :: IO ()
main = do
  mt <- isMainThread
  print mt

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

Interactive GHCi 7.8.2 panics:

$ ghci -v -framework Foundation foo.o Main.hs
GHCi, version 7.8.2:  :? 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-
wired-in package integer-gmp mapped to integer-gmp-
wired-in package base mapped to base-
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-
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- --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- -Wl,-rpath -Wl,/opt/ghc-7.8.2/lib/ghc-7.8.2/base- -L/opt/ghc-7.8.2/lib/ghc-7.8.2/integer-gmp- -Wl,-rpath -Wl,/opt/ghc-7.8.2/lib/ghc-7.8.2/integer-gmp- -L/opt/ghc-7.8.2/lib/ghc-7.8.2/ghc-prim- -Wl,-rpath -Wl,/opt/ghc-7.8.2/lib/ghc-7.8.2/ghc-prim- -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- -lHSinteger-gmp- -lHSghc-prim- -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:

Omitting -framework Foundation makes no difference to the output.

Change History (12)

comment:1 Changed 5 years ago by mietek

Keywords: panic dynamic linking added
Type of failure: None/UnknownGHCi crash

comment:2 Changed 5 years ago by mietek

comment:3 Changed 5 years ago by mietek

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

Last edited 5 years ago by mietek (previous) (diff)

comment:4 Changed 5 years ago by mietek

Description: modified (diff)

comment:5 Changed 5 years ago by mietek

comment:6 Changed 5 years ago by tulcod

Cc: tulcod added

comment:7 Changed 5 years ago by George

Cc: george added

comment:8 Changed 5 years ago by George

I am seeing this on 7.10.1 RC1 when calling main:

ghc: panic! (the 'impossible' happened)

(GHC version 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","") ,("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-") ,("Global Package DB","/usr/local/lib/ghc-") ]

OS 10.10.1

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

Last edited 5 years ago by George (previous) (diff)

comment:9 Changed 4 years ago by konn

I have a similar phenomenon with GHC 7.10.2 (installed with Haskell Platform) on OS X Yosemite 10.10.5.

The same error also occurs when launching GHCi with -package foo where foo uses Obj-C code through FFI. Template Haskell uses GHCi internally, so this means that we can't use Template Haskell with Objective-C FFI.

comment:10 Changed 4 years ago by ezyang

Component: GHCiRuntime System (Linker)

comment:11 Changed 4 years ago by trommler

Cc: trommler added

comment:12 Changed 7 months ago by mietek

My test case repository is now named

Note: See TracTickets for help on using tickets.