diff --git a/xpcom/glue/standalone/nsXPCOMGlue.cpp b/xpcom/glue/standalone/nsXPCOMGlue.cpp index 41815a8ee5f8..a9440b8acb76 100644 --- a/xpcom/glue/standalone/nsXPCOMGlue.cpp +++ b/xpcom/glue/standalone/nsXPCOMGlue.cpp @@ -29,14 +29,6 @@ static bool do_preload = false; #define READ_TEXTMODE "r" #endif -#if defined(SUNOS4) || defined(NEXTSTEP) || \ - defined(XP_MACOSX) || \ - (defined(OPENBSD) || defined(NETBSD)) && !defined(__ELF__) -#define LEADING_UNDERSCORE "_" -#else -#define LEADING_UNDERSCORE -#endif - #if defined(XP_WIN) #include #include @@ -84,61 +76,6 @@ CloseLibHandle(LibHandleType aLibHandle) FreeLibrary(aLibHandle); } -#elif defined(XP_MACOSX) -#include - -typedef const mach_header* LibHandleType; - -static LibHandleType -GetLibHandle(pathstr_t aDependentLib) -{ - LibHandleType libHandle = NSAddImage(aDependentLib, - NSADDIMAGE_OPTION_RETURN_ON_ERROR | - NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME); - if (!libHandle) { - NSLinkEditErrors linkEditError; - int errorNum; - const char* errorString; - const char* fileName; - NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString); - fprintf(stderr, "XPCOMGlueLoad error %d:%d for file %s:\n%s\n", - linkEditError, errorNum, fileName, errorString); - } - return libHandle; -} - -static NSFuncPtr -GetSymbol(LibHandleType aLibHandle, const char* aSymbol) -{ - // Try to use |NSLookupSymbolInImage| since it is faster than searching - // the global symbol table. If we couldn't get a mach_header pointer - // for the XPCOM dylib, then use |NSLookupAndBindSymbol| to search the - // global symbol table (this shouldn't normally happen, unless the user - // has called XPCOMGlueStartup(".") and relies on libxpcom.dylib - // already being loaded). - NSSymbol sym = nullptr; - if (aLibHandle) { - sym = NSLookupSymbolInImage(aLibHandle, aSymbol, - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | - NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - } else { - if (NSIsSymbolNameDefined(aSymbol)) { - sym = NSLookupAndBindSymbol(aSymbol); - } - } - if (!sym) { - return nullptr; - } - - return (NSFuncPtr)NSAddressOfSymbol(sym); -} - -static void -CloseLibHandle(LibHandleType aLibHandle) -{ - // we cannot unload dylibs on OS X -} - #else #include @@ -159,7 +96,12 @@ typedef void* LibHandleType; static LibHandleType GetLibHandle(pathstr_t aDependentLib) { - LibHandleType libHandle = dlopen(aDependentLib, RTLD_GLOBAL | RTLD_LAZY); + LibHandleType libHandle = dlopen(aDependentLib, + RTLD_GLOBAL | RTLD_LAZY +#ifdef XP_MACOSX + | RTLD_FIRST +#endif + ); if (!libHandle) { fprintf(stderr, "XPCOMGlueLoad error for file %s:\n%s\n", aDependentLib, dlerror()); @@ -385,7 +327,7 @@ XPCOMGlueLoad(const char* aXPCOMFile) GetFrozenFunctionsFunc sym = (GetFrozenFunctionsFunc)GetSymbol(sTop->libHandle, - LEADING_UNDERSCORE "NS_GetFrozenFunctions"); + "NS_GetFrozenFunctions"); if (!sym) { // No symbol found. XPCOMGlueUnload(); @@ -404,8 +346,7 @@ XPCOMGlueLoadXULFunctions(const nsDynamicFunctionLoad* aSymbols) nsresult rv = NS_OK; while (aSymbols->functionName) { char buffer[512]; - snprintf(buffer, sizeof(buffer), - LEADING_UNDERSCORE "%s", aSymbols->functionName); + snprintf(buffer, sizeof(buffer), "%s", aSymbols->functionName); *aSymbols->function = (NSFuncPtr)GetSymbol(sTop->libHandle, buffer); if (!*aSymbols->function) {