OS X framework + ghci linker + RTS flags = bus error?

Judah Jacobson judah.jacobson at gmail.com
Tue Oct 19 21:07:06 EDT 2004


The dynamic linker appears to interact in a strange way with RTS
command-line flags on OS X. (version 10.2.8, with ghc-6.2.2;
although ghc-6.2.1 and ghc-6.3.20041009 also seem to have this
problem).  Here's a simple example:

******************************
// BusErr.m

#include <Foundation/Foundation.h>

int foo(int n) {
    NSLog(@"In foo.");
    return n;
}

******************************

>gcc -c BusErr.m
>ghci -framework Foundation +RTS -RTS BusErr.o

Loading package base ... linking ... done.
Loading object (static) BusErr.o ... done
Loading object (framework) Foundation ... done
final link ... Bus error

******************************

A similar error occurs when using foreign code from a framework
in a Template Haskell splice  (which is where this matters to me).  The 
error is avoided either by using ghc instead of ghci, by removing the
"+RTS -RTS" flags, or by removing the call to NSLog (or, eg, replacing 
it with printf which is not linked via a framework). 

I've tracked the bus error to the call to NSLookupAndBindSymbol in
rts/Linker.c (on the symbol "_NSLog", in this case) but can't
figure out anything more than that.  

Thanks in advance,
-Judah


******************************
Crash report:

Date/Time:  2004-10-19 19:45:35 -0400
OS Version: 10.2.8 (Build 6R73)

Command:    ghc-6.2.2
PID:        1155

Exception:  EXC_BAD_ACCESS (0x0001)
Codes:      KERN_PROTECTION_FAILURE (0x0002) at 0x00000000

Thread 0 Crashed:
 #0   0x90013c54 in memcmp
 #1   0x901a5458 in __CFInitialize
 #2   0x8fe0901c in call_image_init_routines
 #3   0x8fe106e4 in link_in_need_modules
 #4   0x8fe104e4 in bind_symbol_by_name
 #5   0x8fe136d8 in _dyld_NSLookupAndBindSymbol
 #6   0x9003ea94 in NSLookupAndBindSymbol
 #7   0x00a6ff64 in 0xa6ff64
 #8   0x00a7069c in 0xa7069c
 #9   0x00a7125c in 0xa7125c
 #10  0x00a701d4 in 0xa701d4
 #11  0x00326810 in 0x326810
 #12  0x00a68cb8 in 0xa68cb8
 #13  0x00a69698 in 0xa69698
 #14  0x00a695b0 in 0xa695b0
 #15  0x00a82250 in 0xa82250
 #16  0x00a3c880 in 0xa3c880
 #17  0x000021b0 in 0x21b0
 #18  0x00002030 in 0x2030

PPC Thread State:
  srr0: 0x90013c54 srr1: 0x0000f030                vrsave: 0x00000000
   xer: 0x00000000   lr: 0x901a5458  ctr: 0x00000010   mq: 0x00000000
    r0: 0x00000010   r1: 0xbfffcd10   r2: 0x00000006   r3: 0x00000000
    r4: 0x901c8581   r5: 0x00000010   r6: 0x00b97000   r7: 0x00b97000
    r8: 0x00000000   r9: 0x0000002d  r10: 0x00000001  r11: 0xa0132f4c
   r12: 0x90013c40  r13: 0x00000000  r14: 0x00b88af8  r15: 0x0000000f
   r16: 0x0152df20  r17: 0x0152dfbc  r18: 0x0152dfb4  r19: 0x00000000
   r20: 0x8fe48480  r21: 0x8fe48470  r22: 0x8fe48a44  r23: 0x00000000
   r24: 0x66000000  r25: 0x8fe4844c  r26: 0xbffffa10  r27: 0xbffffa28
   r28: 0xa0135370  r29: 0x00000007  r30: 0x00000006  r31: 0x901a5370



More information about the Glasgow-haskell-bugs mailing list