1--- a/a/nspr/configure	2017-08-29 23:44:13.686045013 +0530
2+++ b/b/nspr/configure	2017-08-29 23:46:53.774768655 +0530
3@@ -7034,7 +7034,7 @@
4     PR_MD_CSRCS=linux.c
5     MKSHLIB='$(CC) $(DSO_LDOPTS) -o $@'
6     DSO_CFLAGS=-fPIC
7-    DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@)'
8+    DSO_LDOPTS='-shared -Wl,-soname -Wl,$(notdir $@) $(if $(filter-out $(OS),ANDROID),-Wl$(COMMA)-z$(COMMA)origin -Wl$(COMMA)-rpath$(COMMA)\$$ORIGIN)'
9     _OPTIMIZE_FLAGS=-O2
10     _DEBUG_FLAGS="-g -fno-inline"  # most people on linux use gcc/gdb, and that
11                                    # combo is not yet good at debugging inlined
12--- a/nss.orig/nspr/pr/src/misc/prnetdb.c	2017-08-29 23:44:13.690045031 +0530
13+++ b/nss/nspr/pr/src/misc/prnetdb.c	2017-08-29 23:47:03.810814019 +0530
14@@ -438,7 +438,7 @@
15     char *buf = *bufp;
16     PRIntn buflen = *buflenp;
17
18-    if (align && ((long)buf & (align - 1))) {
19+    if (align && ((ptrdiff_t)buf & (align - 1))) {
20         PRIntn skip = align - ((ptrdiff_t)buf & (align - 1));
21         if (buflen < skip) {
22             return 0;
23--- a/a/nss/cmd/platlibs.mk	2017-08-29 23:44:13.554044416 +0530
24+++ b/b/nss/cmd/platlibs.mk	2017-08-29 23:46:09.638569150 +0530
25@@ -10,17 +10,22 @@
26
27 ifeq ($(OS_ARCH), SunOS)
28 ifeq ($(USE_64), 1)
29-EXTRA_SHARED_LIBS += -R '$$ORIGIN/../lib:/usr/lib/mps/secv1/64:/usr/lib/mps/64'
30+#In OOo we would probable put the executables next to libs
31+EXTRA_SHARED_LIBS += -R '$$ORIGIN'
32 else
33-EXTRA_SHARED_LIBS += -R '$$ORIGIN/../lib:/usr/lib/mps/secv1:/usr/lib/mps'
34+EXTRA_SHARED_LIBS += -R '$$ORIGIN'
35 endif
36 endif
37
38+ifeq ($(OS_ARCH), FreeBSD)
39+EXTRA_SHARED_LIBS += -Wl,-z,origin -Wl,-rpath,'$$ORIGIN'
40+endif
41+
42 ifeq ($(OS_ARCH), Linux)
43 ifeq ($(USE_64), 1)
44-EXTRA_SHARED_LIBS += -Wl,-rpath,'$$ORIGIN/../lib64:/opt/sun/private/lib64:$$ORIGIN/../lib'
45+EXTRA_SHARED_LIBS += -Wl,-z,origin -Wl,-rpath,'$$ORIGIN'
46 else
47-EXTRA_SHARED_LIBS += -Wl,-rpath,'$$ORIGIN/../lib:/opt/sun/private/lib'
48+EXTRA_SHARED_LIBS += -Wl,-z,origin -Wl,-rpath,'$$ORIGIN'
49 endif
50 endif
51
52--- a/nss.org/nss/coreconf/arch.mk	2017-08-29 23:44:13.646044832 +0530
53+++ b/nss/nss/coreconf/arch.mk	2017-08-29 23:45:51.494487134 +0530
54@@ -305,11 +305,17 @@
55     OBJDIR_NAME_COMPILER = $(COMPILER_TAG)
56 endif
57 OBJDIR_NAME_BASE = $(OS_TARGET)$(OS_RELEASE)$(CPU_TAG)$(OBJDIR_NAME_COMPILER)$(LIBC_TAG)$(IMPL_STRATEGY)$(OBJDIR_TAG)
58-OBJDIR_NAME = $(OBJDIR_NAME_BASE).OBJ
59+# OBJDIR_NAME is used to build the directory containing the built objects, for
60+# example mozilla/dist/Linux2.6_x86_glibc_PTH_DBG.OBJ
61+# We need to deliver the contents of that folder into instdir. To make that
62+# easier in the makefile we rename this directory to "out".
63+#OBJDIR_NAME = $(OBJDIR_NAME_BASE).OBJ
64+OBJDIR_NAME = out
65
66
67 ifeq (,$(filter-out WIN%,$(OS_TARGET)))
68-ifndef BUILD_OPT
69+ifdef THIS_HAS_BEEN_DISABLED_TO_GET_out
70+
71 #
72 # Define USE_DEBUG_RTL if you want to use the debug runtime library
73 # (RTL) in the debug build
74--- a/nss.org/nss/coreconf/FreeBSD.mk	2017-08-29 23:44:13.642044814 +0530
75+++ b/nss/nss/coreconf/FreeBSD.mk	2017-08-29 23:45:20.850348615 +0530
76@@ -25,6 +25,7 @@
77
78 DSO_CFLAGS		= -fPIC
79 DSO_LDOPTS		= -shared -Wl,-soname -Wl,$(notdir $@)
80+DSO_LDOPTS		+= -Wl,-z,origin '-Wl,-rpath,$$ORIGIN'
81
82 #
83 # The default implementation strategy for FreeBSD is pthreads.
84--- a/nss.org/nss/coreconf/Linux.mk	2017-08-29 23:44:13.642044814 +0530
85+++ b/nss/nss/coreconf/Linux.mk	2017-08-29 23:47:26.318915759 +0530
86@@ -147,7 +147,7 @@
87 # Also, -z defs conflicts with Address Sanitizer, which emits relocations
88 # against the libsanitizer runtime built into the main executable.
89 ZDEFS_FLAG		= -Wl,-z,defs
90-DSO_LDOPTS		+= $(if $(findstring 2.11.90.0.8,$(shell ld -v)),,$(ZDEFS_FLAG))
91+DSO_LDOPTS		+= $(if $(findstring 2.11.90.0.8,$(shell ld -v)),,$(ZDEFS_FLAG)) $(if $(filter-out $(OS),ANDROID),-Wl$(COMMA)-z$(COMMA)origin '-Wl$(COMMA)-rpath$(COMMA)$$ORIGIN')
92 LDFLAGS			+= $(ARCHFLAG) -z noexecstack
93
94 # On Maemo, we need to use the -rpath-link flag for even the standard system
95@@ -177,8 +177,13 @@
96 endif
97 endif
98
99+ifneq ($(SYSTEM_ZLIB),)
100+# Currently (3.12.4) only the tools modutil and signtool are linked with libz
101+# If USE_SYSTEM_ZLIB is not set then the tools link statically libzlib.a which
102+# is also built in nss.
103 USE_SYSTEM_ZLIB = 1
104 ZLIB_LIBS = -lz
105+endif
106
107 # The -rpath '$$ORIGIN' linker option instructs this library to search for its
108 # dependencies in the same directory where it resides.
109--- a/nss.org/nss/coreconf/rules.mk	2017-08-29 23:44:13.646044832 +0530
110+++ b/nss/nss/coreconf/rules.mk	2017-08-29 23:47:37.442966042 +0530
111@@ -261,7 +261,7 @@
112 ifeq (,$(filter-out _WIN%,$(NS_USE_GCC)_$(OS_TARGET)))
113 	$(AR) $(subst /,\\,$(OBJS))
114 else
115-	$(AR) $(OBJS)
116+	$(AR) cr $@ $(OBJS)
117 endif
118 	$(RANLIB) $@
119
120--- a/nss.org/nss/coreconf/SunOS5.mk	2017-08-29 23:44:13.646044832 +0530
121+++ b/nss/nss/coreconf/SunOS5.mk	2017-08-29 23:45:00.902258445 +0530
122@@ -48,8 +48,11 @@
123 	    # OPTIMIZER += -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer
124 	endif
125 else
126-	CC         = cc
127-	CCC        = CC
128+	# CC is taken from environment automatically.
129+	#	CC         = cc
130+	# Use CXX from environment.
131+	#	CCC        = CC
132+    CCC       = $(CXX)
133 	ASFLAGS   += -Wa,-P
134 	OS_CFLAGS += $(NOMD_OS_CFLAGS) $(ARCHFLAG)
135 	ifndef BUILD_OPT
136--- a/nss.org/nss/coreconf/Werror.mk	2017-08-29 23:44:13.646044832 +0530
137+++ b/nss/nss/coreconf/Werror.mk	2017-08-29 23:44:23.994091608 +0530
138@@ -94,7 +94,8 @@
139     endif #ndef NSS_ENABLE_WERROR
140
141     ifeq ($(NSS_ENABLE_WERROR),1)
142-      WARNING_CFLAGS += -Werror
143+      # We do not treat warnings as errors.
144+	  # WARNING_CFLAGS += -Werror
145     else
146       # Old versions of gcc (< 4.8) don't support #pragma diagnostic in functions.
147       # Use this to disable use of that #pragma and the warnings it suppresses.
148--- a/nss.org/nss/Makefile	2017-08-29 23:44:13.402043729 +0530
149+++ b/nss/nss/Makefile	2017-08-29 23:44:39.774162939 +0530
150@@ -1,3 +1,5 @@
151+export AR
152+export RANLIB
153 #! gmake
154 #
155 # This Source Code Form is subject to the terms of the Mozilla Public
156