--- old/usr/src/cmd/sgs/libld/common/machrel.amd.c	2019-02-28 22:40:42.550342340 +0000
+++ new/usr/src/cmd/sgs/libld/common/machrel.amd.c	2019-02-28 22:40:42.570207008 +0000
@@ -740,7 +740,6 @@
 		DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
 		    R_AMD64_TPOFF32, arsp, ld_reloc_sym_name));
 		arsp->rel_rtype = R_AMD64_TPOFF32;
-		arsp->rel_raddend = 0;
 		return (FIX_RELOC);
 	}
 
@@ -764,7 +763,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-02-28 22:40:43.107275482 +0000
+++ new/usr/src/cmd/sgs/packages/common/SUNWonld-README	2019-02-28 22:40:43.130349184 +0000
@@ -1662,3 +1662,4 @@
 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
+10471	ld(1) amd64 LD->LE TLS transition causes memory corruption
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/README	2019-02-28 22:40:43.721906630 +0000
+++ /dev/null	2019-02-28 22:40:43.000000000 +0000
@@ -1,9 +0,0 @@
-This tests the x64 link-editor's handling of Initial Executable TLS sequences.
-
-The original C source files are in orig/ but unused, since we need to avoid
-any changes to the compiler influencing our tests.
-
-    % ksh x64-ie-test.sh /path/to/proto/root
-    pass: addq-->leaq 1
-    ...
-    pass: bad insn sequence
--- /dev/null	2019-02-28 22:40:43.000000000 +0000
+++ new/usr/src/pkg/manifests/system-test-elftest.mf	2019-02-28 22:40:43.905109321 +0000
@@ -0,0 +1,57 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2018, Richard Lowe.
+#
+
+set name=pkg.fmri value=pkg:/system/test/elftest@$(PKGVERS)
+set name=pkg.description value="ELF Unit Tests"
+set name=pkg.summary value="ELF Test Suite"
+set name=info.classification \
+    value=org.opensolaris.category.2008:Development/System
+set name=variant.arch value=$(ARCH)
+dir path=opt/elf-tests
+dir path=opt/elf-tests/bin
+dir path=opt/elf-tests/runfiles
+dir path=opt/elf-tests/tests
+dir path=opt/elf-tests/tests/assert-deflib
+dir path=opt/elf-tests/tests/tls
+dir path=opt/elf-tests/tests/tls/amd64
+dir path=opt/elf-tests/tests/tls/amd64/ie
+dir path=opt/elf-tests/tests/tls/amd64/ld
+dir path=opt/elf-tests/tests/tls/i386
+dir path=opt/elf-tests/tests/tls/i386/ld
+file path=opt/elf-tests/README mode=0444
+file path=opt/elf-tests/bin/elftest mode=0555
+file path=opt/elf-tests/runfiles/default.run mode=0444
+file path=opt/elf-tests/tests/assert-deflib/link.c mode=0444
+file path=opt/elf-tests/tests/assert-deflib/test-deflib mode=0555
+file path=opt/elf-tests/tests/tls/amd64/ie/Makefile.test mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ie/amd64-ie-test mode=0555
+file path=opt/elf-tests/tests/tls/amd64/ie/style1-func-with-r12.s mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ie/style1-func-with-r13.s mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ie/style1-func.s mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ie/style1-main.s mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ie/style2-with-badness.s mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ie/style2-with-r12.s mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ie/style2-with-r13.s mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ie/style2.s mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ld/Makefile.test mode=0444
+file path=opt/elf-tests/tests/tls/amd64/ld/amd64-ld-test mode=0555
+file path=opt/elf-tests/tests/tls/amd64/ld/ld-with-addend.s mode=0444
+file path=opt/elf-tests/tests/tls/i386/ld/Makefile.test mode=0444
+file path=opt/elf-tests/tests/tls/i386/ld/half-ldm.s mode=0444
+file path=opt/elf-tests/tests/tls/i386/ld/i386-ld-test mode=0555
+license lic_CDDL license=lic_CDDL
+depend fmri=developer/linker type=require
+depend fmri=developer/object-file type=require
+depend fmri=system/test/testrunner type=require
--- old/usr/src/test/Makefile	2019-02-28 22:40:44.133155543 +0000
+++ new/usr/src/test/Makefile	2019-02-28 22:40:44.150999319 +0000
@@ -16,7 +16,14 @@
 
 .PARALLEL: $(SUBDIRS)
 
-SUBDIRS = libc-tests crypto-tests os-tests test-runner util-tests zfs-tests \
-	smbclient-tests
+SUBDIRS = \
+	crypto-tests \
+	elf-tests \
+	libc-tests \
+	os-tests \
+	smbclient-tests \
+	test-runner \
+	util-tests \
+	zfs-tests
 
 include Makefile.com
--- /dev/null	2019-02-28 22:40:44.000000000 +0000
+++ new/usr/src/test/elf-tests/Makefile	2019-02-28 22:40:44.579894116 +0000
@@ -0,0 +1,20 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+.PARALLEL: $(SUBDIRS)
+
+SUBDIRS = cmd doc runfiles tests
+
+include $(SRC)/test/Makefile.com
--- /dev/null	2019-02-28 22:40:44.000000000 +0000
+++ new/usr/src/test/elf-tests/cmd/Makefile	2019-02-28 22:40:44.791312920 +0000
@@ -0,0 +1,38 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+include $(SRC)/test/Makefile.com
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+ROOTBIN = $(ROOTOPTPKG)/bin
+
+PROGS = elftest
+
+CMDS = $(PROGS:%=$(ROOTBIN)/%)
+$(CMDS) := FILEMODE = 0555
+
+all lint clean clobber:
+
+install: $(CMDS)
+
+$(CMDS): $(ROOTBIN)
+
+$(ROOTBIN):
+	$(INS.dir)
+
+$(ROOTBIN)/%: %.ksh
+	$(INS.rename)
--- /dev/null	2019-02-28 22:40:45.000000000 +0000
+++ new/usr/src/test/elf-tests/cmd/elftest.ksh	2019-02-28 22:40:45.011822236 +0000
@@ -0,0 +1,49 @@
+#!/usr/bin/ksh
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+ELF_TESTS="/opt/elf-tests"
+runner="/opt/test-runner/bin/run"
+
+function fail
+{
+	echo $1
+	exit ${2:-1}
+}
+
+function find_runfile
+{
+	typeset distro=default
+
+	[[ -n $distro ]] && echo $ELF_TESTS/runfiles/$distro.run
+}
+
+while getopts c: c; do
+	case $c in
+	'c')
+		runfile=$OPTARG
+		[[ -f $runfile ]] || fail "Cannot read file: $runfile"
+		;;
+	esac
+done
+shift $((OPTIND - 1))
+
+[[ -z $runfile ]] && runfile=$(find_runfile)
+[[ -z $runfile ]] && fail "Couldn't determine distro"
+
+$runner -c $runfile
+
+exit $?
--- /dev/null	2019-02-28 22:40:45.000000000 +0000
+++ new/usr/src/test/elf-tests/doc/Makefile	2019-02-28 22:40:45.233582360 +0000
@@ -0,0 +1,36 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+include $(SRC)/Makefile.master
+
+READMES = README
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+
+FILES = $(READMES:%=$(ROOTOPTPKG)/%)
+$(FILES) := FILEMODE = 0444
+
+all: $(READMES)
+
+install: $(ROOTOPTPKG) $(FILES)
+
+clean lint clobber:
+
+$(ROOTOPTPKG):
+	$(INS.dir)
+
+$(ROOTOPTPKG)/%: %
+	$(INS.file)
--- /dev/null	2019-02-28 22:40:45.000000000 +0000
+++ new/usr/src/test/elf-tests/doc/README	2019-02-28 22:40:45.443755429 +0000
@@ -0,0 +1,59 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
+#
+
+ELF Software Generation Utilities Unit Test Suite README
+
+1. Building and installing the ELF/SGS Unit Test Suite
+2. Running the ELF/SGS Unit Test Suite
+3. Test results
+
+--------------------------------------------------------------------------------
+
+1. Building and installing the ELF/SGS Unit Test Suite
+
+The ELF/SGS Unit Test Suite runs under the testrunner framework (which can be
+installed as pkg:/system/test/testrunner). To build both the ELF/SGS Unit Test Suite
+and the testrunner without running a full nightly:
+
+	build_machine$ bldenv [-d] <your_env_file>
+	build_machine$ cd $SRC/test
+	build_machine$ dmake install
+	build_machine$ cd $SRC/pkg
+	build_machine$ dmake install
+
+Then set the publisher on the test machine to point to your repository and
+install the ELF/SGS Unit Test Suite.
+
+	test_machine# pkg install pkg:/system/test/elftest
+
+Note, the framework will be installed automatically, as the ELF/SGS Unit Test Suite
+depends on it.
+
+2. Running the ELF/SGS Unit Test Suite
+
+The pre-requisites for running the ELF/SGS Unit Test Suite are:
+    None
+
+Once the pre-requisites are satisfied, simply run the elftest script:
+
+	test_machine$ /opt/elf-tests/bin/elftest
+
+3. Test results
+
+While the ELF/SGS Unit Test Suite is running, one informational line is printed at
+the end of each test, and a results summary is printed at the end of the run.
+The results summary includes the location of the complete logs, which is of the
+form /var/tmp/test_results/<ISO 8601 date>.
--- /dev/null	2019-02-28 22:40:45.000000000 +0000
+++ new/usr/src/test/elf-tests/runfiles/Makefile	2019-02-28 22:40:45.616006624 +0000
@@ -0,0 +1,40 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2012 by Delphix. All rights reserved.
+# Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
+# Copyright 2014 Garrett D'Amore <garrett@damore.org>
+#
+
+include $(SRC)/Makefile.master
+
+SRCS = default.run
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+RUNFILES = $(ROOTOPTPKG)/runfiles
+
+CMDS = $(SRCS:%=$(RUNFILES)/%)
+$(CMDS) := FILEMODE = 0444
+
+all: $(SRCS)
+
+install: $(CMDS)
+
+clean lint clobber:
+
+$(CMDS): $(RUNFILES) $(SRCS)
+
+$(RUNFILES):
+	$(INS.dir)
+
+$(RUNFILES)/%: %
+	$(INS.file)
--- /dev/null	2019-02-28 22:40:45.000000000 +0000
+++ new/usr/src/test/elf-tests/runfiles/default.run	2019-02-28 22:40:45.828717508 +0000
@@ -0,0 +1,37 @@
+
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2018, Richard Lowe.
+
+[DEFAULT]
+pre =
+verbose = False
+quiet = False
+timeout = 60
+post =
+outputdir = /var/tmp/test_results
+
+[/opt/elf-tests/tests/assert-deflib]
+tests = ['test-deflib']
+
+
+[/opt/elf-tests/tests/tls/amd64/ie]
+arch = i86pc
+tests = ['amd64-ie-test']
+
+[/opt/elf-tests/tests/tls/i386/ld]
+arch = i86pc
+tests = ['i386-ld-test']
+
+[/opt/elf-tests/tests/tls/amd64/ld]
+arch = i86pc
+tests = ['amd64-ld-test']
--- /dev/null	2019-02-28 22:40:46.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/Makefile	2019-02-28 22:40:46.052738125 +0000
@@ -0,0 +1,21 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2018 Joyent, Inc.
+#
+
+SUBDIRS =		\
+	assert-deflib	\
+	tls
+
+include $(SRC)/test/Makefile.com
--- /dev/null	2019-02-28 22:40:46.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/assert-deflib/Makefile	2019-02-28 22:40:46.279081466 +0000
@@ -0,0 +1,48 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2018, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG =	test-deflib
+
+DATAFILES =	link.c
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/assert-deflib
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+lint:
+
+clobber: clean
+	-$(RM) $(PROG)
+
+clean:
+	-$(RM) $(CLEANFILES)
+
+$(CMDS): $(TESTDIR) $(PROG)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- old/usr/src/cmd/sgs/test/ld/assert-deflib/link.c	2019-02-28 22:40:46.482429774 +0000
+++ /dev/null	2019-02-28 22:40:46.000000000 +0000
@@ -1,23 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright (c) 2012, Joyent, Inc.
- */
-
-#include <stdio.h>
-
-int
-main(void)
-{
-	(void) printf("Hello, world!\n");
-	return (0);
-}
--- /dev/null	2019-02-28 22:40:46.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/assert-deflib/link.c	2019-02-28 22:40:46.498512184 +0000
@@ -0,0 +1,23 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright (c) 2012, Joyent, Inc.
+ */
+
+#include <stdio.h>
+
+int
+main(void)
+{
+	(void) printf("Hello, world!\n");
+	return (0);
+}
--- old/usr/src/cmd/sgs/test/ld/assert-deflib/test-deflib.sh	2019-02-28 22:40:46.684058947 +0000
+++ /dev/null	2019-02-28 22:40:46.000000000 +0000
@@ -1,135 +0,0 @@
-#!/bin/bash
-#
-# This file and its contents are supplied under the terms of the
-# Common Development and Distribution License ("CDDL"), version 1.0.
-# You may only use this file in accordance with the terms of version
-# 1.0 of the CDDL.
-#
-# A full copy of the text of the CDDL should have accompanied this
-# source.  A copy of the CDDL is also available via the Internet at
-# http://www.illumos.org/license/CDDL.
-#
-
-#
-# Copyright (c) 2012, Joyent, Inc.
-#
-
-#
-# This test validates that the -zassert-deflib option of ld(1) works correctly.
-# It requires that some cc is in your path and that you have passed in the path
-# to the proto area with the new version of libld.so.4. One thing that we have
-# to do is be careful with using LD_LIBRARY_PATH. Setting LD_LIBRARY_PATH does
-# not change the default search path so we want to make sure that we use a
-# different ISA (e.g. 32-bit vs 64-bit) from the binary we're generating.
-#
-unalias -a
-
-sh_path=
-sh_lib="lib"
-sh_lib64="$sh_lib/64"
-sh_soname="libld.so.4"
-sh_cc="cc"
-sh_cflags="-m32"
-sh_file="link.c"
-sh_arg0=$(basename $0)
-
-function fatal
-{
-        local msg="$*"
-        [[ -z "$msg" ]] && msg="failed"
-        echo "$sh_arg0: $msg" >&2
-        exit 1
-}
-
-
-#
-# Validate that everything we need is in our path. That includes having cc
-# and the proto area libld.
-#
-function validate
-{
-	[[ -f $sh_path/$sh_lib/$sh_soname ]] || fatal "missing 32-bit $sh_soname"
-	[[ -f $sh_path/$sh_lib64/$sh_soname ]] ||
-	    fatal "missing 64-bit $sh_soname"
-	which $sh_cc >/dev/null || fatal "cc not in path"
-}
-
-#
-# $1 is a series of flags to append
-# $2 is expected exit status
-# $3 is pre-test message
-# $4 is the failure message
-#
-function run
-{
-	local ret
-
-	echo $3
-	LD_LIBRARY_PATH_64="$sh_path/$sh_lib64" $sh_cc $sh_cflags $sh_file $1
-	if [[ $? -eq $2 ]]; then
-		printf "success\n\n"
-	else
-		fatal $4
-	fi
-}
-
-sh_path=$1
-[[ -z "$1" ]] && fatal "<proto root>"
-validate
-
-run "-Wl,-zassert-deflib" 0 \
-    "Testing basic compilation succeeds with warnings..." \
-    "failed to compile with warnings"
-
-run "-Wl,-zassert-deflib -Wl,-zfatal-warnings" 1 \
-    "Testing basic compilation fails if warning are fatal..." \
-    "linking succeeeded, expected failure"
-
-run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
-    "Testing basic exception with fatal warnings..." \
-    "linking failed despite exception"
-
-run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
-    "Testing basic exception with fatal warnings..." \
-    "linking failed despite exception"
-
-
-run "-Wl,-zassert-deflib=lib.so -Wl,-zfatal-warnings" 1 \
-    "Testing invalid library name..." \
-    "ld should not allow invalid library name"
-
-run "-Wl,-zassert-deflib=libf -Wl,-zfatal-warnings" 1 \
-    "Testing invalid library name..." \
-    "ld should not allow invalid library name"
-
-run "-Wl,-zassert-deflib=libf.s -Wl,-zfatal-warnings" 1 \
-    "Testing invalid library name..." \
-    "ld should not allow invalid library name"
-
-run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings -lelf" 1 \
-    "Errors even if one library is under exception path..." \
-    "one exception shouldn't stop another"
-
-args="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libelf.so"
-args="$args -Wl,-zfatal-warnings -lelf"
-
-run "$args" 0 \
-    "Multiple exceptions work..." \
-    "multiple exceptions don't work"
-
-args="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libelfe.so"
-args="$args -Wl,-zfatal-warnings -lelf"
-
-run "$args" 1 \
-    "Exceptions only catch the specific library" \
-    "exceptions caught the wrong library"
-
-args="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libel.so"
-args="$args -Wl,-zfatal-warnings -lelf"
-
-run "$args" 1 \
-    "Exceptions only catch the specific library" \
-    "exceptions caught the wrong library"
-
-echo "Tests passed."
-exit 0
--- /dev/null	2019-02-28 22:40:46.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/assert-deflib/test-deflib.sh	2019-02-28 22:40:46.693644219 +0000
@@ -0,0 +1,136 @@
+#!/bin/bash
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2012, Joyent, Inc.
+#
+
+#
+# This test validates that the -zassert-deflib option of ld(1) works correctly.
+# It requires that some cc is in your path and that you have passed in the path
+# to the proto area with the new version of libld.so.4. One thing that we have
+# to do is be careful with using LD_LIBRARY_PATH. Setting LD_LIBRARY_PATH does
+# not change the default search path so we want to make sure that we use a
+# different ISA (e.g. 32-bit vs 64-bit) from the binary we're generating.
+#
+unalias -a
+
+TESTDIR=$(dirname $0)
+
+sh_path=
+sh_lib="lib"
+sh_lib64="$sh_lib/64"
+sh_soname="libld.so.4"
+sh_cc="gcc"
+sh_cflags="-m32"
+sh_file="${TESTDIR}/link.c"
+sh_arg0=$(basename $0)
+
+function fatal
+{
+        local msg="$*"
+        [[ -z "$msg" ]] && msg="failed"
+        echo "$sh_arg0: $msg" >&2
+        exit 1
+}
+
+
+#
+# Validate that everything we need is in our path. That includes having cc
+# and the proto area libld.
+#
+function validate
+{
+	[[ -f $sh_path/$sh_lib/$sh_soname ]] || fatal "missing 32-bit $sh_soname"
+	[[ -f $sh_path/$sh_lib64/$sh_soname ]] ||
+	    fatal "missing 64-bit $sh_soname"
+	which $sh_cc >/dev/null || fatal "cc not in path"
+}
+
+#
+# $1 is a series of flags to append
+# $2 is expected exit status
+# $3 is pre-test message
+# $4 is the failure message
+#
+function run
+{
+	local ret
+
+	echo $3
+	LD_LIBRARY_PATH_64="$sh_path/$sh_lib64" $sh_cc $sh_cflags $sh_file $1
+	if [[ $? -eq $2 ]]; then
+		printf "success\n\n"
+	else
+		fatal $4
+	fi
+}
+
+sh_path=${1:-/}
+validate
+
+run "-Wl,-zassert-deflib" 0 \
+    "Testing basic compilation succeeds with warnings..." \
+    "failed to compile with warnings"
+
+run "-Wl,-zassert-deflib -Wl,-zfatal-warnings" 1 \
+    "Testing basic compilation fails if warning are fatal..." \
+    "linking succeeeded, expected failure"
+
+run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
+    "Testing basic exception with fatal warnings..." \
+    "linking failed despite exception"
+
+run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings" 0 \
+    "Testing basic exception with fatal warnings..." \
+    "linking failed despite exception"
+
+
+run "-Wl,-zassert-deflib=lib.so -Wl,-zfatal-warnings" 1 \
+    "Testing invalid library name..." \
+    "ld should not allow invalid library name"
+
+run "-Wl,-zassert-deflib=libf -Wl,-zfatal-warnings" 1 \
+    "Testing invalid library name..." \
+    "ld should not allow invalid library name"
+
+run "-Wl,-zassert-deflib=libf.s -Wl,-zfatal-warnings" 1 \
+    "Testing invalid library name..." \
+    "ld should not allow invalid library name"
+
+run "-Wl,-zassert-deflib=libc.so -Wl,-zfatal-warnings -lelf" 1 \
+    "Errors even if one library is under exception path..." \
+    "one exception shouldn't stop another"
+
+args="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libelf.so"
+args="$args -Wl,-zfatal-warnings -lelf"
+
+run "$args" 0 \
+    "Multiple exceptions work..." \
+    "multiple exceptions don't work"
+
+args="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libelfe.so"
+args="$args -Wl,-zfatal-warnings -lelf"
+
+run "$args" 1 \
+    "Exceptions only catch the specific library" \
+    "exceptions caught the wrong library"
+
+args="-Wl,-zassert-deflib=libc.so -Wl,-zassert-deflib=libel.so"
+args="$args -Wl,-zfatal-warnings -lelf"
+
+run "$args" 1 \
+    "Exceptions only catch the specific library" \
+    "exceptions caught the wrong library"
+
+echo "Tests passed."
+exit 0
--- /dev/null	2019-02-28 22:40:47.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/Makefile	2019-02-28 22:40:47.132530607 +0000
@@ -0,0 +1,19 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2018 Joyent, Inc.
+#
+
+SUBDIRS = amd64 i386
+
+include $(SRC)/test/Makefile.com
--- /dev/null	2019-02-28 22:40:47.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/Makefile	2019-02-28 22:40:47.343959328 +0000
@@ -0,0 +1,19 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2018 Joyent, Inc.
+#
+
+SUBDIRS = ie ld
+
+include $(SRC)/test/Makefile.com
--- /dev/null	2019-02-28 22:40:47.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/Makefile	2019-02-28 22:40:47.575193663 +0000
@@ -0,0 +1,58 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2018, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG =	amd64-ie-test
+
+DATAFILES =			\
+	Makefile.test		\
+	style1-func-with-r12.s	\
+	style1-func-with-r13.s	\
+	style1-func.s		\
+	style1-main.s		\
+	style2-with-badness.s	\
+	style2-with-r12.s	\
+	style2-with-r13.s	\
+	style2.s
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/tls/amd64/ie
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+lint:
+
+clobber: clean
+	-$(RM) $(PROG)
+
+clean:
+	-$(RM) $(CLEANFILES)
+
+$(CMDS): $(TESTDIR) $(PROG)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/Makefile	2019-02-28 22:40:47.813597244 +0000
+++ /dev/null	2019-02-28 22:40:47.000000000 +0000
@@ -1,87 +0,0 @@
-#
-# This file and its contents are supplied under the terms of the
-# Common Development and Distribution License ("CDDL"), version 1.0.
-# You may only use this file in accordance with the terms of version
-# 1.0 of the CDDL.
-#
-# A full copy of the text of the CDDL should have accompanied this
-# source.  A copy of the CDDL is also available via the Internet at
-# http://www.illumos.org/license/CDDL.
-#
-
-# Copyright 2012, Richard Lowe.
-
-include $(SRC)/Makefile.master
-
-# We have to use GCC, and only GCC.  The best way is to ask cw(1) which GCC to use.
-CC_CMD =	$(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc -_compiler
-CC =		$(CC_CMD:sh)
-CFLAGS = 	-O1 -m64
-
-LINK.c = env LD_ALTEXEC=$(PROTO)/usr/bin/amd64/ld $(CC) $(CFLAGS) -o $@ $^
-COMPILE.c = $(CC) $(CFLAGS) -c -o $@ $^
-COMPILE.s = $(CC) $(CFLAGS) -c -o $@ $^
-
-.KEEP_STATE:
-
-install default: all
-
-.c.o:
-	$(COMPILE.c)
-
-.s.o:
-	$(COMPILE.s)
-
-# A basic use of TLS that uses the movq m/r --> movq i/r variant
-PROGS += 	style2
-STYLE2OBJS =	style2.o
-style2: $(STYLE2OBJS)
-	$(LINK.c)
-
-# A copy of style2 that uses %r13 in the TLS sequence, and thus excercises the
-# REX transitions of the movq mem,reg -> movq imm,reg variant.
-PROGS +=	style2-with-r13
-STYLE2R13OBJS =	style2-with-r13.o
-style2-with-r13: $(STYLE2R13OBJS)
-	$(LINK.c)
-
-# A copy of style2 that uses %r12 in the TLS sequence, so we can verify that
-# it is _not_ special to this variant
-PROGS +=	style2-with-r12
-STYLE2R12OBJS =	style2-with-r12.o
-style2-with-r12: $(STYLE2R12OBJS)
-	$(LINK.c)
-
-# A copy of style2 that has a R_AMD64_GOTTPOFF relocation with a bad insn sequence
-STYLE2BADNESSOBJS =	style2-with-badness.o
-style2-with-badness: $(STYLE2BADNESSOBJS)
-	-$(LINK.c)
-
-# A basic use of TLS that uses the addq mem/reg --> leaq mem,reg variant
-PROGS +=	style1
-STYLE1OBJS =	style1-main.o style1-func.o
-style1: $(STYLE1OBJS)
-	$(LINK.c)
-
-# A copy of style1-func that uses %r13 in the TLS sequence and thus excercises
-# the REX transitions. of the addq mem,reg --> leaq mem,reg variant
-PROGS +=	style1-with-r13
-STYLE1R13OBJS =	style1-main.o style1-func-with-r13.o
-style1-with-r13: $(STYLE1R13OBJS)
-	$(LINK.c)
-
-# A copy of style1-func that uses %r12 to test the addq mem,reg --> addq imm,reg variant
-PROGS +=	style1-with-r12
-STYLE1R12OBJS =	style1-main.o style1-func-with-r12.o
-style1-with-r12: $(STYLE1R12OBJS)
-	$(LINK.c)
-
-all:	$(PROGS)
-
-clobber clean: 
-	rm -f $(PROGS) $(STYLE1OBJS) $(STYLE1R13OBJS) $(STYLE1R12OBJS) \
-	    $(STYLE2OBJS) $(STYLE2R13OBJS) $(STYLE2R12OBJS) $(STYLE2BADNESSOBJS)
-
-fail: style2-with-badness FRC
-
-FRC:
--- /dev/null	2019-02-28 22:40:47.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/Makefile.test	2019-02-28 22:40:47.837577366 +0000
@@ -0,0 +1,79 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2012, Richard Lowe.
+
+CC =		gcc
+CFLAGS =	-O1 -m64
+
+LINK.c =  $(CC) $(CFLAGS) -o $@ $^
+COMPILE.s = $(CC) $(CFLAGS) -c -o $@ $^
+
+.KEEP_STATE:
+
+install default: all
+
+%.o: $(TESTDIR)/%.s
+	$(COMPILE.s)
+
+# A basic use of TLS that uses the movq m/r --> movq i/r variant
+PROGS +=	style2
+STYLE2OBJS =	style2.o
+style2: $(STYLE2OBJS)
+	$(LINK.c)
+
+# A copy of style2 that uses %r13 in the TLS sequence, and thus excercises the
+# REX transitions of the movq mem,reg -> movq imm,reg variant.
+PROGS +=	style2-with-r13
+STYLE2R13OBJS =	style2-with-r13.o
+style2-with-r13: $(STYLE2R13OBJS)
+	$(LINK.c)
+
+# A copy of style2 that uses %r12 in the TLS sequence, so we can verify that
+# it is _not_ special to this variant
+PROGS +=	style2-with-r12
+STYLE2R12OBJS =	style2-with-r12.o
+style2-with-r12: $(STYLE2R12OBJS)
+	$(LINK.c)
+
+# A copy of style2 that has a R_AMD64_GOTTPOFF relocation with a bad insn sequence
+STYLE2BADNESSOBJS =	style2-with-badness.o
+style2-with-badness: $(STYLE2BADNESSOBJS)
+	-$(LINK.c)
+
+# A basic use of TLS that uses the addq mem/reg --> leaq mem,reg variant
+PROGS +=	style1
+STYLE1OBJS =	style1-main.o style1-func.o
+style1: $(STYLE1OBJS)
+	$(LINK.c)
+
+# A copy of style1-func that uses %r13 in the TLS sequence and thus excercises
+# the REX transitions. of the addq mem,reg --> leaq mem,reg variant
+PROGS +=	style1-with-r13
+STYLE1R13OBJS =	style1-main.o style1-func-with-r13.o
+style1-with-r13: $(STYLE1R13OBJS)
+	$(LINK.c)
+
+# A copy of style1-func that uses %r12 to test the addq mem,reg --> addq imm,reg variant
+PROGS +=	style1-with-r12
+STYLE1R12OBJS =	style1-main.o style1-func-with-r12.o
+style1-with-r12: $(STYLE1R12OBJS)
+	$(LINK.c)
+
+all:	$(PROGS)
+
+clobber clean:
+	rm -f $(PROGS) $(STYLE1OBJS) $(STYLE1R13OBJS) $(STYLE1R12OBJS) \
+	    $(STYLE2OBJS) $(STYLE2R13OBJS) $(STYLE2R12OBJS) $(STYLE2BADNESSOBJS)
+
+fail: style2-with-badness FRC
+
+FRC:
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/README	2019-02-28 22:40:48.347899759 +0000
@@ -0,0 +1,5 @@
+This tests the amd64 link-editor's handling of Initial Executable TLS sequences.
+
+The original C source files are in orig/ but unused, since we need to avoid
+any changes to the compiler influencing our tests.
+
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/x64-ie-test.sh	2019-02-28 22:40:48.567872544 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,62 +0,0 @@
-#!/bin/ksh
-#
-# This file and its contents are supplied under the terms of the
-# Common Development and Distribution License ("CDDL"), version 1.0.
-# You may only use this file in accordance with the terms of version
-# 1.0 of the CDDL.
-#
-# A full copy of the text of the CDDL should have accompanied this
-# source.  A copy of the CDDL is also available via the Internet at
-# http://www.illumos.org/license/CDDL.
-#
-
-# Copyright 2012, Richard Lowe.
-
-function grep_test {
-    name=$1
-    pattern=$2
-
-    if /usr/bin/fgrep -q "${pattern}"; then
-	print -u2 "pass: $name"
-    else
-        print -u2 "FAIL: $name"
-    fi
-}        
-
-function dis_test {
-    name=${1}
-    func=${2}
-    file=${3}
-    pattern=${4}
-
-    dis -F${func} ${file} | grep_test "${name}" "${pattern}"
-}
-
-make PROTO="${1}"
-
-dis_test "addq-->leaq 1" func style1 \
-    'func+0x10: 48 8d 92 f8 ff ff  leaq   -0x8(%rdx),%rdx'
-dis_test "addq-->leaq 2" func style1 \
-    'func+0x17: 48 8d b6 f0 ff ff  leaq   -0x10(%rsi),%rsi'
-
-dis_test "addq-->leaq w/REX 1" func style1-with-r13 \
-    'func+0x10: 48 8d 92 f8 ff ff  leaq   -0x8(%rdx),%rdx'
-dis_test "addq-->leaq w/REX 2" func style1-with-r13 \
-    'func+0x17: 4d 8d ad f0 ff ff  leaq   -0x10(%r13),%r13'
-
-dis_test "addq-->addq for SIB 1" func style1-with-r12 \
-    'func+0x10: 48 8d 92 f8 ff ff  leaq   -0x8(%rdx),%rdx'
-dis_test "addq-->addq for SIB 2" func style1-with-r12 \
-    'func+0x17: 49 81 c4 f0 ff ff  addq   $-0x10,%r12	<0xfffffffffffffff0>'
-
-dis_test "movq-->movq" main style2 \
-    'main+0x4:  48 c7 c6 f0 ff ff  movq   $-0x10,%rsi	<0xfffffffffffffff0>'
-
-dis_test "movq-->movq w/REX" main style2-with-r13 \
-    'main+0x4:  49 c7 c5 f0 ff ff  movq   $-0x10,%r13	<0xfffffffffffffff0>'
-
-dis_test "movq-->movq incase of SIB" main style2-with-r12 \
-    'main+0x4:  49 c7 c4 f0 ff ff  movq   $-0x10,%r12	<0xfffffffffffffff0>'
-
-make PROTO="${1}" fail 2>&1 | grep_test "bad insn sequence" \
-   'ld: fatal: relocation error: R_AMD64_TPOFF32: file style2-with-badness.o: symbol foo: section .text: offset 0x7, relocation against unknown TLS instruction sequence'
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/amd64-ie-test.sh	2019-02-28 22:40:48.586704963 +0000
@@ -0,0 +1,64 @@
+#!/bin/ksh
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2012, Richard Lowe.
+
+function grep_test {
+    name=$1
+    pattern=$2
+
+    if /usr/bin/fgrep -q "${pattern}"; then
+	print -u2 "pass: $name"
+    else
+        print -u2 "FAIL: $name"
+        exit 1
+    fi
+}
+
+function dis_test {
+    name=${1}
+    func=${2}
+    file=${3}
+    pattern=${4}
+
+    dis -F${func} ${file} | grep_test "${name}" "${pattern}"
+}
+
+TESTDIR=$(dirname $0)
+make -f ${TESTDIR}/Makefile.test TESTDIR=${TESTDIR}
+
+dis_test "addq-->leaq 1" func style1 \
+    'func+0x10: 48 8d 92 f8 ff ff  leaq   -0x8(%rdx),%rdx'
+dis_test "addq-->leaq 2" func style1 \
+    'func+0x17: 48 8d b6 f0 ff ff  leaq   -0x10(%rsi),%rsi'
+
+dis_test "addq-->leaq w/REX 1" func style1-with-r13 \
+    'func+0x10: 48 8d 92 f8 ff ff  leaq   -0x8(%rdx),%rdx'
+dis_test "addq-->leaq w/REX 2" func style1-with-r13 \
+    'func+0x17: 4d 8d ad f0 ff ff  leaq   -0x10(%r13),%r13'
+
+dis_test "addq-->addq for SIB 1" func style1-with-r12 \
+    'func+0x10: 48 8d 92 f8 ff ff  leaq   -0x8(%rdx),%rdx'
+dis_test "addq-->addq for SIB 2" func style1-with-r12 \
+    'func+0x17: 49 81 c4 f0 ff ff  addq   $-0x10,%r12	<0xfffffffffffffff0>'
+
+dis_test "movq-->movq" main style2 \
+    'main+0x4:  48 c7 c6 f0 ff ff  movq   $-0x10,%rsi	<0xfffffffffffffff0>'
+
+dis_test "movq-->movq w/REX" main style2-with-r13 \
+    'main+0x4:  49 c7 c5 f0 ff ff  movq   $-0x10,%r13	<0xfffffffffffffff0>'
+
+dis_test "movq-->movq incase of SIB" main style2-with-r12 \
+    'main+0x4:  49 c7 c4 f0 ff ff  movq   $-0x10,%r12	<0xfffffffffffffff0>'
+
+make -f ${TESTDIR}/Makefile.test fail TESTDIR=${TESTDIR} 2>&1 | grep_test "bad insn sequence" \
+   'ld: fatal: relocation error: R_AMD64_TPOFF32: file style2-with-badness.o: symbol foo: section .text: offset 0x7, relocation against unknown TLS instruction sequence'
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/orig/style1-func.c	2019-02-28 22:40:49.054289804 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,24 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */
-
-#include <stdio.h>
-
-extern __thread char *foo, *bar;
-
-void
-func()
-{
-	printf("foo: %p bar: %p\n", &foo, &bar);
-}
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-func.c	2019-02-28 22:40:49.072202900 +0000
@@ -0,0 +1,24 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+#include <stdio.h>
+
+extern __thread char *foo, *bar;
+
+void
+func()
+{
+	printf("foo: %p bar: %p\n", &foo, &bar);
+}
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/orig/style1-main.c	2019-02-28 22:40:49.275166147 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,29 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */
-
-#include <stdio.h>
-
-extern void func();
-
-__thread char *foo = "foo";
-__thread char *bar = "bar";
-
-int
-main(void)
-{
-	printf("foo: %p bar: %p\n", &foo, &bar);
-	func();
-	return (0);
-}
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style1-main.c	2019-02-28 22:40:49.290577867 +0000
@@ -0,0 +1,29 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+#include <stdio.h>
+
+extern void func();
+
+__thread char *foo = "foo";
+__thread char *bar = "bar";
+
+int
+main(void)
+{
+	printf("foo: %p bar: %p\n", &foo, &bar);
+	func();
+	return (0);
+}
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/orig/style2.c	2019-02-28 22:40:49.503824514 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,25 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */
-
-#include <stdio.h>
-
-__thread char *foo __attribute__((tls_model("initial-exec"))) = "foo";
-
-int
-main(void)
-{
-	printf("foo: %p\n", &foo);
-	return (0);
-}
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/orig/style2.c	2019-02-28 22:40:49.521316082 +0000
@@ -0,0 +1,25 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+#include <stdio.h>
+
+__thread char *foo __attribute__((tls_model("initial-exec"))) = "foo";
+
+int
+main(void)
+{
+	printf("foo: %p\n", &foo);
+	return (0);
+}
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/style1-func-with-r12.s	2019-02-28 22:40:49.747397561 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,39 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */
-
-	.section	.rodata.str1.1,"aMS",@progbits,1
-.LC0:
-	.string	"foo: %p bar: %p\n"
-	.text
-.globl func
-	.type	func, @function
-func:
-.LFB0:
-	pushq	%rbp
-.LCFI0:
-	movq	%rsp, %rbp
-.LCFI1:
-	movq	%fs:0, %r12
-	movq	%r12, %rdx
-	addq	bar@GOTTPOFF(%rip), %rdx
-	addq	foo@GOTTPOFF(%rip), %r12
-        movq    %r12, %rsi     
-	movl	$.LC0, %edi
-	movl	$0, %eax
-	call	printf
-	leave
-	ret
-.LFE0:
-	.size	func, .-func
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r12.s	2019-02-28 22:40:49.763918844 +0000
@@ -0,0 +1,39 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"foo: %p bar: %p\n"
+	.text
+.globl func
+	.type	func, @function
+func:
+.LFB0:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	movq	%fs:0, %r12
+	movq	%r12, %rdx
+	addq	bar@GOTTPOFF(%rip), %rdx
+	addq	foo@GOTTPOFF(%rip), %r12
+	movq	%r12, %rsi
+	movl	$.LC0, %edi
+	movl	$0, %eax
+	call	printf
+	leave
+	ret
+.LFE0:
+	.size	func, .-func
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/style1-func-with-r13.s	2019-02-28 22:40:50.188664524 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,38 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */
-	.section	.rodata.str1.1,"aMS",@progbits,1
-.LC0:
-	.string	"foo: %p bar: %p\n"
-	.text
-.globl func
-	.type	func, @function
-func:
-.LFB0:
-	pushq	%rbp
-.LCFI0:
-	movq	%rsp, %rbp
-.LCFI1:
-	movq	%fs:0, %r13
-	movq	%r13, %rdx
-	addq	bar@GOTTPOFF(%rip), %rdx
-	addq	foo@GOTTPOFF(%rip), %r13
-        movq    %r13, %rsi
-	movl	$.LC0, %edi
-	movl	$0, %eax
-	call	printf
-	leave
-	ret
-.LFE0:
-	.size	func, .-func
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func-with-r13.s	2019-02-28 22:40:50.199669703 +0000
@@ -0,0 +1,38 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"foo: %p bar: %p\n"
+	.text
+.globl func
+	.type	func, @function
+func:
+.LFB0:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	movq	%fs:0, %r13
+	movq	%r13, %rdx
+	addq	bar@GOTTPOFF(%rip), %rdx
+	addq	foo@GOTTPOFF(%rip), %r13
+        movq    %r13, %rsi
+	movl	$.LC0, %edi
+	movl	$0, %eax
+	call	printf
+	leave
+	ret
+.LFE0:
+	.size	func, .-func
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/style1-func.s	2019-02-28 22:40:50.378461362 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,38 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */
-
-	.section	.rodata.str1.1,"aMS",@progbits,1
-.LC0:
-	.string	"foo: %p bar: %p\n"
-	.text
-.globl func
-	.type	func, @function
-func:
-.LFB0:
-	pushq	%rbp
-.LCFI0:
-	movq	%rsp, %rbp
-.LCFI1:
-	movq	%fs:0, %rsi
-	movq	%rsi, %rdx
-	addq	bar@GOTTPOFF(%rip), %rdx
-	addq	foo@GOTTPOFF(%rip), %rsi
-	movl	$.LC0, %edi
-	movl	$0, %eax
-	call	printf
-	leave
-	ret
-.LFE0:
-	.size	func, .-func
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-func.s	2019-02-28 22:40:50.395854237 +0000
@@ -0,0 +1,38 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"foo: %p bar: %p\n"
+	.text
+.globl func
+	.type	func, @function
+func:
+.LFB0:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	movq	%fs:0, %rsi
+	movq	%rsi, %rdx
+	addq	bar@GOTTPOFF(%rip), %rdx
+	addq	foo@GOTTPOFF(%rip), %rsi
+	movl	$.LC0, %edi
+	movl	$0, %eax
+	call	printf
+	leave
+	ret
+.LFE0:
+	.size	func, .-func
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/style1-main.s	2019-02-28 22:40:50.610567513 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,60 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */
-
-	.section	.rodata.str1.1,"aMS",@progbits,1
-.LC0:
-	.string	"foo: %p bar: %p\n"
-	.text
-.globl main
-	.type	main, @function
-main:
-.LFB0:
-	pushq	%rbp
-.LCFI0:
-	movq	%rsp, %rbp
-.LCFI1:
-	movq	%fs:0, %rsi
-	leaq	bar@TPOFF(%rsi), %rdx
-	addq	$foo@TPOFF, %rsi
-	movl	$.LC0, %edi
-	movl	$0, %eax
-	call	printf
-	movl	$0, %eax
-	call	func
-	movl	$0, %eax
-	leave
-	ret
-.LFE0:
-	.size	main, .-main
-.globl foo
-	.section	.rodata.str1.1
-.LC1:
-	.string	"foo"
-	.section	.tdata,"awT",@progbits
-	.align 8
-	.type	foo, @object
-	.size	foo, 8
-foo:
-	.quad	.LC1
-.globl bar
-	.section	.rodata.str1.1
-.LC2:
-	.string	"bar"
-	.section	.tdata
-	.align 8
-	.type	bar, @object
-	.size	bar, 8
-bar:
-	.quad	.LC2
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/style1-main.s	2019-02-28 22:40:50.630811903 +0000
@@ -0,0 +1,60 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"foo: %p bar: %p\n"
+	.text
+.globl main
+	.type	main, @function
+main:
+.LFB0:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	movq	%fs:0, %rsi
+	leaq	bar@TPOFF(%rsi), %rdx
+	addq	$foo@TPOFF, %rsi
+	movl	$.LC0, %edi
+	movl	$0, %eax
+	call	printf
+	movl	$0, %eax
+	call	func
+	movl	$0, %eax
+	leave
+	ret
+.LFE0:
+	.size	main, .-main
+.globl foo
+	.section	.rodata.str1.1
+.LC1:
+	.string	"foo"
+	.section	.tdata,"awT",@progbits
+	.align 8
+	.type	foo, @object
+	.size	foo, 8
+foo:
+	.quad	.LC1
+.globl bar
+	.section	.rodata.str1.1
+.LC2:
+	.string	"bar"
+	.section	.tdata
+	.align 8
+	.type	bar, @object
+	.size	bar, 8
+bar:
+	.quad	.LC2
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/style2-with-badness.s	2019-02-28 22:40:50.843540505 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,47 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */	
-
-	.section	.rodata.str1.1,"aMS",@progbits,1
-.LC0:
-	.string	"foo: %p\n"
-	.text
-.globl main
-	.type	main, @function
-main:
-.LFB0:
-	pushq	%rbp
-.LCFI0:
-	movq	%rsp, %rbp
-.LCFI1:
-	leaq	foo@GOTTPOFF(%rip), %rsi
-	addq	%fs:0, %rsi
-	movl	$.LC0, %edi
-	movl	$0, %eax
-	call	printf
-	movl	$0, %eax
-	leave
-	ret
-.LFE0:
-	.size	main, .-main
-.globl foo
-	.section	.rodata.str1.1
-.LC1:
-	.string	"foo"
-	.section	.tdata,"awT",@progbits
-	.align 8
-	.type	foo, @object
-	.size	foo, 8
-foo:
-	.quad	.LC1
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-badness.s	2019-02-28 22:40:50.860134191 +0000
@@ -0,0 +1,47 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"foo: %p\n"
+	.text
+.globl main
+	.type	main, @function
+main:
+.LFB0:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	leaq	foo@GOTTPOFF(%rip), %rsi
+	addq	%fs:0, %rsi
+	movl	$.LC0, %edi
+	movl	$0, %eax
+	call	printf
+	movl	$0, %eax
+	leave
+	ret
+.LFE0:
+	.size	main, .-main
+.globl foo
+	.section	.rodata.str1.1
+.LC1:
+	.string	"foo"
+	.section	.tdata,"awT",@progbits
+	.align 8
+	.type	foo, @object
+	.size	foo, 8
+foo:
+	.quad	.LC1
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/style2-with-r12.s	2019-02-28 22:40:51.298347177 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,48 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */	
-
-	.section	.rodata.str1.1,"aMS",@progbits,1
-.LC0:
-	.string	"foo: %p\n"
-	.text
-.globl main
-	.type	main, @function
-main:
-.LFB0:
-	pushq	%rbp
-.LCFI0:
-	movq	%rsp, %rbp
-.LCFI1:
-	movq	foo@GOTTPOFF(%rip), %r12
-	addq	%fs:0, %r12
-        movq    %r12, %rsi
-	movl	$.LC0, %edi
-	movl	$0, %eax
-	call	printf
-	movl	$0, %eax
-	leave
-	ret
-.LFE0:
-	.size	main, .-main
-.globl foo
-	.section	.rodata.str1.1
-.LC1:
-	.string	"foo"
-	.section	.tdata,"awT",@progbits
-	.align 8
-	.type	foo, @object
-	.size	foo, 8
-foo:
-	.quad	.LC1
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r12.s	2019-02-28 22:40:51.314010700 +0000
@@ -0,0 +1,49 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"foo: %p\n"
+	.text
+.globl main
+	.type	main, @function
+main:
+.LFB0:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	movq	foo@GOTTPOFF(%rip), %r12
+	addq	%fs:0, %r12
+        movq    %r12, %rsi
+	movl	$.LC0, %edi
+	movl	$0, %eax
+	call	printf
+	movl	$0, %eax
+	leave
+	ret
+.LFE0:
+	.size	main, .-main
+.globl foo
+	.section	.rodata.str1.1
+.LC1:
+	.string	"foo"
+
+	.section	.tdata,"awT",@progbits
+	.align 8
+	.type	foo, @object
+	.size	foo, 8
+foo:
+	.quad	.LC1
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/style2-with-r13.s	2019-02-28 22:40:51.751855746 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,48 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */	
-
-	.section	.rodata.str1.1,"aMS",@progbits,1
-.LC0:
-	.string	"foo: %p\n"
-	.text
-.globl main
-	.type	main, @function
-main:
-.LFB0:
-	pushq	%rbp
-.LCFI0:
-	movq	%rsp, %rbp
-.LCFI1:
-	movq	foo@GOTTPOFF(%rip), %r13
-	addq	%fs:0, %r13
-        movq    %r13, %rsi
-	movl	$.LC0, %edi
-	movl	$0, %eax
-	call	printf
-	movl	$0, %eax
-	leave
-	ret
-.LFE0:
-	.size	main, .-main
-.globl foo
-	.section	.rodata.str1.1
-.LC1:
-	.string	"foo"
-	.section	.tdata,"awT",@progbits
-	.align 8
-	.type	foo, @object
-	.size	foo, 8
-foo:
-	.quad	.LC1
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/style2-with-r13.s	2019-02-28 22:40:51.766131981 +0000
@@ -0,0 +1,48 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"foo: %p\n"
+	.text
+.globl main
+	.type	main, @function
+main:
+.LFB0:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	movq	foo@GOTTPOFF(%rip), %r13
+	addq	%fs:0, %r13
+        movq    %r13, %rsi
+	movl	$.LC0, %edi
+	movl	$0, %eax
+	call	printf
+	movl	$0, %eax
+	leave
+	ret
+.LFE0:
+	.size	main, .-main
+.globl foo
+	.section	.rodata.str1.1
+.LC1:
+	.string	"foo"
+	.section	.tdata,"awT",@progbits
+	.align 8
+	.type	foo, @object
+	.size	foo, 8
+foo:
+	.quad	.LC1
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/style2.s	2019-02-28 22:40:52.206415147 +0000
+++ /dev/null	2019-02-28 22:40:48.000000000 +0000
@@ -1,47 +0,0 @@
-/*
- * This file and its contents are supplied under the terms of the
- * Common Development and Distribution License ("CDDL"), version 1.0.
- * You may only use this file in accordance with the terms of version
- * 1.0 of the CDDL.
- *
- * A full copy of the text of the CDDL should have accompanied this
- * source.  A copy of the CDDL is also available via the Internet at
- * http://www.illumos.org/license/CDDL.
- */
-
-/*
- * Copyright 2012, Richard Lowe.
- */	
-
-	.section	.rodata.str1.1,"aMS",@progbits,1
-.LC0:
-	.string	"foo: %p\n"
-	.text
-.globl main
-	.type	main, @function
-main:
-.LFB0:
-	pushq	%rbp
-.LCFI0:
-	movq	%rsp, %rbp
-.LCFI1:
-	movq	foo@GOTTPOFF(%rip), %rsi
-	addq	%fs:0, %rsi
-	movl	$.LC0, %edi
-	movl	$0, %eax
-	call	printf
-	movl	$0, %eax
-	leave
-	ret
-.LFE0:
-	.size	main, .-main
-.globl foo
-	.section	.rodata.str1.1
-.LC1:
-	.string	"foo"
-	.section	.tdata,"awT",@progbits
-	.align 8
-	.type	foo, @object
-	.size	foo, 8
-foo:
-	.quad	.LC1
--- /dev/null	2019-02-28 22:40:48.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ie/style2.s	2019-02-28 22:40:52.224622750 +0000
@@ -0,0 +1,47 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"foo: %p\n"
+	.text
+.globl main
+	.type	main, @function
+main:
+.LFB0:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+.LCFI1:
+	movq	foo@GOTTPOFF(%rip), %rsi
+	addq	%fs:0, %rsi
+	movl	$.LC0, %edi
+	movl	$0, %eax
+	call	printf
+	movl	$0, %eax
+	leave
+	ret
+.LFE0:
+	.size	main, .-main
+.globl foo
+	.section	.rodata.str1.1
+.LC1:
+	.string	"foo"
+	.section	.tdata,"awT",@progbits
+	.align 8
+	.type	foo, @object
+	.size	foo, 8
+foo:
+	.quad	.LC1
--- /dev/null	2019-02-28 22:40:52.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ld/Makefile	2019-02-28 22:40:52.663222209 +0000
@@ -0,0 +1,51 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2018, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG =	amd64-ld-test
+
+DATAFILES =		\
+	Makefile.test	\
+	ld-with-addend.s	\
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/tls/amd64/ld
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+lint:
+
+clobber: clean
+	-$(RM) $(PROG)
+
+clean:
+	-$(RM) $(CLEANFILES)
+
+$(CMDS): $(TESTDIR) $(PROG)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	2019-02-28 22:40:52.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ld/Makefile.test	2019-02-28 22:40:52.891769394 +0000
@@ -0,0 +1,38 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2012, Richard Lowe.
+
+CC =		gcc
+CFLAGS =	-O1 -m64
+
+LINK.c =  $(CC) $(CFLAGS) -o $@ $^
+COMPILE.s = $(CC) $(CFLAGS) -c -o $@ $^
+
+.KEEP_STATE:
+
+install default: all
+
+%.o: $(TESTDIR)/%.s
+	$(COMPILE.s)
+
+# an R_AMD64_DTPOFF32 with an addend, which must be preserved
+PROGS +=	ld-with-addend
+
+ld-with-addend: ld-with-addend.o
+	$(LINK.c)
+
+all:	$(PROGS)
+
+clobber clean:
+	rm -f $(PROGS) ld-with-addend.o
+
+FRC:
--- /dev/null	2019-02-28 22:40:53.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ld/amd64-ld-test.sh	2019-02-28 22:40:53.127216981 +0000
@@ -0,0 +1,46 @@
+#!/bin/ksh
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2012, Richard Lowe.
+
+function grep_test {
+    name=$1
+    pattern=$2
+
+    if /usr/bin/grep -q "${pattern}"; then
+	print -u2 "pass: $name"
+        else
+        print -u2 "FAIL: $name"
+        exit 1
+    fi
+}
+
+function dis_test {
+    name=${1}
+    func=${2}
+    file=${3}
+    pattern=${4}
+
+    dis -F${func} ${file} | grep_test "${name}" "${pattern}"
+}
+
+TESTDIR=$(dirname $0)
+
+make -f ${TESTDIR}/Makefile.test TESTDIR=${TESTDIR}
+
+# if we fail, the addend won't be applied, the leaq with be -0x10(%rax)
+dis_test "addend is preserved" main ld-with-addend \
+    'main+0x10: 48 8d b0 f2 ff ff  leaq   -0xe(%rax),%rsi'
+
+# We have an addend of 2, a failure will print 'incorrect'
+./ld-with-addend | grep_test 'ld-with-addend execution' \
+    '^foo: correct ([a-f0-9]*)$'
--- /dev/null	2019-02-28 22:40:53.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/amd64/ld/ld-with-addend.s	2019-02-28 22:40:53.357470608 +0000
@@ -0,0 +1,43 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2012, Richard Lowe.
+ */
+
+	.section	.rodata.str1.1,"aMS",@progbits,1
+.LC0:
+	.string	"foo: %s (%p)\n"
+	.text
+	.section	.tdata,"awT",@progbits
+foo:
+	.string	"incorrect"
+        .text
+.globl main
+	.type	main, @function
+main:
+.LFB0:
+	pushq	%rbp
+.LCFI0:
+	movq	%rsp, %rbp
+        .LCFI1:
+	leaq	foo@tlsld(%rip), %rdi
+	call	__tls_get_addr@plt
+	leaq	2+foo@dtpoff(%rax), %rsi
+        movq	%rsi, %rdx
+        movq	%rsi, %rsi
+	movl	$.LC0, %edi
+	movl	$0, %eax
+	call	printf
+	movl	$0, %eax
+	leave
+	ret
+	.size	main, .-main
--- /dev/null	2019-02-28 22:40:53.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/i386/Makefile	2019-02-28 22:40:53.570393476 +0000
@@ -0,0 +1,19 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
+# Copyright 2018 Joyent, Inc.
+#
+
+SUBDIRS = ld
+
+include $(SRC)/test/Makefile.com
--- /dev/null	2019-02-28 22:40:53.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/i386/ld/Makefile	2019-02-28 22:40:53.787278083 +0000
@@ -0,0 +1,51 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2018, Richard Lowe.
+
+include $(SRC)/cmd/Makefile.cmd
+include $(SRC)/test/Makefile.com
+
+PROG =	i386-ld-test
+
+DATAFILES =		\
+	Makefile.test	\
+	half-ldm.s	\
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/tls/i386/ld
+
+CMDS = $(PROG:%=$(TESTDIR)/%)
+$(CMDS) := FILEMODE = 0555
+
+
+DATA = $(DATAFILES:%=$(TESTDIR)/%)
+$(DATA) := FILEMODE = 0444
+
+all: $(PROG)
+
+install: all $(CMDS) $(DATA)
+
+lint:
+
+clobber: clean
+	-$(RM) $(PROG)
+
+clean:
+	-$(RM) $(CLEANFILES)
+
+$(CMDS): $(TESTDIR) $(PROG)
+
+$(TESTDIR):
+	$(INS.dir)
+
+$(TESTDIR)/%: %
+	$(INS.file)
--- /dev/null	2019-02-28 22:40:54.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/i386/ld/Makefile.test	2019-02-28 22:40:54.001419120 +0000
@@ -0,0 +1,38 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2012, Richard Lowe.
+
+CC =		gcc
+CFLAGS =	-O1 -m32
+
+LINK.c =  $(CC) $(CFLAGS) -o $@ $^
+COMPILE.s = $(CC) $(CFLAGS) -c -o $@ $^
+
+.KEEP_STATE:
+
+install default: all
+
+%.o: $(TESTDIR)/%.s
+	$(COMPILE.s)
+
+# an R_386_TLS_LDM with a regular R_386_PLT32 not a R_386_TLS_LDM_PLT
+PROGS +=	half-ldm
+
+half-ldm: half-ldm.o
+	$(LINK.c)
+
+all:	$(PROGS)
+
+clobber clean:
+	rm -f $(PROGS) half-ldm.o
+
+FRC:
--- /dev/null	2019-02-28 22:40:54.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/i386/ld/half-ldm.s	2019-02-28 22:40:54.215950563 +0000
@@ -0,0 +1,49 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source.  A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.u
+ */
+
+/*
+ * Copyright 2019, Richard Lowe.
+ */
+
+        .section .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+        .string "foo: %s (%p)\n"
+        .section .tdata,"awT",@progbits
+        .align 4
+	.type foo, @object
+        .size foo,4
+.local foo
+foo:
+	.string	"foo"
+        .text
+.globl main
+        .type main, @function
+main:
+        pushl %ebp
+        movl %esp, %ebp
+	/*
+         * an R_386_TLS_LDM relocation without a following
+         * followed by an R_386_PLT32 relocation, rather than an
+	 * R_386_TLS_LDM_PLT the call should be removed, and _not_
+         * left alone unrelocated as it was prior to:
+         * 10267 ld and GCC disagree about i386 local dynamic TLS
+         */
+        leal foo@TLSLDM(%ebx), %eax
+        call ___tls_get_addr@PLT
+        leal  foo@DTPOFF(%eax), %edx
+        pushl %edx
+        pushl %edx
+        pushl $.LC0
+        call printf@PLT
+        movl $0x0,%eax
+        leave
+        ret
+	.size main, .-main
--- /dev/null	2019-02-28 22:40:54.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/i386/ld/i386-ld-test.sh	2019-02-28 22:40:54.436245175 +0000
@@ -0,0 +1,43 @@
+#!/bin/ksh
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source.  A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+# Copyright 2012, Richard Lowe.
+
+function grep_test {
+    name=$1
+    pattern=$2
+
+    if /usr/bin/grep -q "${pattern}"; then
+	print -u2 "pass: $name"
+        else
+        print -u2 "FAIL: $name"
+        exit 1
+    fi
+}
+
+function dis_test {
+    name=${1}
+    func=${2}
+    file=${3}
+    pattern=${4}
+
+    dis -F${func} ${file} | grep_test "${name}" "${pattern}"
+}
+
+TESTDIR=$(dirname $0)
+make -f ${TESTDIR}/Makefile.test TESTDIR=${TESTDIR}
+
+dis_test "call-->nop" main half-ldm \
+    'main\+0x9:  0f 1f 44 00 00     nopl   0x0(%eax,%eax)'
+
+./half-ldm | grep_test 'half-ldm execution' \
+    '^foo: foo ([a-f0-9]*)$'
