1diff -ru -x '*~' -x '*.orig' -x '*.rej' nss/cmd/shlibsign/shlibsign.c nss/cmd/shlibsign/shlibsign.c
2--- nss/cmd/shlibsign/shlibsign.c 2017-01-04 15:24:24.000000000 +0100
3+++ nss/cmd/shlibsign/shlibsign.c 2017-01-24 14:43:31.030420852 +0100
4@@ -875,6 +875,8 @@
5 goto cleanup;
6 }
7 lib = PR_LoadLibrary(libname);
8+ if (!lib)
9+ lib = PR_LoadLibrary(NIX_NSS_LIBDIR"libsoftokn3.so");
10 assert(lib != NULL);
11 if (!lib) {
12 PR_fprintf(PR_STDERR, "loading softokn3 failed");
13diff -ru -x '*~' -x '*.orig' -x '*.rej' nss/coreconf/config.mk nss/coreconf/config.mk
14--- nss/coreconf/config.mk 2017-01-04 15:24:24.000000000 +0100
15+++ nss/coreconf/config.mk 2017-01-24 14:43:47.989432372 +0100
16@@ -208,3 +208,6 @@
17 # exported symbols, which causes problem when NSS is built as part of Mozilla.
18 # So we add a NSS_SSL_ENABLE_ZLIB variable to allow Mozilla to turn this off.
19 NSS_SSL_ENABLE_ZLIB = 1
20+
21+# Nix specific stuff.
22+DEFINES += -DNIX_NSS_LIBDIR=\"$(out)/lib/\"
23diff -ru -x '*~' -x '*.orig' -x '*.rej' nss/lib/pk11wrap/pk11load.c nss/lib/pk11wrap/pk11load.c
24--- nss/lib/pk11wrap/pk11load.c 2017-01-04 15:24:24.000000000 +0100
25+++ nss/lib/pk11wrap/pk11load.c 2017-01-24 14:45:06.883485652 +0100
26@@ -440,6 +440,13 @@
27 * unload the library if anything goes wrong from here on out...
28 */
29 library = PR_LoadLibrary(mod->dllName);
30+ if ((library == NULL) &&
31+ !rindex(mod->dllName, PR_GetDirectorySeparator())) {
32+ library = PORT_LoadLibraryFromOrigin(my_shlib_name,
33+ (PRFuncPtr) &softoken_LoadDSO,
34+ mod->dllName);
35+ }
36+
37 mod->library = (void *)library;
38
39 if (library == NULL) {
40diff -ru -x '*~' -x '*.orig' -x '*.rej' nss/lib/util/secload.c nss/lib/util/secload.c
41--- nss/lib/util/secload.c 2017-01-04 15:24:24.000000000 +0100
42+++ nss/lib/util/secload.c 2017-01-24 14:43:31.030420852 +0100
43@@ -70,9 +70,14 @@
44
45 /* Remove the trailing filename from referencePath and add the new one */
46 c = strrchr(referencePath, PR_GetDirectorySeparator());
47+ if (!c) { /* referencePath doesn't contain a / means that dladdr gave us argv[0]
48+ * and program was called from $PATH. Hack to get libs from NIX_NSS_LIBDIR */
49+ referencePath = NIX_NSS_LIBDIR;
50+ c = (char*) &referencePath[sizeof(NIX_NSS_LIBDIR) - 1]; /* last / */
51+ }
52 if (c) {
53 size_t referencePathSize = 1 + c - referencePath;
54- fullName = (char*)PORT_Alloc(strlen(name) + referencePathSize + 1);
55+ fullName = (char*) PORT_Alloc(strlen(name) + referencePathSize + 5);
56 if (fullName) {
57 memcpy(fullName, referencePath, referencePathSize);
58 strcpy(fullName + referencePathSize, name);
59@@ -82,6 +87,11 @@
60 #endif
61 libSpec.type = PR_LibSpec_Pathname;
62 libSpec.value.pathname = fullName;
63+ if ((referencePathSize >= 4) &&
64+ (strncmp(fullName + referencePathSize - 4, "bin", 3) == 0)) {
65+ memcpy(fullName + referencePathSize -4, "lib", 3);
66+ }
67+ strcpy(fullName + referencePathSize, name);
68 dlh = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL
69 #ifdef PR_LD_ALT_SEARCH_PATH
70 /* allow library's dependencies to be found in the same directory
71@@ -89,6 +99,10 @@
72 | PR_LD_ALT_SEARCH_PATH
73 #endif
74 );
75+ if (! dlh) {
76+ strcpy(fullName + referencePathSize, name);
77+ dlh = PR_LoadLibraryWithFlags(libSpec, PR_LD_NOW | PR_LD_LOCAL);
78+ }
79 PORT_Free(fullName);
80 }
81 }