From 6f69004ae9aa595ad439771fa41b0feeb118810b Mon Sep 17 00:00:00 2001 From: Roman Leshchinskiy Date: Wed, 5 Sep 2007 05:22:13 +0000 Subject: [PATCH] Use dlsym on OS X if available On OS X 10.4 and newer, we have to use dlsym because the old NS* interface has been deprecated. The patch checks for HAVE_DLFCN_H instead of switching on the OS version. There is one additional quirk: although OS X prefixes global symbols with an underscore, dlsym expects its argument NOT to have a leading underscore. As a hack, we simply strip it off in lookupSymbol. Something a bit more elaborate might be cleaner. --- rts/Linker.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/rts/Linker.c b/rts/Linker.c index c212c0f..7c6d744 100644 --- a/rts/Linker.c +++ b/rts/Linker.c @@ -83,7 +83,9 @@ # include # include # include +#if !defined(HAVE_DLFCN_H) # include +#endif #if defined(powerpc_HOST_ARCH) # include #endif @@ -1068,12 +1070,25 @@ lookupSymbol( char *lbl ) return dlsym(dl_prog_handle, lbl); # endif # elif defined(OBJFORMAT_MACHO) +# if HAVE_DLFCN_H + /* On OS X 10.3 and later, we use dlsym instead of the old legacy + interface. + + HACK: On OS X, global symbols are prefixed with an underscore. + However, dlsym wants us to omit the leading underscore from the + symbol name. For now, we simply strip it off here (and ONLY + here). + */ + ASSERT(lbl[0] == '_'); + return dlsym(dl_prog_handle, lbl+1); +# else if(NSIsSymbolNameDefined(lbl)) { NSSymbol symbol = NSLookupAndBindSymbol(lbl); return NSAddressOfSymbol(symbol); } else { return NULL; } +# endif /* HAVE_DLFCN_H */ # elif defined(OBJFORMAT_PEi386) OpenedDLL* o_dll; void* sym; -- 1.7.10.4