Bug 370766: support 64-bit Mac OS X x86_64, which uses the dlopen functions
authorwtc%google.com
Sat, 13 Dec 2008 19:34:10 +0000
changeset 4018 e64b976f244bae4612728fd249fffc482df88efb
parent 4017 c28dfb5af1fd126b1a583c4448413b4f911186ae
child 4019 cf3860d376be8c0c25e767c727020dd85fed9a20
push idunknown
push userunknown
push dateunknown
bugs370766
Bug 370766: support 64-bit Mac OS X x86_64, which uses the dlopen functions (declared in <dlfcn.h>) for dynamic library loading, and doesn't support CFBundles. Contributed by Glen Beasley <glen.beasley@sun.com>. r=wtc.
pr/src/linking/prlink.c
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -39,17 +39,17 @@
 #include "primpl.h"
 
 #include <string.h>
 
 #ifdef XP_BEOS
 #include <image.h>
 #endif
 
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
 #include <CodeFragments.h>
 #include <TextUtils.h>
 #include <Types.h>
 #include <Aliases.h>
 #include <CFURL.h>
 #include <CFBundle.h>
 #include <CFString.h>
 #include <CFDictionary.h>
@@ -150,18 +150,18 @@ struct _imcb *IAC$GL_IMAGE_LIST = NULL;
 
 #define MAX_DEVNAM 64
 #define MAX_FILNAM 255
 #endif  /* VMS */
 
 /*
  * On these platforms, symbols have a leading '_'.
  */
-#if defined(SUNOS4) || defined(DARWIN) || defined(NEXTSTEP) \
-    || defined(WIN16) || defined(XP_OS2) \
+#if defined(SUNOS4) || (defined(DARWIN) && defined(USE_MACH_DYLD)) \
+    || defined(NEXTSTEP) || defined(WIN16) || defined(XP_OS2) \
     || ((defined(OPENBSD) || defined(NETBSD)) && !defined(__ELF__))
 #define NEED_LEADING_UNDERSCORE
 #endif
 
 #define PR_LD_PATHW 0x8000  /* for PR_LibSpec_PathnameU */
 
 /************************************************************************/
 
@@ -174,17 +174,17 @@ struct PRLibrary {
 #ifdef XP_PC
 #ifdef XP_OS2
     HMODULE                     dlh;
 #else
     HINSTANCE                   dlh;
 #endif
 #endif
 
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
     CFragConnectionID           connection;
     CFBundleRef                 bundle;
     Ptr                         main;
     CFMutableDictionaryRef      wrappers;
     const struct mach_header*   image;
 #endif
 
 #ifdef XP_UNIX
@@ -624,17 +624,17 @@ pr_LoadMachDyldModule(const char *name)
                 h = NULL;
             }
         }
     }
     return h;
 }
 #endif
 
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
 
 /*
 ** macLibraryLoadProc is a function definition for a Mac shared library
 ** loading method. The "name" param is the same full or partial pathname
 ** that was passed to pr_LoadLibraryByPathName. The function must fill
 ** in the fields of "lm" which apply to its library type. Returns
 ** PR_SUCCESS if successful.
 */
@@ -783,17 +783,17 @@ pr_LoadViaDyld(const char *name, PRLibra
             PR_LOG(_pr_linker_lm, PR_LOG_MIN, 
                    ("LoadMachDyldModule error %d:%d for file %s:\n%s",
                     linkEditError, errorNum, fileName, errorString));
         }
     }
     return (lm->dlh != NULL || lm->image != NULL) ? PR_SUCCESS : PR_FAILURE;
 }
 
-#endif /* XP_MACOSX */
+#endif /* XP_MACOSX && USE_MACH_DYLD */
 
 #ifdef WIN95
 static HMODULE WINAPI
 EmulateLoadLibraryW(LPCWSTR lpLibFileName)
 {
     HMODULE h;
     char nameA[MAX_PATH];
 
@@ -921,17 +921,17 @@ pr_LoadLibraryByPathname(const char *nam
     lm->name = strdup(name);
 #endif
     lm->dlh = h;
     lm->next = pr_loadmap;
     pr_loadmap = lm;
     }
 #endif /* WIN32 || WIN16 */
 
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
     {
     int     i;
     PRStatus status;
 
     static const macLibraryLoadProc loadProcs[] = {
 #ifdef __ppc__
         pr_LoadViaDyld, pr_LoadCFBundle, pr_LoadViaCFM
 #else  /* __ppc__ */
@@ -949,17 +949,17 @@ pr_LoadLibraryByPathname(const char *nam
         goto unlock;        
     }
     lm->name = strdup(name);
     lm->next = pr_loadmap;
     pr_loadmap = lm;
     }
 #endif
 
-#if defined(XP_UNIX) && !defined(XP_MACOSX)
+#if defined(XP_UNIX) && !(defined(XP_MACOSX) && defined(USE_MACH_DYLD))
 #ifdef HAVE_DLL
     {
 #if defined(USE_DLFCN)
 #ifdef NTO
     /* Neutrino needs RTLD_GROUP to load Netscape plugins. (bug 71179) */
     int dl_flags = RTLD_GROUP;
 #elif defined(AIX)
     /* AIX needs RTLD_MEMBER to load an archive member.  (bug 228899) */
@@ -1013,17 +1013,17 @@ pr_LoadLibraryByPathname(const char *nam
         goto unlock;
     }
     lm->name = strdup(name);
     lm->dlh = h;
     lm->next = pr_loadmap;
     pr_loadmap = lm;
     }
 #endif /* HAVE_DLL */
-#endif /* XP_UNIX */
+#endif /* XP_UNIX && !(XP_MACOSX && USE_MACH_DYLD) */
 
     lm->refCount = 1;
 
 #ifdef XP_BEOS
     {
         image_info info;
         int32 cookie = 0;
         image_id imageid = B_ERROR;
@@ -1294,17 +1294,17 @@ PR_UnloadLibrary(PRLibrary *lib)
 #endif /* XP_UNIX */
 #ifdef XP_PC
     if (lib->dlh) {
         FreeLibrary((HINSTANCE)(lib->dlh));
         lib->dlh = (HINSTANCE)NULL;
     }
 #endif  /* XP_PC */
 
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
     /* Close the connection */
     if (lib->connection)
         CloseConnection(&(lib->connection));
     if (lib->bundle)
         CFRelease(lib->bundle);
     if (lib->wrappers)
         CFRelease(lib->wrappers);
     /* No way to unload an image (lib->image) */
@@ -1393,17 +1393,17 @@ pr_FindSymbolInLib(PRLibrary *lm, const 
     }
 #endif
 #endif  /* XP_OS2 */
 
 #if defined(WIN32) || defined(WIN16)
     f = GetProcAddress(lm->dlh, name);
 #endif  /* WIN32 || WIN16 */
 
-#ifdef XP_MACOSX
+#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
 /* add this offset to skip the leading underscore in name */
 #define SYM_OFFSET 1
     if (lm->bundle) {
         CFStringRef nameRef = CFStringCreateWithCString(NULL, name + SYM_OFFSET, kCFStringEncodingASCII);
         if (nameRef) {
             f = CFBundleGetFunctionPointerForName(lm->bundle, nameRef);
             CFRelease(nameRef);
         }
@@ -1434,17 +1434,17 @@ pr_FindSymbolInLib(PRLibrary *lm, const 
                  NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
                  | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
         if (symbol != NULL)
             f = NSAddressOfSymbol(symbol);
         else
             f = NULL;
     }
 #undef SYM_OFFSET
-#endif /* XP_MACOSX */
+#endif /* XP_MACOSX && USE_MACH_DYLD */
 
 #ifdef XP_BEOS
     if( B_NO_ERROR != get_image_symbol( (image_id)lm->dlh, name, B_SYMBOL_TYPE_TEXT, &f ) ) {
         f = NULL;
     }
 #endif
 
 #ifdef XP_UNIX
@@ -1622,17 +1622,18 @@ PR_LoadStaticLibrary(const char *name, c
     PR_ExitMonitor(pr_linker_lock);
     return result;
 }
 
 PR_IMPLEMENT(char *)
 PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr)
 {
 #if defined(USE_DLFCN) && (defined(SOLARIS) || defined(FREEBSD) \
-        || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__))
+        || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
+        || defined(DARWIN))
     Dl_info dli;
     char *result;
 
     if (dladdr((void *)addr, &dli) == 0) {
         PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, _MD_ERRNO());
         DLLErrorInternal(_MD_ERRNO());
         return NULL;
     }