$OpenBSD: patch-mozilla_nsprpub_pr_src_linking_prlink_c,v 1.4 2012/09/17 20:00:09 landry Exp $
If dlopen() fails, retry with everything stripped after .so
https://bugzilla.mozilla.org/show_bug.cgi?id=650772
--- mozilla/nsprpub/pr/src/linking/prlink.c.orig	Tue Mar  6 14:14:10 2012
+++ mozilla/nsprpub/pr/src/linking/prlink.c	Sun Sep  2 00:30:56 2012
@@ -11,6 +11,10 @@
 #include <image.h>
 #endif
 
+#if defined(OpenBSD)
+#include <sys/param.h> /* for MAXPATHLEN */
+#endif
+
 #if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
 #include <Carbon/Carbon.h>
 #include <CoreFoundation/CoreFoundation.h>
@@ -777,6 +781,10 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flag
 #else
     int dl_flags = 0;
 #endif
+#if defined(OpenBSD)
+    char sname[MAXPATHLEN];
+    char *c;
+#endif
     void *h = NULL;
 
     if (flags & PR_LD_LAZY) {
@@ -801,7 +809,18 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flag
         }
 #else
     h = dlopen(name, dl_flags);
+#if defined(OPENBSD)
+    /* On OpenBSD, we don't know what can be major.minor in libfoo.so.major.minor */
+    /* but ld.so is smart enough to open the correct lib when asked for libfoo.so */
+    /* so if the previous dlopen() failed, let's strip what's after .so and retry */
+    strncpy(sname, name, MAXPATHLEN);
+    if (!h) {
+        if ((c = strstr(sname,".so")) != NULL)
+            c[3] = '\0';
+        h = dlopen(sname, dl_flags);
+    }
 #endif
+#endif
 #elif defined(USE_HPSHL)
     int shl_flags = 0;
     shl_t h;
@@ -832,7 +851,11 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flag
         PR_DELETE(lm);
         goto unlock;
     }
+#if defined(OPENBSD)
+    lm->name = strdup(sname);
+#else
     lm->name = strdup(name);
+#endif
     lm->dlh = h;
     lm->next = pr_loadmap;
     pr_loadmap = lm;
