Commit 6f69004a authored by's avatar
Browse files

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.
parent c4b993f3
......@@ -83,7 +83,9 @@
# include <mach-o/loader.h>
# include <mach-o/nlist.h>
# include <mach-o/reloc.h>
#if !defined(HAVE_DLFCN_H)
# include <mach-o/dyld.h>
#if defined(powerpc_HOST_ARCH)
# include <mach-o/ppc/reloc.h>
......@@ -1068,12 +1070,25 @@ lookupSymbol( char *lbl )
return dlsym(dl_prog_handle, lbl);
# endif
# elif defined(OBJFORMAT_MACHO)
/* On OS X 10.3 and later, we use dlsym instead of the old legacy
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
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;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment