--- old/usr/src/cmd/sgs/libld/common/machrel.intel.c	2019-01-21 01:45:14.345356007 +0000
+++ new/usr/src/cmd/sgs/libld/common/machrel.intel.c	2019-01-21 01:45:14.361204175 +0000
@@ -415,11 +415,22 @@
 	0x90
 };
 
-static uchar_t tlsinstr_gd_ie_movgs[] = {
+static uchar_t tlsinstr_ld_le_movgs[] = {
 	/*
-	 *	movl %gs:0x0,%eax
+	 * 0x00 movl %gs:0x0,%eax
 	 */
-	0x65, 0xa1, 0x00, 0x00, 0x00, 00
+	0x65, 0xa1, 0x00, 0x00, 0x00, 0x00,
+};
+
+/*
+ * 0x00 nopl 0(%eax,%eax) -- the intel recommended 5-byte nop
+ * See Intel® 64 and IA-32 Architectures Software Developer’s Manual
+ *    Volume 2B: Instruction Set Reference, M-U
+ *    Table 4-12, Recommended Multi-Byte Sequence of NOP Instruction
+ */
+static uchar_t tlsinstr_nop5[] = {
+
+	0x0f, 0x1f, 0x44, 0x00, 0x00
 };
 
 #define	TLS_GD_IE_MOV	0x8b	/* movl opcode */
@@ -528,7 +539,8 @@
 	case R_386_TLS_GD_PLT:
 	case R_386_PLT32:
 		/*
-		 * Fixup done via the TLS_GD relocation
+		 * Fixup done via the TLS_GD/TLS_LDM relocation processing
+		 * and ld_reloc_plt() handling __tls_get_addr().
 		 */
 		DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
 		    R_386_NONE, arsp, ld_reloc_sym_name));
@@ -542,17 +554,10 @@
 		 * Transition:
 		 *	call __tls_get_addr()
 		 * to:
-		 *	nop
-		 *	nop
-		 *	nop
-		 *	nop
-		 *	nop
-		 */
-		*(offset - 1) = TLS_NOP;
-		*(offset) = TLS_NOP;
-		*(offset + 1) = TLS_NOP;
-		*(offset + 2) = TLS_NOP;
-		*(offset + 3) = TLS_NOP;
+		 *	nopl 0x0(%eax,%eax)
+		 */
+		(void) memcpy(offset - 1, tlsinstr_nop5,
+		    sizeof (tlsinstr_nop5));
 		return (FIX_DONE);
 
 	case R_386_TLS_LDM:
@@ -569,8 +574,17 @@
 		 *
 		 *  0x00 movl %gs:0, %eax
 		 */
-		(void) memcpy(offset - 2, tlsinstr_gd_ie_movgs,
-		    sizeof (tlsinstr_gd_ie_movgs));
+		(void) memcpy(offset - 2, tlsinstr_ld_le_movgs,
+		    sizeof (tlsinstr_ld_le_movgs));
+
+		/*
+		 *  We implicitly treat this as if a R_386_TLS_LDM_PLT for the
+		 *  __tls_get_addr call followed it as the GNU compiler
+		 *  doesn't generate one.  This is safe, because if one _does_
+		 *  exist we'll just write the nop again.
+		 */
+		(void) memcpy(offset + 4, tlsinstr_nop5,
+		    sizeof (tlsinstr_nop5));
 		return (FIX_DONE);
 
 	case R_386_TLS_LDO_32:
@@ -736,7 +750,7 @@
 	 */
 	REL_CACHE_TRAVERSE(&ofl->ofl_actrels, idx, rcbp, arsp) {
 		uchar_t		*addr;
-		Xword 		value;
+		Xword		value;
 		Sym_desc	*sdp;
 		const char	*ifl_name;
 		Xword		refaddr;
--- old/usr/src/cmd/sgs/packages/common/SUNWonld-README	2019-01-21 01:45:14.830283452 +0000
+++ new/usr/src/cmd/sgs/packages/common/SUNWonld-README	2019-01-21 01:45:14.846548738 +0000
@@ -71,7 +71,7 @@
 	http://sunsoftpatch.eng
 
     If it has been obsoleted, the patch will be in:
-    
+
         /net/on${RELEASE}-patch/on${RELEASE}/patches/${MACH}/obsolete
 
 
@@ -146,7 +146,7 @@
     4158744 patch 103627-02 causes core when RPATH has blank entry and
 	    dlopen/dlclose is used
 are incorporated in the following patches:
-	Solaris/SunOS 5.5.1_sparc	patch 103627-13	
+	Solaris/SunOS 5.5.1_sparc	patch 103627-13
 	Solaris/SunOS 5.5.1_x86		patch 103628-12
 --------------------------------------------------------------------------------
 All the above changes are incorporated in the following patches:
@@ -459,7 +459,7 @@
 4497270 The -zredlocsym option should not eliminate partially initialized local
 	symbols
 4496963 dumping an object with crle(1) that uses $ORIGIN can loose its
-	dependencies 
+	dependencies
 4499413 Sun linker orders of magnitude slower than gnu linker
 4461760 lazy loading libXm and libXt can fail.
 4469031 The partial initialized (local) symbols for intel platform is not
@@ -649,7 +649,7 @@
 4765536 crle: symbolic links can confuse alternative object configuration info
 4766815 ld -r of object the TLS data fails
 4770484 elfdump can not handle stripped archive file
-4770494 The ld command gives improper error message handling broken archive 
+4770494 The ld command gives improper error message handling broken archive
 4775738 overwriting output relocation table when 'ld -zignore' is used
 4778247 elfdump -e of core files fails
 4779976 elfdump dies on bad relocation entries
@@ -722,7 +722,7 @@
 --------------------------------------------------------------------------------
 All the above changes are incorporated in the following patches:
 	Solaris/SunOS 5.9_sparc		patch T112963-09
-	Solaris/SunOS 5.9_x86  		patch T113986-05
+	Solaris/SunOS 5.9_x86		patch T113986-05
 	Solaris/SunOS 5.8_sparc		patch T109147-25
 	Solaris/SunOS 5.8_x86		patch T109148-25
 --------------------------------------------------------------------------------
@@ -806,7 +806,7 @@
 4955802 /usr/ccs/bin/ld dumps core in process_reld()
 4964415 elfdump issues wrong relocation error message
 4966465 LD_NOAUXFLTR fails when object is both a standard and auxiliary filter
-4973865 the link-editor does not scale properly when linking objects with 
+4973865 the link-editor does not scale properly when linking objects with
 	lots of syms
 4975598 SHT_SUNW_ANNOTATE section relocation not resolved
 4974828 nss_files nss_compat r_mt tests randomly segfaulting
@@ -935,7 +935,7 @@
 6195521 64-bit moe(1) missed the train
 6198358 AMD64: bad eh_frame_hdr data when C and C++ mixed in a.out
 6204123 ld.so.1: symbol lookup fails even after lazy loading fallback
-6207495 UNIX98/UNIX03 vsx namespace violation DYNL.hdr/misc/dlfcn/T.dlfcn 
+6207495 UNIX98/UNIX03 vsx namespace violation DYNL.hdr/misc/dlfcn/T.dlfcn
 	14 Failed
 6217285 ctfmerge crashed during full onnv build
 --------------------------------------------------------------------------------
@@ -1350,7 +1350,7 @@
 	PSARC/2007/026 ELF symbol sort sections
 6518480 ld -melf_i386 doesn't complain (D)
 6519951 bfu is just another word for exit today (RPATH -> RUNPATH conversion
-	bites us) (D) 
+	bites us) (D)
 6521504 ld: hardware capabilities processing from relocatables objects needs
 	hardening.
 6518322 Some ELF utilities need updating for .SUNW_ldynsym section (D)
@@ -1661,3 +1661,4 @@
 7323	ld(1) -zignore can erroneously discard init and fini arrays as unreferenced
 7594	ld -zaslr should accept Solaris-compatible values
 8616	ld has trouble parsing -z options specified with -Wl
+10267	ld and GCC disagree about i386 local dynamic TLS
