1diff --git nss/cmd/shlibsign/shlibsign.c nss/cmd/shlibsign/shlibsign.c
2index ad8f3b84e..74676d039 100644
3--- nss/cmd/shlibsign/shlibsign.c
4+++ nss/cmd/shlibsign/shlibsign.c
5@@ -875,6 +875,8 @@ main(int argc, char **argv)
6 goto cleanup;
7 }
8 lib = PR_LoadLibrary(libname);
9+ if (!lib)
10+ lib = PR_LoadLibrary(NIX_NSS_LIBDIR"libsoftokn3.so");
11 assert(lib != NULL);
12 if (!lib) {
13 PR_fprintf(PR_STDERR, "loading softokn3 failed");
14diff --git nss/lib/pk11wrap/pk11load.c nss/lib/pk11wrap/pk11load.c
15index 119c8c512..720d39ccc 100644
16--- nss/lib/pk11wrap/pk11load.c
17+++ nss/lib/pk11wrap/pk11load.c
18@@ -486,6 +486,15 @@ secmod_LoadPKCS11Module(SECMODModule *mod, SECMODModule **oldModule)
19 #else
20 library = PR_LoadLibrary(mod->dllName);
21 #endif // defined(_WIN32)
22+#ifndef NSS_STATIC_SOFTOKEN
23+ if ((library == NULL) &&
24+ !rindex(mod->dllName, PR_GetDirectorySeparator())) {
25+ library = PORT_LoadLibraryFromOrigin(my_shlib_name,
26+ (PRFuncPtr) &softoken_LoadDSO,
27+ mod->dllName);
28+ }
29+#endif
30+
31 mod->library = (void *)library;
32
33 if (library == NULL) {
34diff --git nss/lib/util/secload.c nss/lib/util/secload.c
35index 1cebae4e2..9194bb761 100644
36--- nss/lib/util/secload.c
37+++ nss/lib/util/secload.c
38@@ -70,9 +70,14 @@ loader_LoadLibInReferenceDir(const char* referencePath, const char* name)
39
40 /* Remove the trailing filename from referencePath and add the new one */
41 c = strrchr(referencePath, PR_GetDirectorySeparator());
42+ if (!c) { /* referencePath doesn't contain a / means that dladdr gave us argv[0]
43+ * and program was called from $PATH. Hack to get libs from NIX_NSS_LIBDIR */
44+ referencePath = NIX_NSS_LIBDIR;
45+ c = (char*) &referencePath[sizeof(NIX_NSS_LIBDIR) - 1]; /* last / */
46+ }
47 if (c) {
48 size_t referencePathSize = 1 + c - referencePath;
49- fullName = (char*)PORT_Alloc(strlen(name) + referencePathSize + 1);
50+ fullName = (char*) PORT_Alloc(strlen(name) + referencePathSize + 5);
51 if (fullName) {
52 memcpy(fullName, referencePath, referencePathSize);
53 strcpy(fullName + referencePathSize, name);
54@@ -82,6 +87,11 @@ loader_LoadLibInReferenceDir(const char* referencePath, const char* name)
55 #endif
56 libSpec.type = PR_LibSpec_Pathname;
57 libSpec.value.pathname = fullName;
58+ if ((referencePathSize >= 4) &&
59+ (strncmp(fullName + referencePathSize - 4, "bin", 3) == 0)) {
60+ memcpy(fullName + referencePathSize -4, "lib", 3);
61+ }
62+ strcpy(fullName + referencePathSize, name);
63 dlh = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL
64 #ifdef PR_LD_ALT_SEARCH_PATH
65 /* allow library's dependencies to be found in the same directory
66@@ -89,6 +99,10 @@ loader_LoadLibInReferenceDir(const char* referencePath, const char* name)
67 | PR_LD_ALT_SEARCH_PATH
68 #endif
69 );
70+ if (!dlh) {
71+ strcpy(fullName + referencePathSize, name);
72+ dlh = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL);
73+ }
74 PORT_Free(fullName);
75 }
76 }