--- old/usr/src/cmd/file/elf_read.c	2019-02-24 19:19:04.913351284 +0000
+++ new/usr/src/cmd/file/elf_read.c	2019-02-24 19:19:04.928289878 +0000
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
-/*	  All Rights Reserved  	*/
+/*	  All Rights Reserved	*/
 
 
 /*	Copyright (c) 1987, 1988 Microsoft Corporation	*/
@@ -79,6 +79,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/elf.h>
+#include <sys/link.h>
 #include <elfcap.h>
 #include "file.h"
 #include "elf_read.h"
@@ -125,7 +126,7 @@
 
 /*
  * file_xlatetom:	translate different headers from file
- * 			representation to memory representaion.
+ *			representation to memory representaion.
  */
 #define	HDRSZ 512
 static int
@@ -141,7 +142,7 @@
 	/* will convert only these types */
 	if (type != ELF_T_EHDR && type != ELF_T_PHDR &&
 	    type != ELF_T_SHDR && type != ELF_T_WORD &&
-	    type != ELF_T_CAP)
+	    type != ELF_T_CAP && type != ELF_T_DYN)
 		return (ELF_READ_FAIL);
 
 	src.d_buf = (Elf_Void *)hdr;
@@ -162,7 +163,7 @@
 
 /*
  * xlatetom_nhdr:	There is no routine to convert Note header
- * 			so we convert each field of this header.
+ *			so we convert each field of this header.
  */
 static int
 xlatetom_nhdr(Elf_Nhdr *nhdr)
@@ -177,7 +178,7 @@
 
 /*
  * elf_read:	reads elf header, program, section headers to
- * 		collect all information needed for file(1)
+ *		collect all information needed for file(1)
  *		output and stores them in Elf_Info.
  */
 int
@@ -300,7 +301,7 @@
 /*
  * process_phdr:	Read Program Headers and see if it is a core
  *			file of either new or (pre-restructured /proc)
- * 			type, read the name of the file that dumped this
+ *			type, read the name of the file that dumped this
  *			core, else see if this is a dynamically linked.
  */
 static int
@@ -415,17 +416,12 @@
 static int
 process_shdr(Elf_Info *EI)
 {
-	int 		capn, mac;
-	int 		i, j, idx;
-	FILE_ELF_OFF_T	cap_off;
-	FILE_ELF_SIZE_T	csize;
+	int		mac;
+	int		i, j, idx;
 	char		*strtab;
 	size_t		strtab_sz;
-	Elf_Cap 	Chdr;
 	Elf_Shdr	*shdr = &EI_Shdr;
 
-
-	csize = sizeof (Elf_Cap);
 	mac = EI_Ehdr.e_machine;
 
 	/* if there are no sections, return success anyway */
@@ -457,9 +453,15 @@
 			continue;
 		}
 
-		cap_off = shdr->sh_offset;
 		if (shdr->sh_type == SHT_SUNW_cap) {
-			char capstr[128];
+			char		capstr[128];
+			Elf_Cap		Chdr;
+			FILE_ELF_OFF_T	cap_off;
+			FILE_ELF_SIZE_T	csize;
+			int capn;
+
+			cap_off = shdr->sh_offset;
+			csize = sizeof (Elf_Cap);
 
 			if (shdr->sh_size == 0 || shdr->sh_entsize == 0) {
 				(void) fprintf(stderr, ELF_ERR_ELFCAP1,
@@ -471,8 +473,8 @@
 				/*
 				 * read cap and xlate the values
 				 */
-				if (pread64(EI->elffd, &Chdr, csize, cap_off)
-				    != csize ||
+				if ((pread64(EI->elffd, &Chdr, csize, cap_off)
+				    != csize) ||
 				    file_xlatetom(ELF_T_CAP, (char *)&Chdr)
 				    == 0) {
 					(void) fprintf(stderr, ELF_ERR_ELFCAP2,
@@ -503,6 +505,39 @@
 				(void) strlcat(EI->cap_str, capstr,
 				    sizeof (EI->cap_str));
 			}
+		} else if (shdr->sh_type == SHT_DYNAMIC) {
+			Elf_Dyn dyn;
+			FILE_ELF_SIZE_T dsize;
+			FILE_ELF_OFF_T doff;
+			int dynn;
+
+			doff = shdr->sh_offset;
+			dsize = sizeof (Elf_Dyn);
+
+			if (shdr->sh_size == 0 || shdr->sh_entsize == 0) {
+				(void) fprintf(stderr, ELF_ERR_DYNAMIC1,
+				    File, EI->file);
+				return (ELF_READ_FAIL);
+			}
+
+			dynn = (shdr->sh_size / shdr->sh_entsize);
+			for (j = 0; j < dynn; j++) {
+				if (pread64(EI->elffd, &dyn, dsize, doff)
+				    != dsize ||
+				    file_xlatetom(ELF_T_DYN, (char *)&dyn)
+				    == 0) {
+					(void) fprintf(stderr, ELF_ERR_DYNAMIC2,
+					    File, EI->file);
+					return (ELF_READ_FAIL);
+				}
+
+				doff += dsize;
+
+				if ((dyn.d_tag == DT_SUNW_KMOD) &&
+				    (dyn.d_un.d_val == 1)) {
+					EI->kmod = B_TRUE;
+				}
+			}
 		}
 
 		/*
--- old/usr/src/cmd/file/elf_read.h	2019-02-24 19:19:05.363963681 +0000
+++ new/usr/src/cmd/file/elf_read.h	2019-02-24 19:19:05.380330370 +0000
@@ -26,8 +26,6 @@
 #ifndef _ELF_READ_H
 #define	_ELF_READ_H
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
-
 #define	BUFSZ 128
 typedef struct Elf_Info {
 	boolean_t	dynamic;	/* dymanically linked? */
@@ -40,6 +38,7 @@
 	char		fname[PRFNSZ];	/* name of process that dumped core */
 	char		cap_str[BUFSZ];	/* hw/sw capabilities */
 	char		*file;		/* file being processed */
+	boolean_t	kmod;
 } Elf_Info;
 
 /* values for Elf_Info.stripped */
@@ -53,10 +52,14 @@
 #define	EC_NEWCORE	0x2
 
 /* elf file processing errors */
-#define	ELF_ERR_ELFCAP1	gettext("%s: %s zero size or zero entry ELF " \
-			    "section - ELF capabilities ignored\n")
-#define	ELF_ERR_ELFCAP2	gettext("%s: %s: can't read ELF capabilities " \
-			    "data - ELF capabilities ignored\n")
+#define	ELF_ERR_ELFCAP1		gettext("%s: %s zero size or zero entry ELF " \
+	"section - ELF capabilities ignored\n")
+#define	ELF_ERR_ELFCAP2		gettext("%s: %s: can't read ELF capabilities " \
+	"data - ELF capabilities ignored\n")
+#define	ELF_ERR_DYNAMIC1	gettext("%s: %s zero size or zero entry ELF " \
+	"section - ELF dynamic tags ignored\n")
+#define	ELF_ERR_DYNAMIC2	gettext("%s: %s: can't read ELF dynamic " \
+	"data - ELF dynamic tags ignored\n")
 
 extern int is_in_list(char *str);
 
@@ -72,6 +75,7 @@
 #define	Elf_Cap		Elf64_Cap
 #define	Elf_Nhdr	Elf64_Nhdr
 #define	Elf_Word	Elf64_Word
+#define	Elf_Dyn		Elf64_Dyn
 
 #define	elf_read	elf_read64
 #define	elf_xlatetom	elf64_xlatetom
@@ -88,6 +92,7 @@
 #define	Elf_Cap		Elf32_Cap
 #define	Elf_Nhdr	Elf32_Nhdr
 #define	Elf_Word	Elf32_Word
+#define	Elf_Dyn		Elf32_Dyn
 
 #define	elf_read	elf_read32
 #define	elf_xlatetom	elf32_xlatetom
--- old/usr/src/cmd/file/file.c	2019-02-24 19:19:05.787417276 +0000
+++ new/usr/src/cmd/file/file.c	2019-02-24 19:19:05.801762395 +0000
@@ -19,7 +19,7 @@
  * CDDL HEADER END
  */
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
-/*	  All Rights Reserved  	*/
+/*	  All Rights Reserved	*/
 
 
 /*	Copyright (c) 1987, 1988 Microsoft Corporation	*/
@@ -614,7 +614,7 @@
  *	be applied before context-sensitive tests, to avoid
  *	false context-sensitive matches.
  *
- * 	Returns -1 on error which should result in error (non-zero)
+ *	Returns -1 on error which should result in error (non-zero)
  *	exit status for the file utility.
  *	Returns 0 if no matching file type found.
  *	Returns 1 if matching file type found.
@@ -1330,6 +1330,10 @@
 	if (version == 1)
 		(void) printf(" %s %d", gettext("Version"), version);
 
+	if (EInfo.kmod) {
+		(void) printf(", %s", gettext("kernel module"));
+	}
+
 	/* Print Flags */
 	print_elf_flags(EInfo);
 
@@ -1483,9 +1487,10 @@
 	return (1);
 }
 
+/* look for "1hddddd" where d is a digit */
 static int
 sccs(void)
-{				/* look for "1hddddd" where d is a digit */
+{
 	register int j;
 
 	if (fbuf[0] == 1 && fbuf[1] == 'h') {
--- old/usr/src/cmd/sgs/dump/common/dump.c	2019-02-24 19:19:06.292912701 +0000
+++ new/usr/src/cmd/sgs/dump/common/dump.c	2019-02-24 19:19:06.310139344 +0000
@@ -1225,6 +1225,7 @@
 			case DT_SUNW_CAPCHAINENT:
 			case DT_SUNW_CAPCHAINSZ:
 			case DT_SUNW_ASLR:
+			case DT_SUNW_KMOD:
 				(void) printf(pdyn_Fmtptr,
 				    EC_XWORD(p_dyn.d_un.d_val));
 				break;
--- old/usr/src/cmd/sgs/include/_libelf.h	2019-02-24 19:19:06.812800417 +0000
+++ new/usr/src/cmd/sgs/include/_libelf.h	2019-02-24 19:19:06.829550125 +0000
@@ -47,6 +47,7 @@
 extern size_t		_elf_getarsymwordsize(Elf *);
 extern Elf64_Off	_elf_getxoff(Elf_Data *);
 extern GElf_Xword	_gelf_getdyndtflags_1(Elf *);
+extern GElf_Xword	_gelf_getdynval(Elf *, GElf_Sxword);
 extern int		_elf_swap_wrimage(Elf *);
 extern uint_t		_elf_sys_encoding(void);
 
--- old/usr/src/cmd/sgs/include/libld.h	2019-02-24 19:19:07.228505750 +0000
+++ new/usr/src/cmd/sgs/include/libld.h	2019-02-24 19:19:07.244336268 +0000
@@ -105,7 +105,7 @@
  */
 struct rel_cache {
 	APlist		*rc_list;	/* list of Rel_cachebuf */
-	Word		rc_cnt;		/* 	and count */
+	Word		rc_cnt;		/*	and count */
 };
 
 /*
@@ -147,7 +147,7 @@
 	RLXREL_REJ_NONE = 0,	/* Replacement symbol was found */
 	RLXREL_REJ_TARGET,	/* Target sec disallows relaxed relocations */
 	RLXREL_REJ_SECTION,	/* Either there is no replacement section, */
-				/* 	or its attributes are incompatible */
+				/*	or its attributes are incompatible */
 	RLXREL_REJ_SYMBOL,	/* Replacement symbol not found */
 } Rlxrel_rej;
 
@@ -261,15 +261,15 @@
 	APlist		*ofl_ents;	/* list of entrance descriptors */
 	avl_tree_t	ofl_ents_avl;	/* O(log N) access to named ent. desc */
 	APlist		*ofl_objs;	/* relocatable object file list */
-	Word		ofl_objscnt;	/* 	and count */
+	Word		ofl_objscnt;	/*	and count */
 	APlist		*ofl_ars;	/* archive library list */
-	Word		ofl_arscnt;	/* 	and count */
+	Word		ofl_arscnt;	/*	and count */
 	int		ofl_ars_gsandx; /* archive group argv index. 0 means */
 					/*	no current group, < 0 means */
 					/*	error reported. >0 is cur ndx */
 	Word		ofl_ars_gsndx;	/* current -zrescan-start ofl_ars ndx */
 	APlist		*ofl_sos;	/* shared object list */
-	Word		ofl_soscnt;	/* 	and count */
+	Word		ofl_soscnt;	/*	and count */
 	APlist		*ofl_soneed;	/* list of implicitly required .so's */
 	APlist		*ofl_socntl;	/* list of .so control definitions */
 	Rel_cache	ofl_outrels;	/* list of output relocations */
@@ -283,7 +283,7 @@
 	APlist		*ofl_ismove;	/* list of .SUNW_move sections */
 	APlist		*ofl_ismoverel;	/* list of relocation input section */
 					/* targeting to expanded area */
-	APlist		*ofl_parsyms; 	/* list of partially initialized */
+	APlist		*ofl_parsyms;	/* list of partially initialized */
 					/*	symbols (ie. move symbols) */
 	APlist		*ofl_extrarels;	/* relocation sections which have */
 					/*    a NULL sh_info */
@@ -467,6 +467,8 @@
 #define	FLG_OF_FATWARN	0x400000000000	/* make warnings fatal */
 #define	FLG_OF_ADEFLIB	0x800000000000	/* no libraries in default path */
 
+#define	FLG_OF_KMOD	0x1000000000000	/* output is a kernel module */
+
 /*
  * In the flags1 arena, establish any options that are applicable to archive
  * extraction first, and associate a mask.  These values are recorded with any
@@ -536,6 +538,7 @@
 #define	FLG_OFG_NO_MF		0x00000008	/* use v2 mapfile syntax */
 #define	FLG_OFG_NO_TEXT		0x00000010	/* verify pure text segment */
 #define	FLG_OFG_NO_UNUSED	0x00000020	/* remove unused dependency */
+#define	FLG_OFG_NO_KMOD		0x00000040	/* use -z type=kmod */
 
 /*
  * Test to see if a guidance should be given for a given category
@@ -879,7 +882,7 @@
 #define	FLG_IF_DISPPEND 0x00000800	/* displacement relocation done */
 					/*	in the ld time. */
 #define	FLG_IF_DISPDONE 0x00001000	/* displacement relocation done */
-					/* 	at the run time */
+					/*	at the run time */
 #define	FLG_IF_MAPFILE	0x00002000	/* file is a mapfile */
 #define	FLG_IF_HSTRTAB	0x00004000	/* file has a string section */
 #define	FLG_IF_FILEREF	0x00008000	/* file contains a section which */
@@ -916,11 +919,11 @@
 	Elf_Data	*is_indata;	/* input sections raw data */
 	Is_desc		*is_symshndx;	/* related SHT_SYM_SHNDX section */
 	Is_desc		*is_comdatkeep;	/* If COMDAT section is discarded, */
-					/* 	this is section that was kept */
+					/*	this is section that was kept */
 	Word		is_scnndx;	/* original section index in file */
 	Word		is_ordndx;	/* index for section.  Used to decide */
 					/*	where to insert section when */
-					/* 	reordering sections */
+					/*	reordering sections */
 	Word		is_keyident;	/* key for SHF_{ORDERED|LINK_ORDER} */
 					/*	processing and ident used for */
 					/*	 placing/ordering sections */
@@ -990,7 +993,7 @@
 					/*	by section symbol index */
 	Word		os_ordndx;	/* index for section.  Used to decide */
 					/*	where to insert section when */
-					/* 	reordering sections */
+					/*	reordering sections */
 	Xword		os_szoutrels;	/* size of output relocation section */
 	uint_t		os_namehash;	/* hash on section name */
 	uchar_t		os_flags;	/* various flags */
@@ -1067,7 +1070,7 @@
 #define	FLG_SG_P_FLAGS		0x0020	/* p_flags segment attribute set */
 #define	FLG_SG_P_TYPE		0x0040	/* p_type segment attribute set */
 #define	FLG_SG_IS_ORDER		0x0080	/* input section ordering is required */
-					/* 	for this segment. */
+					/*	for this segment. */
 #define	FLG_SG_NOHDR		0x0100	/* don't map ELF or phdrs into */
 					/*	this segment */
 #define	FLG_SG_EMPTY		0x0200	/* an empty segment specification */
@@ -1141,7 +1144,7 @@
 	Move		*md_move;	/* original Move entry */
 	Xword		md_start;	/* start position */
 	Xword		md_len;		/* length of initialization */
-	Word 		md_oidx;	/* output Move entry index */
+	Word		md_oidx;	/* output Move entry index */
 } Mv_desc;
 
 /*
@@ -1172,7 +1175,7 @@
  * important for performance.
  */
 struct sym_aux {
-	APlist 		*sa_dfiles;	/* files where symbol is defined */
+	APlist		*sa_dfiles;	/* files where symbol is defined */
 	Sym		sa_sym;		/* copy of symtab entry */
 	const char	*sa_vfile;	/* first unavailable definition */
 	const char	*sa_rfile;	/* file with first symbol referenced */
@@ -1184,6 +1187,7 @@
 	Half		sa_symspec;	/* special symbol ids */
 	Half		sa_overndx;	/* output file versioning index */
 	Half		sa_dverndx;	/* dependency versioning index */
+	Os_desc		*sa_boundsec;	/* output section of SECBOUND_ syms */
 };
 
 /*
@@ -1200,13 +1204,15 @@
  * These are the ids for processing of `Special symbols'.  They are used
  * to set the sym->sd_aux->sa_symspec field.
  */
-#define	SDAUX_ID_ETEXT	1		/* etext && _etext symbol */
-#define	SDAUX_ID_EDATA	2		/* edata && _edata symbol */
-#define	SDAUX_ID_END	3		/* end, _end, && _END_ symbol */
-#define	SDAUX_ID_DYN	4		/* DYNAMIC && _DYNAMIC symbol */
-#define	SDAUX_ID_PLT	5		/* _PROCEDURE_LINKAGE_TABLE_ symbol */
-#define	SDAUX_ID_GOT	6		/* _GLOBAL_OFFSET_TABLE_ symbol */
-#define	SDAUX_ID_START	7		/* START_ && _START_ symbol */
+#define	SDAUX_ID_ETEXT		1	/* etext && _etext symbol */
+#define	SDAUX_ID_EDATA		2	/* edata && _edata symbol */
+#define	SDAUX_ID_END		3	/* end, _end, && _END_ symbol */
+#define	SDAUX_ID_DYN		4	/* DYNAMIC && _DYNAMIC symbol */
+#define	SDAUX_ID_PLT		5	/* _PROCEDURE_LINKAGE_TABLE_ symbol */
+#define	SDAUX_ID_GOT		6	/* _GLOBAL_OFFSET_TABLE_ symbol */
+#define	SDAUX_ID_START		7	/* START_ && _START_ symbol */
+#define	SDAUX_ID_SECBOUND_START	8	/* __start_<section> symbols */
+#define	SDAUX_ID_SECBOUND_STOP	9	/* __stop_<section> symbols */
 
 /*
  * Flags for sym_desc.sd_flags
@@ -1226,7 +1232,7 @@
 #define	FLG_SY_NOTAVAIL	0x00000020	/* symbol is not available to the */
 					/*	application either because it */
 					/*	originates from an implicitly */
-					/* 	referenced shared object, or */
+					/*	referenced shared object, or */
 					/*	because it is not part of a */
 					/*	specified version. */
 #define	FLG_SY_REDUCED	0x00000040	/* a global is reduced to local */
@@ -1236,7 +1242,7 @@
 #define	FLG_SY_MAPREF	0x00000200	/* symbol reference generated by user */
 					/*	from mapfile */
 #define	FLG_SY_REFRSD	0x00000400	/* symbols sd_ref has been raised */
-					/* 	due to a copy-relocs */
+					/*	due to a copy-relocs */
 					/*	weak-strong pairing */
 #define	FLG_SY_INTPOSE	0x00000800	/* symbol defines an interposer */
 #define	FLG_SY_INVALID	0x00001000	/* unwanted/erroneous symbol */
--- old/usr/src/cmd/sgs/include/sgs.h	2019-02-24 19:19:07.744200219 +0000
+++ new/usr/src/cmd/sgs/include/sgs.h	2019-02-24 19:19:07.759122002 +0000
@@ -194,7 +194,8 @@
 #define	SGS_REJ_PLATCAP		16	/* platform capability mismatch */
 #define	SGS_REJ_HWCAP_2		17	/* hardware capabilities mismatch */
 #define	SGS_REJ_ARCHIVE		18	/* archive used in invalid context */
-#define	SGS_REJ_NUM		19
+#define	SGS_REJ_KMOD		19	/* object is a kernel module */
+#define	SGS_REJ_NUM		20
 
 #define	FLG_REJ_ALTER		0x01	/* object name is an alternative */
 
--- old/usr/src/cmd/sgs/libconv/common/dynamic.c	2019-02-24 19:19:08.163310167 +0000
+++ new/usr/src/cmd/sgs/libconv/common/dynamic.c	2019-02-24 19:19:08.179387770 +0000
@@ -114,7 +114,7 @@
 	MSG_DF_SYMBOLIC_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
 	MSG_DF_TEXTREL_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
 	MSG_DF_BIND_NOW_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
-	MSG_DF_STATIC_TLS_CF_SIZE 	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
+	MSG_DF_STATIC_TLS_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
 	CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
 
 	/*
@@ -557,8 +557,10 @@
 		MSG_DT_SUNW_LDMACH_CF,		0,
 		MSG_DT_SUNW_CAPCHAINENT_CF,	0,
 		MSG_DT_SUNW_CAPCHAINSZ_CF,	0,
-		0, 				0,
-		MSG_DT_SUNW_ASLR_CF
+		0,				0,
+		MSG_DT_SUNW_ASLR_CF,		0,
+		0,				0,
+		MSG_DT_SUNW_KMOD_CF
 	};
 	static const Msg	tags_sunw_auxiliary_cfnp[] = {
 		MSG_DT_SUNW_AUXILIARY_CFNP,	MSG_DT_SUNW_RTLDINF_CFNP,
@@ -572,7 +574,9 @@
 		MSG_DT_SUNW_CAPCHAINENT_CFNP,	0,
 		MSG_DT_SUNW_CAPCHAINSZ_CFNP,	0,
 		0,				0,
-		MSG_DT_SUNW_ASLR_CFNP
+		MSG_DT_SUNW_ASLR_CFNP,		0,
+		0,				0,
+		MSG_DT_SUNW_KMOD_CFNP
 	};
 	static const Msg	tags_sunw_auxiliary_nf[] = {
 		MSG_DT_SUNW_AUXILIARY_NF,	MSG_DT_SUNW_RTLDINF_NF,
@@ -586,7 +590,9 @@
 		MSG_DT_SUNW_CAPCHAINENT_NF,	0,
 		MSG_DT_SUNW_CAPCHAINSZ_NF,	0,
 		0,				0,
-		MSG_DT_SUNW_ASLR_NF
+		MSG_DT_SUNW_ASLR_NF,		0,
+		0,				0,
+		MSG_DT_SUNW_KMOD_NF
 	};
 	static const conv_ds_msg_t ds_sunw_auxiliary_cf = {
 	    CONV_DS_MSG_INIT(DT_SUNW_AUXILIARY, tags_sunw_auxiliary_cf) };
--- old/usr/src/cmd/sgs/libconv/common/dynamic.msg	2019-02-24 19:19:08.628701773 +0000
+++ new/usr/src/cmd/sgs/libconv/common/dynamic.msg	2019-02-24 19:19:08.644724302 +0000
@@ -175,12 +175,15 @@
 @ MSG_DT_SUNW_CAPCHAINENT_CF	"DT_SUNW_CAPCHAINENT"		# 0x6000001d
 @ MSG_DT_SUNW_CAPCHAINENT_CFNP		"SUNW_CAPCHAINENT"
 @ MSG_DT_SUNW_CAPCHAINENT_NF		"sunw_capchainent"
-@ MSG_DT_SUNW_CAPCHAINSZ_CF	"DT_SUNW_CAPCHAINSZ"		# 0x6000001d
+@ MSG_DT_SUNW_CAPCHAINSZ_CF	"DT_SUNW_CAPCHAINSZ"		# 0x6000001f
 @ MSG_DT_SUNW_CAPCHAINSZ_CFNP		"SUNW_CAPCHAINSZ"
 @ MSG_DT_SUNW_CAPCHAINSZ_NF		"sunw_capchainsz"
 @ MSG_DT_SUNW_ASLR_CF		"DT_SUNW_ASLR"			# 0x60000023
 @ MSG_DT_SUNW_ASLR_CFNP			"SUNW_ASLR"
 @ MSG_DT_SUNW_ASLR_NF			"sunw_aslr"
+@ MSG_DT_SUNW_KMOD_CF		"DT_SUNW_KMOD"			# 0x60000027
+@ MSG_DT_SUNW_KMOD_CFNP			"SUNW_KMOD"
+@ MSG_DT_SUNW_KMOD_NF			"sunw_kmod"
 
 @ MSG_DT_GNU_PRELINKED_CF	"DT_GNU_PRELINKED"		# 0x6ffffdf5
 @ MSG_DT_GNU_PRELINKED_CFNP		"GNU_PRELINKED"
--- old/usr/src/cmd/sgs/libconv/common/elf.c	2019-02-24 19:19:09.081600028 +0000
+++ new/usr/src/cmd/sgs/libconv/common/elf.c	2019-02-24 19:19:09.097079304 +0000
@@ -1211,6 +1211,7 @@
 		    &reject_desc_buf->flags_buf));
 	case SGS_REJ_UNKFILE:
 	case SGS_REJ_ARCHIVE:
+	case SGS_REJ_KMOD:
 		return (NULL);
 	case SGS_REJ_STR:
 	case SGS_REJ_HWCAP_1:
--- old/usr/src/cmd/sgs/libelf/common/gelf.c	2019-02-24 19:19:09.560570058 +0000
+++ new/usr/src/cmd/sgs/libelf/common/gelf.c	2019-02-24 19:19:09.575587223 +0000
@@ -698,7 +698,7 @@
 
 GElf_Sym *
 gelf_getsymshndx(Elf_Data *symdata, Elf_Data *shndxdata,
-	int ndx, GElf_Sym *symptr, Elf32_Word *xshndx)
+    int ndx, GElf_Sym *symptr, Elf32_Word *xshndx)
 {
 	if (gelf_getsym(symdata, ndx, symptr) == 0)
 		return (NULL);
@@ -719,7 +719,7 @@
 
 int
 gelf_update_symshndx(Elf_Data *symdata, Elf_Data *shndxdata,
-	int ndx, GElf_Sym *symptr, Elf32_Word xshndx)
+    int ndx, GElf_Sym *symptr, Elf32_Word xshndx)
 {
 	if (gelf_update_sym(symdata, ndx, symptr) == 0)
 		return (0);
@@ -1091,7 +1091,7 @@
  * Otherwise, return 0.
  */
 GElf_Xword
-_gelf_getdyndtflags_1(Elf *elf)
+_gelf_getdynval(Elf *elf, GElf_Sxword tag)
 {
 	Elf_Scn *scn = NULL;
 	Elf_Data *data;
@@ -1108,7 +1108,7 @@
 			n = shdr.sh_size / shdr.sh_entsize;
 			for (i = 0; i < n; i++) {
 				(void) gelf_getdyn(data, i, &dyn);
-				if (dyn.d_tag == DT_FLAGS_1) {
+				if (dyn.d_tag == tag) {
 					return (dyn.d_un.d_val);
 				}
 			}
@@ -1117,3 +1117,9 @@
 	}
 	return (0);
 }
+
+GElf_Xword
+_gelf_getdyndtflags_1(Elf *elf)
+{
+	return (_gelf_getdynval(elf, DT_FLAGS_1));
+}
--- old/usr/src/cmd/sgs/libelf/common/mapfile-vers	2019-02-24 19:19:10.009609024 +0000
+++ new/usr/src/cmd/sgs/libelf/common/mapfile-vers	2019-02-24 19:19:10.025091909 +0000
@@ -170,6 +170,7 @@
 	_elf_sys_encoding;
 	_elf_swap_wrimage;
 	_gelf_getdyndtflags_1;
+	_gelf_getdynval;
 
 $if _ELF32
 	elf_demangle;
--- old/usr/src/cmd/sgs/libld/common/args.c	2019-02-24 19:19:10.443450828 +0000
+++ new/usr/src/cmd/sgs/libld/common/args.c	2019-02-24 19:19:10.459065182 +0000
@@ -37,7 +37,7 @@
  *    OPTION			MEANING
  *
  *    -z dtrace=symbol		assigns symbol to PT_SUNWDTRACE segment,
- *    				providing scratch area for dtrace processing.
+ *				providing scratch area for dtrace processing.
  *
  *    -z noreloc		suppress relocation processing.  This provides
  *				a mechanism for validating kernel module symbol
@@ -103,7 +103,6 @@
 
 static Boolean	aflag	= FALSE;
 static Boolean	bflag	= FALSE;
-static Boolean	rflag	= FALSE;
 static Boolean	sflag	= FALSE;
 static Boolean	zinflag = FALSE;
 static Boolean	zlflag	= FALSE;
@@ -112,9 +111,17 @@
 static Boolean	Beflag	= FALSE;
 static Boolean	Bsflag	= FALSE;
 static Boolean	Dflag	= FALSE;
-static Boolean	Gflag	= FALSE;
 static Boolean	Vflag	= FALSE;
 
+enum output_type {
+	OT_RELOC,		/* relocatable object */
+	OT_SHARED,		/* shared object */
+	OT_EXEC,		/* dynamic executable */
+	OT_KMOD,		/* kernel module */
+};
+
+static enum output_type	otype = OT_EXEC;
+
 /*
  * ztflag's state is set by pointing it to the matching string:
  *	text | textoff | textwarn
@@ -228,6 +235,7 @@
 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZT));
 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTO));
 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTW));
+	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZTY));
 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZWRAP));
 	(void) fprintf(stderr, MSG_INTL(MSG_ARG_DETAIL_ZVER));
 }
@@ -313,18 +321,46 @@
 		ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_YP),
 		    Llibdir ? 'L' : 'U');
 
-	if (rflag) {
-		if (dflag == SET_UNKNOWN)
-			dflag = SET_FALSE;
+	if ((otype == OT_RELOC) || (otype == OT_KMOD)) {
+		if (otype == OT_RELOC) {
+			if (dflag == SET_UNKNOWN)
+				dflag = SET_FALSE;
+			if ((dflag == SET_TRUE) &&
+			    OFL_GUIDANCE(ofl, FLG_OFG_NO_KMOD)) {
+				ld_eprintf(ofl, ERR_GUIDANCE,
+				    MSG_INTL(MSG_GUIDE_KMOD));
+			}
+		} else if (otype == OT_KMOD) {
+			if (dflag != SET_UNKNOWN) {
+				ld_eprintf(ofl, ERR_FATAL,
+				    MSG_INTL(MSG_MARG_INCOMP),
+				    MSG_INTL(MSG_MARG_TYPE_KMOD),
+				    MSG_ORIG(MSG_ARG_D));
+			}
+
+			dflag = SET_TRUE;
+		}
+
 		/*
 		 * Combining relocations when building a relocatable
 		 * object isn't allowed.  Warn the user, but proceed.
 		 */
-		if (ofl->ofl_flags & FLG_OF_COMREL)
+		if (ofl->ofl_flags & FLG_OF_COMREL) {
+			const char *msg;
+
+			if (otype == OT_RELOC) {
+				msg = MSG_INTL(MSG_MARG_REL);
+			} else {
+				msg = MSG_INTL(MSG_MARG_TYPE_KMOD);
+			}
 			ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_MARG_INCOMP),
-			    MSG_INTL(MSG_MARG_REL),
+			    msg,
 			    MSG_ORIG(MSG_ARG_ZCOMBRELOC));
+		}
 		ofl->ofl_flags |= FLG_OF_RELOBJ;
+
+		if (otype == OT_KMOD)
+			ofl->ofl_flags |= FLG_OF_KMOD;
 	} else {
 		/*
 		 * Translating object capabilities to symbol capabilities is
@@ -375,7 +411,7 @@
 		    MSG_ORIG(MSG_ARG_ZRELAXRELOC),
 		    MSG_ORIG(MSG_ARG_ZNORELAXRELOC));
 
-	if (ofl->ofl_filtees && !Gflag)
+	if (ofl->ofl_filtees && (otype != OT_SHARED))
 		ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ST_ONLYAVL),
 		    ((ofl->ofl_flags & FLG_OF_AUX) ?
 		    MSG_INTL(MSG_MARG_FILTER_AUX) : MSG_INTL(MSG_MARG_FILTER)));
@@ -429,7 +465,7 @@
 			ofl->ofl_guideflags |= FLG_OFG_NO_TEXT;
 		}
 
-		if (Gflag || !rflag) {
+		if ((otype == OT_SHARED) || (otype == OT_EXEC)) {
 			/*
 			 * Create a dynamic object.  -Bdirect indicates that all
 			 * references should be bound directly.  This also
@@ -469,7 +505,7 @@
 			}
 		}
 
-		if (!Gflag && !rflag) {
+		if (otype == OT_EXEC) {
 			/*
 			 * Dynamically linked executable.
 			 */
@@ -493,7 +529,7 @@
 				ld_eprintf(ofl, ERR_FATAL,
 				    MSG_INTL(MSG_MARG_DY_INCOMP),
 				    MSG_INTL(MSG_MARG_SONAME));
-		} else if (!rflag) {
+		} else if (otype == OT_SHARED) {
 			/*
 			 * Shared library.
 			 */
@@ -543,6 +579,9 @@
 				    MSG_INTL(MSG_MARG_REL),
 				    MSG_ORIG(MSG_ARG_CI));
 		}
+
+		assert((ofl->ofl_flags & (FLG_OF_SHAROBJ|FLG_OF_EXEC)) !=
+		    (FLG_OF_SHAROBJ|FLG_OF_EXEC));
 	} else {
 		ofl->ofl_flags |= FLG_OF_STATIC;
 
@@ -564,14 +603,14 @@
 		if (ztflag)
 			ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ARG_ST_INCOMP),
 			    MSG_ORIG(MSG_ARG_ZTEXTALL));
-		if (Gflag)
+		if (otype == OT_SHARED)
 			ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_ST_INCOMP),
 			    MSG_INTL(MSG_MARG_SO));
-		if (aflag && rflag)
+		if (aflag && (otype == OT_RELOC))
 			ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_MARG_INCOMP),
 			    MSG_ORIG(MSG_ARG_A), MSG_INTL(MSG_MARG_REL));
 
-		if (rflag) {
+		if (otype == OT_RELOC) {
 			/*
 			 * We can only strip the symbol table and string table
 			 * if no output relocations will refer to them.
@@ -717,7 +756,7 @@
 
 	/*
 	 * The argument being examined is either:
-	 *	ld32= 	or
+	 *	ld32=	or
 	 *	ld64=
 	 */
 #if	defined(_LP64)
@@ -917,8 +956,8 @@
 /*
  * Parse the -z assert-deflib option. This option can appear in two different
  * forms:
- * 	-z assert-deflib
- * 	-z assert-deflib=libfred.so
+ *	-z assert-deflib
+ *	-z assert-deflib=libfred.so
  *
  * Either form enables this option, the latter form marks libfred.so as an
  * exempt library from the check. It is valid to have multiple invocations of
@@ -1201,7 +1240,7 @@
 
 		case 'r':
 			DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
-			rflag = TRUE;
+			otype = OT_RELOC;
 			break;
 
 		case 'R':
@@ -1509,6 +1548,35 @@
 			    MSG_ARG_ASSDEFLIB_SIZE) == 0) {
 				if (assdeflib_parse(ofl, optarg) != TRUE)
 					return (S_ERROR);
+			} else if (strncmp(optarg, MSG_ORIG(MSG_ARG_TYPE),
+			    MSG_ARG_TYPE_SIZE) == 0) {
+				char *p = optarg + MSG_ARG_TYPE_SIZE;
+				if (*p != '=') {
+					ld_eprintf(ofl, ERR_FATAL,
+					    MSG_INTL(MSG_ARG_ILLEGAL),
+					    MSG_ORIG(MSG_ARG_Z), optarg);
+					return (S_ERROR);
+				}
+
+				p++;
+				if (strcmp(p,
+				    MSG_ORIG(MSG_ARG_TYPE_RELOC)) == 0) {
+					otype = OT_RELOC;
+				} else if (strcmp(p,
+				    MSG_ORIG(MSG_ARG_TYPE_EXEC)) == 0) {
+					otype = OT_EXEC;
+				} else if (strcmp(p,
+				    MSG_ORIG(MSG_ARG_TYPE_SHARED)) == 0) {
+					otype = OT_SHARED;
+				} else if (strcmp(p,
+				    MSG_ORIG(MSG_ARG_TYPE_KMOD)) == 0) {
+					otype = OT_KMOD;
+				} else {
+					ld_eprintf(ofl, ERR_FATAL,
+					    MSG_INTL(MSG_ARG_ILLEGAL),
+					    MSG_ORIG(MSG_ARG_Z), optarg);
+					return (S_ERROR);
+				}
 			/*
 			 * The following options just need validation as they
 			 * are interpreted on the second pass through the
@@ -1627,7 +1695,7 @@
 
 		case 'G':
 			DBG_CALL(Dbg_args_option(ofl->ofl_lml, ndx, c, NULL));
-			Gflag = TRUE;
+			otype = OT_SHARED;
 			break;
 
 		case 'L':
--- old/usr/src/cmd/sgs/libld/common/files.c	2019-02-24 19:19:10.996040781 +0000
+++ new/usr/src/cmd/sgs/libld/common/files.c	2019-02-24 19:19:11.011657862 +0000
@@ -2356,7 +2356,7 @@
 static uintptr_t
 rel_process(Is_desc *isc, Ifl_desc *ifl, Ofl_desc *ofl)
 {
-	Word 	rndx;
+	Word	rndx;
 	Is_desc	*risc;
 	Os_desc	*osp;
 	Shdr	*shdr = isc->is_shdr;
@@ -3193,6 +3193,20 @@
 			if (rej->rej_type == 0) {
 				*rej = _rej;
 				rej->rej_name = strdup(_rej.rej_name);
+			}
+			return (0);
+		}
+
+		if (_gelf_getdynval(elf, DT_SUNW_KMOD) == 1) {
+			_rej.rej_name = name;
+			DBG_CALL(Dbg_file_rejected(ofl->ofl_lml, &_rej,
+			    ld_targ.t_m.m_mach));
+			_rej.rej_type = SGS_REJ_KMOD;
+			_rej.rej_str = elf_errmsg(-1);
+
+			if (rej->rej_type == 0) {
+				*rej = _rej;
+				rej->rej_name = strdup(_rej.rej_name);
 			}
 			return (0);
 		}
--- old/usr/src/cmd/sgs/libld/common/globals.c	2019-02-24 19:19:11.563549030 +0000
+++ new/usr/src/cmd/sgs/libld/common/globals.c	2019-02-24 19:19:11.578204633 +0000
@@ -34,7 +34,7 @@
 #include	"_libld.h"
 
 Ld_heap		*ld_heap;	/* list of allocated blocks for */
-				/* 	link-edit dynamic allocations */
+				/*	link-edit dynamic allocations */
 APlist		*lib_support;	/* list of support libraries specified */
 				/*	(-S option) */
 int		demangle_flag;	/* symbol demangling required */
@@ -78,9 +78,10 @@
 		MSG_REJ_MACHCAP,	/* MSG_INTL(MSG_REJ_MACHCAP) */
 		MSG_REJ_PLATCAP,	/* MSG_INTL(MSG_REJ_PLATCAP) */
 		MSG_REJ_HWCAP_2,	/* MSG_INTL(MSG_REJ_HWCAP_2) */
-		MSG_REJ_ARCHIVE		/* MSG_INTL(MSG_REJ_ARCHIVE) */
+		MSG_REJ_ARCHIVE,	/* MSG_INTL(MSG_REJ_ARCHIVE) */
+		MSG_REJ_KMOD		/* MSG_INTL(MSG_REJ_KMOD) */
 	};
-#if SGS_REJ_NUM != (SGS_REJ_ARCHIVE + 1)
+#if SGS_REJ_NUM != (SGS_REJ_KMOD + 1)
 #error SGS_REJ_NUM has changed
 #endif
 
--- old/usr/src/cmd/sgs/libld/common/libld.msg	2019-02-24 19:19:11.964074938 +0000
+++ new/usr/src/cmd/sgs/libld/common/libld.msg	2019-02-24 19:19:11.979030160 +0000
@@ -36,7 +36,7 @@
 
 #
 # TRANSLATION_NOTE -- Beginning of USAGE message
-# 	The following messages are the usage messages for the ld command.
+#	The following messages are the usage messages for the ld command.
 #	Tab characters (\t) are used to align the messages.
 #
 #	Each usage message starts with \t, and if the message has more than one
@@ -54,9 +54,9 @@
 #	In C locale, the first 3 messages would look like the following:
 #
 #	usage: ld [-6:abc:.....] file(s)
-#        	[-a]            create an absolute file
-#        	[-b]            do not do special PIC relocations in a.out
-#        	[-c file]       record configuration 'file'
+#		[-a]		create an absolute file
+#		[-b]		do not do special PIC relocations in a.out
+#		[-c file]	record configuration 'file'
 #
 @ MSG_ARG_USAGE		"usage: ld [-%s] file(s)\n"
 @ MSG_ARG_DETAIL_3	"\t[-32]\t\tenforce a 32-bit link-edit\n"
@@ -251,6 +251,8 @@
 			 text\n"
 @ MSG_ARG_DETAIL_ZTW	"\t[-z textwarn]\twarn if there are relocations \
 			 against text\n"
+@ MSG_ARG_DETAIL_ZTY	"\t[-z type=type]\tspecify the type of object \
+			 (exec, kmod, reloc, shared)\n"
 @ MSG_ARG_DETAIL_ZWRAP	"\t[-z wrap=symbol], [-wrap=symbol], [--wrap=symbol]\n\
 			 \t\t\twrap symbol references\n"
 @ MSG_ARG_DETAIL_ZVER	"\t[-z verbose]\t\
@@ -353,13 +355,13 @@
 
 #
 # TRANSLATION_NOTE
-# 	The following 7 messages are the message to print the
+#	The following 7 messages are the message to print the
 #	following example messages.
 #
 #Text relocation remains		      referenced
 #    against symbol		    offset	in file
-#str                                 0x14      	main.o
-#printf                              0x1c      	main.o
+#str				     0x14	main.o
+#printf				     0x1c	main.o
 #
 #	The first two lines are the header, and the next msgid
 #	is the format string for the header.
@@ -476,7 +478,7 @@
 
 @ MSG_SCN_DWFOVRFLW	"%s: section %s: encoded DWARF data exceeds \
 			 section size"
-@ MSG_SCN_DWFBADENC	"%s: section %s: invalid DWARF encoding: %#x"                         
+@ MSG_SCN_DWFBADENC	"%s: section %s: invalid DWARF encoding: %#x"
 
 # Symbol processing errors
 
@@ -543,11 +545,11 @@
 
 #
 # TRANSLATION_NOTE
-# 	The following 7 messages are the message to print the
+#	The following 7 messages are the message to print the
 #	following example messages.
 #
 #Undefined			first referenced
-# symbol  			    in file
+# symbol			    in file
 #inquire                            halt_hold.o
 #
 @ MSG_SYM_FMT_UNDEF	"%s\t\t\t%s\
@@ -694,6 +696,7 @@
 @ MSG_REJ_HWCAP_2	"file %s: hardware capability (CA_SUNW_HW_2) \
 			 unsupported: %s"
 @ MSG_REJ_ARCHIVE	"file %s: invalid archive use"
+@ MSG_REJ_KMOD		"file %s: kernel modules can't be link-edit input"
 
 # Guidance messages
 @ MSG_GUIDE_SUMMARY	"see ld(1) -z guidance for more information"
@@ -706,6 +709,7 @@
 @ MSG_GUIDE_TEXT	"position independent (PIC) code recommended for \
 			 shared objects"
 @ MSG_GUIDE_UNUSED	"removal of unused dependency recommended: %s"
+@ MSG_GUIDE_KMOD	"use -z type=kmod, not -r -dy"
 
 @ _END_
 
@@ -879,6 +883,9 @@
 @ MSG_SYM_L_START	"START_"
 @ MSG_SYM_L_START_U	"_START_"
 
+@ MSG_SYM_SECBOUND_START "__start_"
+@ MSG_SYM_SECBOUND_STOP "__stop_"
+
 # Support functions
 
 @ MSG_SUP_VERSION	"ld_version"
@@ -898,10 +905,10 @@
 @ MSG_SUP_INSEC		"ld_input_section"
 @ MSG_SUP_SEC		"ld_section"
 
-# 
+#
 # Message previously in 'ld'
 #
-# 
+#
 @ _START_
 
 # System error messages
@@ -962,11 +969,13 @@
 @ MSG_MARG_FILTER_AUX	"auxiliary filter option (-f, --auxiliary)"
 @ MSG_MARG_FILTER	"filter option (-F, --filter)"
 @ MSG_MARG_OUTFILE	"output object option (-o, --output)"
-@ MSG_MARG_REL		"relocatable object option (-r, --relocatable)"
+@ MSG_MARG_REL		"relocatable object option (-r, --relocatable, \
+			-z type=reloc)"
 @ MSG_MARG_RPATH	"runpath option (-R, -rpath)"
-@ MSG_MARG_SO		"shared object option (-G, -shared)"
+@ MSG_MARG_SO		"shared object option (-G, -shared, -z type=shared)"
 @ MSG_MARG_SONAME	"soname option (-h, --soname)"
 @ MSG_MARG_STRIP	"strip option (-s, --strip-all)"
+@ MSG_MARG_TYPE_KMOD	"-z type=kmod"
 
 # Entrance criteria messages
 
@@ -979,7 +988,7 @@
 # The next message is a format string for a title. The title is composed of
 # two lines. In C locale, it would look like:
 #
-# 	output		input		new
+#	output		input		new
 #	section		section		displacement	size
 #
 # The \t characters are used for alignment.  (output section), (input section),
@@ -1307,7 +1316,7 @@
 @ MSG_STR_PATH		"%s/%s"
 @ MSG_STR_STRNL		"%s\n"
 @ MSG_STR_NL		"\n"
-@ MSG_STR_CAPGROUPID 	"CAP_GROUP_%d"
+@ MSG_STR_CAPGROUPID	"CAP_GROUP_%d"
 
 @ MSG_STR_LD_DYNAMIC	"dynamic"
 @ MSG_STR_SYMBOLIC	"symbolic"
@@ -1443,6 +1452,7 @@
 @ MSG_ARG_DEFERRED	"deferred"
 @ MSG_ARG_NODEFERRED	"nodeferred"
 @ MSG_ARG_ASSDEFLIB	"assert-deflib"
+@ MSG_ARG_TYPE		"type"
 
 @ MSG_ARG_LCOM		"L,"
 @ MSG_ARG_PCOM		"P,"
@@ -1492,6 +1502,12 @@
 @ MSG_ARG_GUIDE_NO_TEXT		"notext"
 @ MSG_ARG_GUIDE_NO_UNUSED	"nounused"
 
+# -z type= strings
+@ MSG_ARG_TYPE_RELOC	"reloc"
+@ MSG_ARG_TYPE_EXEC	"exec"
+@ MSG_ARG_TYPE_SHARED	"shared"
+@ MSG_ARG_TYPE_KMOD	"kmod"
+
 # Environment variable strings
 
 @ MSG_LD_RUN_PATH	"LD_RUN_PATH"
--- old/usr/src/cmd/sgs/libld/common/relocate.c	2019-02-24 19:19:12.456743844 +0000
+++ new/usr/src/cmd/sgs/libld/common/relocate.c	2019-02-24 19:19:12.471317391 +0000
@@ -76,12 +76,12 @@
  */
 typedef struct copy_rel {
 	Sym_desc	*c_sdp;		/* symbol descriptor to be copied */
-	Addr 		c_val;		/* original symbol value */
+	Addr		c_val;		/* original symbol value */
 } Copy_rel;
 
 /*
  * For each copy relocation symbol, determine if the symbol is:
- * 	1) to be *disp* relocated at runtime
+ *	1) to be *disp* relocated at runtime
  *	2) a reference symbol for *disp* relocation
  *	3) possibly *disp* relocated at ld time.
  *
@@ -1543,7 +1543,7 @@
 	 *  -	the -Bsymbolic flag is in use when building a shared object,
 	 *	and the symbol hasn't explicitly been defined as nodirect.
 	 *
-	 *  -	an executable (fixed address) is being created, and the symbol
+	 *  -	an executable (fixed address) )is being created, and the symbol
 	 *	is defined in the executable.
 	 *
 	 *  -	the relocation is against a segment which will not be loaded
@@ -2264,7 +2264,7 @@
 	Shdr		*rshdr = rsect->is_shdr;
 	Is_desc		*misp;
 	Shdr		*mshdr;
-	Xword 		midx;
+	Xword		midx;
 	Move		*mvp;
 
 	/*
@@ -2296,8 +2296,8 @@
 {
 	Ifl_desc	*file = rsect->is_file;
 	Rel		*rend, *reloc;
-	Xword 		rsize, entsize;
-	Rel_desc 	reld;
+	Xword		rsize, entsize;
+	Rel_desc	reld;
 	Rel_aux	rel_aux;
 
 	rsize = rsect->is_shdr->sh_size;
@@ -2961,7 +2961,7 @@
 ld_am_I_partial(Rel_desc *reld, Xword val)
 {
 	Ifl_desc	*ifile = reld->rel_sym->sd_isc->is_file;
-	int 		nlocs = ifile->ifl_locscnt, i;
+	int		nlocs = ifile->ifl_locscnt, i;
 
 	for (i = 1; i < nlocs; i++) {
 		Sym		*osym;
--- old/usr/src/cmd/sgs/libld/common/sections.c	2019-02-24 19:19:13.003777207 +0000
+++ new/usr/src/cmd/sgs/libld/common/sections.c	2019-02-24 19:19:13.019820306 +0000
@@ -1274,6 +1274,9 @@
 			cnt++;
 	}
 
+	if (ofl->ofl_flags & FLG_OF_KMOD)
+		cnt++;
+
 	/*
 	 * Account for Architecture dependent .dynamic entries, and defaults.
 	 */
@@ -2432,7 +2435,7 @@
 	Is_desc		*isec;
 	size_t		size;
 	Xword		sh_flags;
-	char 		*sectname;
+	char		*sectname;
 	Os_desc		*rosp;
 	Word		relsize;
 	const char	*rel_prefix;
@@ -2663,7 +2666,7 @@
 	Is_desc		*isec;
 	Aliste		idx;
 	Sym_desc	*sdp;
-	int 		cnt = 1;
+	int		cnt = 1;
 
 
 	if (new_section(ofl, SHT_SUNW_move, MSG_ORIG(MSG_SCN_SUNWMOVE),
--- old/usr/src/cmd/sgs/libld/common/syms.c	2019-02-24 19:19:13.478479647 +0000
+++ new/usr/src/cmd/sgs/libld/common/syms.c	2019-02-24 19:19:13.487887128 +0000
@@ -636,7 +636,7 @@
     sd_flag_t sdflags_u, sd_flag_t sdflags, Ofl_desc *ofl)
 {
 	Sym_desc	*sdp;
-	Sym_desc 	*usdp;
+	Sym_desc	*usdp;
 	Sym		*sym;
 	Word		hash;
 	avl_index_t	where;
@@ -692,9 +692,10 @@
 				usdp->sd_flags |= FLG_SY_MAPUSED;
 
 			DBG_CALL(Dbg_syms_updated(ofl, usdp, uname));
-		} else
+		} else {
 			ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_SYM_RESERVE),
 			    uname, usdp->sd_file->ifl_name);
+		}
 	} else {
 		/*
 		 * If the symbol does not exist create it.
@@ -795,7 +796,7 @@
  *
  *  -	the symbol has been defined by an implicitly supplied library, ie. one
  *	which was encounted because it was NEEDED by another library, rather
- * 	than from a command line supplied library which would become the only
+ *	than from a command line supplied library which would become the only
  *	dependency of the output file being produced.
  *
  *  -	the symbol has been defined by a version of a shared object that is
@@ -885,6 +886,72 @@
 }
 
 /*
+ * If an undef symbol exists naming a bound for the output section,
+ * turn it into a defined symbol with the correct value.
+ *
+ * We set an arbitrary 1KB limit on the resulting symbol names.
+ */
+static void
+sym_add_bounds(Ofl_desc *ofl, Os_desc *osp, Word bound)
+{
+	Sym_desc *bsdp;
+	char symn[1024];
+	size_t nsz;
+
+	switch (bound) {
+	case SDAUX_ID_SECBOUND_START:
+		nsz = snprintf(symn, sizeof (symn), "%s%s",
+		    MSG_ORIG(MSG_SYM_SECBOUND_START), osp->os_name);
+		if (nsz >= sizeof (symn))
+			return;
+		break;
+	case SDAUX_ID_SECBOUND_STOP:
+		nsz = snprintf(symn, sizeof (symn), "%s%s",
+		    MSG_ORIG(MSG_SYM_SECBOUND_STOP), osp->os_name);
+		if (nsz >= sizeof (symn))
+			return;
+		break;
+	default:
+		assert(0);
+	}
+
+	if ((bsdp = ld_sym_find(symn, SYM_NOHASH, NULL, ofl)) != NULL) {
+		if ((bsdp->sd_shndx != SHN_UNDEF) &&
+		    (bsdp->sd_ref == REF_REL_NEED)) {
+			ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_SYM_RESERVE),
+			    symn, bsdp->sd_file->ifl_name);
+			return;
+		}
+
+		DBG_CALL(Dbg_syms_updated(ofl, bsdp, symn));
+
+		bsdp->sd_aux->sa_symspec = bound;
+		bsdp->sd_aux->sa_boundsec = osp;
+		bsdp->sd_flags |= FLG_SY_SPECSEC;
+		bsdp->sd_ref = REF_REL_NEED;
+		bsdp->sd_sym->st_info = ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE);
+		bsdp->sd_sym->st_other = STV_PROTECTED;
+		bsdp->sd_isc = NULL;
+		bsdp->sd_sym->st_size = 0;
+		bsdp->sd_sym->st_value = 0;
+		bsdp->sd_shndx = bsdp->sd_sym->st_shndx = SHN_ABS;
+	}
+}
+
+static Boolean
+is_cname(const char *name)
+{
+	if (strlen(name) == strspn(name,
+	    "abcdefghijklmnopqrstuvwxyz"
+	    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+	    "0123456789"
+	    "_"))
+		return (TRUE);
+	else
+		return (FALSE);
+}
+
+/*
  * At this point all symbol input processing has been completed, therefore
  * complete the symbol table entries by generating any necessary internal
  * symbols.
@@ -893,12 +960,39 @@
 ld_sym_spec(Ofl_desc *ofl)
 {
 	Sym_desc	*sdp;
+	Sg_desc		*sgp;
+	Aliste		idx1;
+
+	DBG_CALL(Dbg_syms_spec_title(ofl->ofl_lml));
+
+	/*
+	 * For each section in the output file, look for symbols named for the
+	 * __start/__stop patterns.  If references exist, flesh the symbols to
+	 * be defined.
+	 *
+	 * The symbols are given values at the same time as the other special
+	 * symbols.
+	 */
+	if (!(ofl->ofl_flags & FLG_OF_RELOBJ) ||
+	    (ofl->ofl_flags & FLG_OF_KMOD)) {
+		for (APLIST_TRAVERSE(ofl->ofl_segs, idx1, sgp)) {
+			Os_desc *osp;
+			Aliste idx2;
+
+			for (APLIST_TRAVERSE(sgp->sg_osdescs, idx2, osp)) {
+				if (is_cname(osp->os_name)) {
+					sym_add_bounds(ofl, osp,
+					    SDAUX_ID_SECBOUND_START);
+					sym_add_bounds(ofl, osp,
+					    SDAUX_ID_SECBOUND_STOP);
+				}
+			}
+		}
+	}
 
 	if (ofl->ofl_flags & FLG_OF_RELOBJ)
 		return (1);
 
-	DBG_CALL(Dbg_syms_spec_title(ofl->ofl_lml));
-
 	if (sym_add_spec(MSG_ORIG(MSG_SYM_ETEXT), MSG_ORIG(MSG_SYM_ETEXT_U),
 	    SDAUX_ID_ETEXT, 0, (FLG_SY_DEFAULT | FLG_SY_EXPDEF),
 	    ofl) == S_ERROR)
@@ -1133,7 +1227,7 @@
  * or modified), validate and count the relevant entries:
  *
  *  -	check and print any undefined symbols remaining.  Note that if a symbol
- *	has been defined by virtue of the inclusion of 	an implicit shared
+ *	has been defined by virtue of the inclusion of	an implicit shared
  *	library, it is still classed as undefined.
  *
  *  -	count the number of global needed symbols together with the size of
@@ -1141,7 +1235,7 @@
  *	symbols may be reduced to locals).
  *
  *  -	establish the size and alignment requirements for the global .bss
- *	section (the alignment of this section is based on the 	first symbol
+ *	section (the alignment of this section is based on the first symbol
  *	that it will contain).
  */
 uintptr_t
@@ -1890,7 +1984,7 @@
  * input sections from this input file have been assigned an input section
  * descriptor which is saved in the `ifl_isdesc' array.
  *
- *  -	local symbols are saved (as is) if the input file is a 	relocatable
+ *  -	local symbols are saved (as is) if the input file is a	relocatable
  *	object
  *
  *  -	global symbols are added to the linkers internal symbol table if they
--- old/usr/src/cmd/sgs/libld/common/update.c	2019-02-24 19:19:13.931556487 +0000
+++ new/usr/src/cmd/sgs/libld/common/update.c	2019-02-24 19:19:13.950669233 +0000
@@ -184,7 +184,7 @@
 #endif
 	Addr		bssaddr, etext = 0, edata = 0, end = 0, start = 0;
 	Addr		tlsbssaddr = 0;
-	Addr 		parexpnbase, parexpnaddr;
+	Addr		parexpnbase, parexpnaddr;
 	int		start_set = 0;
 	Sym		_sym = {0}, *sym, *symtab = NULL;
 	Sym		*dynsym = NULL, *ldynsym = NULL;
@@ -1333,7 +1333,7 @@
 				 *	keyword in a mapfile.
 				 *
 				 *  -	Symbol reference has been bound to a
-				 * 	dependency which was specified as
+				 *	dependency which was specified as
 				 *	requiring direct bindings with -zdirect.
 				 *
 				 *  -	All symbol references are required to
@@ -1768,6 +1768,19 @@
 				    ofl_osgot->os_scn);
 				sdp->sd_flags &= ~FLG_SY_SPECSEC;
 				break;
+			case SDAUX_ID_SECBOUND_START:
+				sym->st_value = sap->sa_boundsec->
+				    os_shdr->sh_addr;
+				sectndx = elf_ndxscn(sap->sa_boundsec->os_scn);
+				sdp->sd_flags &= ~FLG_SY_SPECSEC;
+				break;
+			case SDAUX_ID_SECBOUND_STOP:
+				sym->st_value = sap->sa_boundsec->
+				    os_shdr->sh_addr +
+				    sap->sa_boundsec->os_shdr->sh_size;
+				sectndx = elf_ndxscn(sap->sa_boundsec->os_scn);
+				sdp->sd_flags &= ~FLG_SY_SPECSEC;
+				break;
 			default:
 				/* NOTHING */
 				;
@@ -2579,6 +2592,12 @@
 	dyn->d_un.d_val = ld_sunw_ldmach();
 	dyn++;
 
+	if (ofl->ofl_flags & FLG_OF_KMOD) {
+		dyn->d_tag = DT_SUNW_KMOD;
+		dyn->d_un.d_val = 1;
+		dyn++;
+	}
+
 	(*ld_targ.t_mr.mr_mach_update_odynamic)(ofl, &dyn);
 
 	for (cnt = 1 + DYNAMIC_EXTRA_ELTS; cnt--; dyn++) {
@@ -3157,7 +3176,7 @@
 					    imvp->m_info);
 				}
 			} else {
-				Boolean 	isredloc = FALSE;
+				Boolean		isredloc = FALSE;
 
 				if ((ELF_ST_BIND(sym->st_info) == STB_LOCAL) &&
 				    (ofl->ofl_flags & FLG_OF_REDLSYM))
@@ -3652,7 +3671,7 @@
 	DBG_CALL(Dbg_seg_title(ofl->ofl_lml));
 	for (APLIST_TRAVERSE(ofl->ofl_segs, idx1, sgp)) {
 		Phdr		*phdr = &(sgp->sg_phdr);
-		Xword 		p_align;
+		Xword		p_align;
 		Aliste		idx2;
 		Sym_desc	*sdp;
 
@@ -3872,8 +3891,8 @@
 			 * Check overlaps
 			 */
 			for (i = 0; i < phdrndx - 1; i++) {
-				Addr 	p_s = (ofl->ofl_phdr[i]).p_vaddr;
-				Addr 	p_e;
+				Addr	p_s = (ofl->ofl_phdr[i]).p_vaddr;
+				Addr	p_e;
 
 				if ((ofl->ofl_phdr[i]).p_type != PT_LOAD)
 					continue;
--- old/usr/src/cmd/sgs/packages/common/SUNWonld-README	2019-02-24 19:19:14.623811685 +0000
+++ new/usr/src/cmd/sgs/packages/common/SUNWonld-README	2019-02-24 19:19:14.639685122 +0000
@@ -1662,3 +1662,5 @@
 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
+XXXXX	support -ztype
+10366	ld(1) should support GNU-style linker sets
--- old/usr/src/cmd/sgs/rtld/common/globals.c	2019-02-24 19:19:15.126408512 +0000
+++ new/usr/src/cmd/sgs/rtld/common/globals.c	2019-02-24 19:19:15.142623624 +0000
@@ -117,7 +117,7 @@
 APlist		*hdl_alp[HDLIST_SZ+2];	/* dlopen() handle list */
 size_t		syspagsz = 0;		/* system page size */
 ulong_t		at_flags = 0;		/* machine specific file flags */
-Uts_desc	*uts = NULL; 		/* utsname descriptor */
+Uts_desc	*uts = NULL;		/* utsname descriptor */
 Isa_desc	*isa = NULL;		/* isalist descriptor */
 
 uint_t		audit_argcnt = 64;	/* no. of stack args to copy (default */
@@ -231,9 +231,10 @@
 		MSG_LDD_REJ_MACHCAP,	/* MSG_INTL(MSG_LDD_REJ_MACHCAP) */
 		MSG_LDD_REJ_PLATCAP,	/* MSG_INTL(MSG_LDD_REJ_PLATCAP) */
 		MSG_LDD_REJ_HWCAP_2,	/* MSG_INTL(MSG_LDD_REJ_HWCAP_2) */
-		MSG_LDD_REJ_ARCHIVE	/* MSG_INTL(MSG_LDD_REJ_ARCHIVE) */
+		MSG_LDD_REJ_ARCHIVE,	/* MSG_INTL(MSG_LDD_REJ_ARCHIVE) */
+		MSG_LDD_REJ_KMOD	/* MSG_INTL(MSG_LDD_REJ_KMOD) */
 	};
-#if SGS_REJ_NUM != (SGS_REJ_ARCHIVE + 1)
+#if SGS_REJ_NUM != (SGS_REJ_KMOD + 1)
 #error SGS_REJ_NUM has changed
 #endif
 
@@ -258,8 +259,9 @@
 		MSG_ERR_REJ_PLATCAP,	/* MSG_INTL(MSG_ERR_REJ_PLATCAP) */
 		MSG_ERR_REJ_HWCAP_2,	/* MSG_INTL(MSG_ERR_REJ_HWCAP_2) */
 		MSG_ERR_REJ_ARCHIVE,	/* MSG_INTL(MSG_ERR_REJ_ARCHIVE) */
+		MSG_ERR_REJ_KMOD,	/* MSG_INTL(MSG_ERR_REJ_KMOD) */
 	};
-#if SGS_REJ_NUM != (SGS_REJ_ARCHIVE + 1)
+#if SGS_REJ_NUM != (SGS_REJ_KMOD + 1)
 #error SGS_REJ_NUM has changed
 #endif
 
@@ -283,8 +285,9 @@
 		MSG_LDD_WARN_MACHCAP,	/* MSG_INTL(MSG_LDD_WARN_MACHCAP) */
 		MSG_LDD_WARN_PLATCAP,	/* MSG_INTL(MSG_LDD_WARN_PLATCAP) */
 		MSG_LDD_WARN_HWCAP_2,	/* MSG_INTL(MSG_LDD_WARN_HWCAP_2) */
-		MSG_STR_EMPTY
+		MSG_STR_EMPTY,
+		MSG_STR_EMPTY,
 	};
-#if SGS_REJ_NUM != (SGS_REJ_ARCHIVE + 1)
+#if SGS_REJ_NUM != (SGS_REJ_KMOD + 1)
 #error SGS_REJ_NUM has changed
 #endif
--- old/usr/src/cmd/sgs/rtld/common/rtld.msg	2019-02-24 19:19:15.552527948 +0000
+++ new/usr/src/cmd/sgs/rtld/common/rtld.msg	2019-02-24 19:19:15.568221853 +0000
@@ -194,6 +194,7 @@
 @ MSG_LDD_REJ_PLATCAP	"  - platform capability (CA_SUNW_PLAT) unsupported: %s"
 @ MSG_LDD_REJ_HWCAP_2	"  - hardware capability (CA_SUNW_HW_2) unsupported: %s"
 @ MSG_LDD_REJ_ARCHIVE	"  - invalid archive use"
+@ MSG_LDD_REJ_KMOD	"  - invalid kernel module use"
 
 @ MSG_LDD_WARN_UNKCAP	"%s: unknown capability: %d"
 @ MSG_LDD_WARN_HWCAP_1	"%s: warning: hardware capability (CA_SUNW_HW_1) \
@@ -227,6 +228,7 @@
 @ MSG_ERR_REJ_PLATCAP	"%s: platform capability (CA_SUNW_PLAT) unsupported: %s"
 @ MSG_ERR_REJ_HWCAP_2	"%s: hardware capability (CA_SUNW_HW_2) unsupported: %s"
 @ MSG_ERR_REJ_ARCHIVE	"%s: invalid archive use"
+@ MSG_ERR_REJ_KMOD	"%s: invalid kernel module use"
 
 # Error TLS failures
 
@@ -236,7 +238,7 @@
 			 link-map list"
 @ MSG_TLS_STATSIZE	"%s: static TLS failure: object loaded after process \
 			 initialization: size (%#llx) exceeds available backup \
-			 reservation (%#llx)"  
+			 reservation (%#llx)"
 @ MSG_TLS_STATINIT	"%s: static TLS failure: object loaded after process \
 			 initialization: can not accommodate initialized data"
 
--- old/usr/src/man/man1/ld.1	2019-02-24 19:19:15.996406563 +0000
+++ new/usr/src/man/man1/ld.1	2019-02-24 19:19:16.013436972 +0000
@@ -24,7 +24,7 @@
 [\fB-z\fR combreloc | nocombreloc ] [\fB-z\fR defs | nodefs]
 [\fB-z\fR direct | nodirect] [\fB-z\fR endfiltee]
 [\fB-z\fR fatal-warnings | nofatal-warnings ] [\fB-z\fR finiarray=\fIfunction\fR]
-[\fB-z\fR globalaudit] [\fB-z\fR groupperm | nogroupperm] 
+[\fB-z\fR globalaudit] [\fB-z\fR groupperm | nogroupperm]
 [\fB-z\fR guidance[=\fIid1\fR,\fIid2\fR...] [\fB-z\fR help ]
 [\fB-z\fR ignore | record] [\fB-z\fR initarray=\fIfunction\fR] [\fB-z\fR initfirst]
 [\fB-z\fR interpose] [\fB-z\fR lazyload | nolazyload]
@@ -35,6 +35,7 @@
 [\fB-z\fR preinitarray=\fIfunction\fR] [\fB-z\fR redlocsym] [\fB-z\fR relaxreloc]
 [\fB-z\fR rescan-now] [\fB-z\fR recan] [\fB-z\fR rescan-start \fI\&...\fR \fB-z\fR rescan-end]]
 [\fB-z\fR target=sparc|x86] [\fB-z\fR text | textwarn | textoff]
+[\fB-z\fR type=\fIexec\fR|\fIkmod\fR|\fIreloc\fR|\fIshared\fR]
 [\fB-z\fR verbose] [\fB-z\fR wrap=\fIsymbol\fR] \fIfilename\fR...
 .fi
 
@@ -1581,6 +1582,56 @@
 .RE
 
 .sp
+.ne 2
+.na
+\fB-z\fR \fBtype=exec|kmod|reloc|shared\fR
+.ad
+.sp .6
+.RS 4n
+Specifies the type of object to create.
+
+.sp
+.ne 2
+.na
+exec
+.ad
+.sp .6
+.RS 4n
+Dynamic executable
+.RE
+
+.sp
+.ne 2
+.na
+reloc
+.ad
+.sp .6
+.RS 4n
+Relocatable object
+.RE
+
+.sp
+.ne 2
+.na
+shared
+.ad
+.sp .6
+.RS 4n
+Dynamic shared object
+.RE
+
+.sp
+.ne 2
+.na
+kmod
+.ad
+.sp .6
+.RS 4n
+illumos kernel module
+.RE
+.RE
+
+.sp
 .ne 2
 .na
 \fB\fB-z\fR \fBverbose\fR\fR
--- /dev/null	2019-02-24 19:19:16.000000000 +0000
+++ new/usr/src/pkg/manifests/system-test-elftest.mf	2019-02-24 19:19:16.936187581 +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/linker-sets
+dir path=opt/elf-tests/tests/tls
+dir path=opt/elf-tests/tests/tls/x64
+dir path=opt/elf-tests/tests/tls/x64/ie
+dir path=opt/elf-tests/tests/tls/x86
+dir path=opt/elf-tests/tests/tls/x86/ld
+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/linker-sets/in-use-check mode=0555
+file path=opt/elf-tests/tests/linker-sets/simple mode=0555
+file path=opt/elf-tests/tests/linker-sets/simple-src.c mode=0444
+file path=opt/elf-tests/tests/linker-sets/simple.out mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/Makefile.test mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/style1-func-with-r12.s mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/style1-func-with-r13.s mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/style1-func.s mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/style1-main.s mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/style2-with-badness.s mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/style2-with-r12.s mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/style2-with-r13.s mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/style2.s mode=0444
+file path=opt/elf-tests/tests/tls/x64/ie/x64-ie-test mode=0555
+file path=opt/elf-tests/tests/tls/x86/ld/Makefile.test mode=0444
+file path=opt/elf-tests/tests/tls/x86/ld/half-ldm.s mode=0444
+file path=opt/elf-tests/tests/tls/x86/ld/x86-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-24 19:19:17.134640361 +0000
+++ new/usr/src/test/Makefile	2019-02-24 19:19:17.149415940 +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-24 19:19:17.000000000 +0000
+++ new/usr/src/test/elf-tests/Makefile	2019-02-24 19:19:17.554687806 +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-24 19:19:17.000000000 +0000
+++ new/usr/src/test/elf-tests/cmd/Makefile	2019-02-24 19:19:17.760917797 +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 = scripts
+
+include $(SRC)/test/Makefile.com
--- /dev/null	2019-02-24 19:19:17.000000000 +0000
+++ new/usr/src/test/elf-tests/cmd/scripts/Makefile	2019-02-24 19:19:17.969056022 +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-24 19:19:18.000000000 +0000
+++ new/usr/src/test/elf-tests/cmd/scripts/elftest.ksh	2019-02-24 19:19:18.172809349 +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.
+#
+
+export 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-24 19:19:18.000000000 +0000
+++ new/usr/src/test/elf-tests/doc/README	2019-02-24 19:19:18.376464905 +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-24 19:19:18.000000000 +0000
+++ new/usr/src/test/elf-tests/runfiles/Makefile	2019-02-24 19:19:18.580533640 +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-24 19:19:18.000000000 +0000
+++ new/usr/src/test/elf-tests/runfiles/default.run	2019-02-24 19:19:18.810006689 +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 2018, Richard Lowe.
+
+[DEFAULT]
+pre =
+verbose = False
+quiet = False
+timeout = 60
+post =
+outputdir = /var/tmp/test_results
+
+[/opt/elf-tests/tests/linker-sets]
+tests = ['simple', 'in-use-check']
+
+[/opt/elf-tests/tests/assert-deflib]
+tests = ['test-deflib']
+
+
+[/opt/elf-tests/tests/tls/x64/ie]
+arch = i86pc
+tests = ['x64-ie-test']
+
+[/opt/elf-tests/tests/tls/x86/ld]
+arch = i86pc
+tests = ['x86-ld-test']
--- /dev/null	2019-02-24 19:19:19.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/Makefile	2019-02-24 19:19:19.001153829 +0000
@@ -0,0 +1,22 @@
+#
+# 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	\
+	linker-sets	\
+	tls
+
+include $(SRC)/test/Makefile.com
--- /dev/null	2019-02-24 19:19:19.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/assert-deflib/Makefile	2019-02-24 19:19:19.202765750 +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 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-24 19:19:19.393827728 +0000
+++ /dev/null	2019-02-24 19:19:19.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-24 19:19:19.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/assert-deflib/link.c	2019-02-24 19:19:19.409135136 +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-24 19:19:19.587330153 +0000
+++ /dev/null	2019-02-24 19:19:19.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-24 19:19:19.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/assert-deflib/test-deflib.sh	2019-02-24 19:19:19.604512075 +0000
@@ -0,0 +1,139 @@
+#!/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
+
+if [[ -z $ELF_TESTS ]]; then
+    print -u2 "Don't know where the test data is rooted";
+    exit 1;
+fi
+
+sh_path=
+sh_lib="lib"
+sh_lib64="$sh_lib/64"
+sh_soname="libld.so.4"
+sh_cc="gcc"
+sh_cflags="-m32"
+sh_file="${ELF_TESTS}/tests/assert-deflib/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-24 19:19:20.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/linker-sets/Makefile	2019-02-24 19:19:20.069728387 +0000
@@ -0,0 +1,50 @@
+#
+# 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 =	simple in-use-check
+
+DATAFILES =	simple-src.c \
+		simple.out
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/linker-sets
+
+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-24 19:19:20.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/linker-sets/in-use-check.sh	2019-02-24 19:19:20.272841462 +0000
@@ -0,0 +1,53 @@
+#!/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 2018, Richard Lowe.
+#
+
+# Test that existing definitions of the start/stop symbols are reported
+# as conflicting with internal symbols.
+
+tmpdir=/tmp/test.$$
+mkdir $tmpdir
+cd $tmpdir
+
+cleanup() {
+    cd /
+    rm -fr $tmpdir
+}
+
+trap 'cleanup' EXIT
+
+cat > broken.c <<EOF
+char foo[1024] __attribute__((section("set_foo")));
+void *__start_set_foo;
+
+int
+main()
+{
+	return (0);
+}
+EOF
+
+# We expect any alternate linker to be in LD_ALTEXEC for us already
+gcc -o broken broken.c -Wall -Wextra -Wl,-zfatal-warnings > in-use.$$.out 2>&1
+if (( $? == 0 )); then
+    print -u2 "use of a reserved symbol didn't fail"
+    exit 1;
+fi
+
+grep -q "^ld: warning: reserved symbol '__start_set_foo' already defined in file" in-use.$$.out
+if (( $? != 0 )); then
+    print -u2 "use of a reserved symbol failed for the wrong reason"
+    exit 1;
+fi
--- /dev/null	2019-02-24 19:19:20.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/linker-sets/simple-src.c	2019-02-24 19:19:20.477797352 +0000
@@ -0,0 +1,105 @@
+/* The meat of this file is a copy of the FreeBSD sys/link_set.h */
+/*
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (c) 1999 John D. Polstra
+ * Copyright (c) 1999,2001 Peter Wemm <peter@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <stdio.h>
+
+#define	MAKE_SET(set, sym)					\
+	__asm__(".globl __start_set_" #set);			\
+	__asm__(".globl __stop_set_" #set);			\
+	static __attribute__((section("set_" #set), used))	\
+	void const *__set_##set##_sym_##sym = &(sym)
+
+/*
+ * Initialize before referring to a given linker set.
+ */
+#define	SET_DECLARE(set, ptype)						\
+	extern  __attribute__((weak)) ptype *__start_set_ ## set;	\
+	extern __attribute__((weak)) ptype *__stop_set_ ## set
+
+#define	SET_BEGIN(set)	(&__start_set_ ## set)
+#define	SET_LIMIT(set)	(&__stop_set_ ## set)
+
+/*
+ * Iterate over all the elements of a set.
+ *
+ * Sets always contain addresses of things, and "pvar" points to words
+ * containing those addresses.  Thus is must be declared as "type **pvar",
+ * and the address of each set item is obtained inside the loop by "*pvar".
+ */
+#define	SET_FOREACH(pvar, set)						\
+	for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++)
+
+#define	SET_ITEM(set, i)						\
+	((SET_BEGIN(set))[i])
+
+/*
+ * Provide a count of the items in a set.
+ */
+#define	SET_COUNT(set)							\
+	(SET_LIMIT(set) - SET_BEGIN(set))
+
+struct foo {
+	char buf[128];
+};
+
+SET_DECLARE(foo, struct foo);
+
+struct foo a = { "foo" };
+struct foo b = { "bar" };
+struct foo c = { "baz" };
+
+MAKE_SET(foo, a);
+MAKE_SET(foo, b);
+MAKE_SET(foo, c);
+
+int
+main(int __attribute__((unused)) argc, char __attribute__((unused)) **argv)
+{
+	struct foo **c;
+	int i = 0;
+
+	printf("Set count: %d\n", SET_COUNT(foo));
+
+
+	printf("a: %s\n", ((struct foo *)__set_foo_sym_a)->buf);
+	printf("b: %s\n", ((struct foo *)__set_foo_sym_b)->buf);
+	printf("c: %s\n", ((struct foo *)__set_foo_sym_c)->buf);
+
+	printf("item(foo, 0): %s\n", SET_ITEM(foo, 0)->buf);
+	printf("item(foo, 1): %s\n", SET_ITEM(foo, 1)->buf);
+	printf("item(foo, 2): %s\n", SET_ITEM(foo, 2)->buf);
+
+	SET_FOREACH(c, foo) {
+		printf("foo[%d]: %s\n", i, (*c)->buf);
+		i++;
+	}
+}
--- /dev/null	2019-02-24 19:19:20.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/linker-sets/simple.out	2019-02-24 19:19:20.694565664 +0000
@@ -0,0 +1,10 @@
+Set count: 3
+a: foo
+b: bar
+c: baz
+item(foo, 0): foo
+item(foo, 1): bar
+item(foo, 2): baz
+foo[0]: foo
+foo[1]: bar
+foo[2]: baz
--- /dev/null	2019-02-24 19:19:20.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/linker-sets/simple.sh	2019-02-24 19:19:20.870606800 +0000
@@ -0,0 +1,54 @@
+#!/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 2018, Richard Lowe.
+#
+
+# Test that a simple use of linker-sets, that is, automatically generated start
+# and end symbols for sections can be generated and used.
+
+if [[ -z $ELF_TESTS ]]; then
+    print -u2 "Don't know where the test data is rooted";
+    exit 1;
+fi
+
+tmpdir=/tmp/test.$$
+mkdir $tmpdir
+cd $tmpdir
+
+cleanup() {
+    cd /
+    rm -fr $tmpdir
+}
+
+trap 'cleanup' EXIT
+
+# We expect any alternate linker to be in LD_ALTEXEC for us already
+gcc -o simple ${ELF_TESTS}/tests/linker-sets/simple-src.c -Wall -Wextra
+if (( $? != 0 )); then
+    print -u2 "compilation of ${ELF_TESTS}/tests/linker-sets/simple-src.c failed";
+    exit 1;
+fi
+
+./simple > simple.$$.out 2>&1
+
+if (( $? != 0 )); then
+    print -u2 "execution of ${ELF_TESTS}/tests/linker-sets/simple-src.c failed";
+    exit 1;
+fi
+
+diff -u ${ELF_TESTS}/tests/linker-sets/simple.out simple.$$.out
+if (( $? != 0 )); then
+    print -u2 "${ELF_TESTS}/tests/linker-sets/simple-src.c output mismatch"
+    exit 1;
+fi
--- /dev/null	2019-02-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/Makefile	2019-02-24 19:19:21.055704145 +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 = x64 x86
+
+include $(SRC)/test/Makefile.com
--- /dev/null	2019-02-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/Makefile	2019-02-24 19:19:21.256666274 +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
+
+include $(SRC)/test/Makefile.com
--- /dev/null	2019-02-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/Makefile	2019-02-24 19:19:21.462313037 +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 =	x64-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/x64/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-24 19:19:21.658432601 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/Makefile.test	2019-02-24 19:19:21.673644439 +0000
@@ -0,0 +1,82 @@
+#
+# 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.c = $(CC) $(CFLAGS) -c -o $@ $^
+COMPILE.s = $(CC) $(CFLAGS) -c -o $@ $^
+
+.KEEP_STATE:
+
+install default: all
+
+%.o: $(ELF_TESTS)/tests/tls/x64/ie/%.c
+	$(COMPILE.c)
+%.o: $(ELF_TESTS)/tests/tls/x64/ie/%.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:
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/README	2019-02-24 19:19:22.079245204 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/README	2019-02-24 19:19:22.094208964 +0000
@@ -0,0 +1,9 @@
+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
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/orig/style1-func.c	2019-02-24 19:19:22.285698690 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/orig/style1-func.c	2019-02-24 19:19:22.301287423 +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-24 19:19:22.499484832 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/orig/style1-main.c	2019-02-24 19:19:22.514678506 +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-24 19:19:22.704600649 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/orig/style2.c	2019-02-24 19:19:22.719086578 +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-24 19:19:22.903261396 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/style1-func-with-r12.s	2019-02-24 19:19:22.918466105 +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-24 19:19:23.330157046 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/style1-func-with-r13.s	2019-02-24 19:19:23.345152837 +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-24 19:19:23.536570374 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/style1-func.s	2019-02-24 19:19:23.549900508 +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-24 19:19:23.722035855 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/style1-main.s	2019-02-24 19:19:23.738504894 +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-24 19:19:23.928950663 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/style2-with-badness.s	2019-02-24 19:19:23.944360552 +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-24 19:19:24.360771720 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/style2-with-r12.s	2019-02-24 19:19:24.376784360 +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-24 19:19:24.794014734 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/style2-with-r13.s	2019-02-24 19:19:24.809238480 +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-24 19:19:25.220043932 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/style2.s	2019-02-24 19:19:25.234919805 +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
--- old/usr/src/cmd/sgs/test/ld/x64/tls/ie/x64-ie-test.sh	2019-02-24 19:19:25.651198712 +0000
+++ /dev/null	2019-02-24 19:19:21.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-24 19:19:21.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x64/ie/x64-ie-test.sh	2019-02-24 19:19:25.666810674 +0000
@@ -0,0 +1,68 @@
+#!/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}"
+}
+
+if [[ -z $ELF_TESTS ]]; then
+    print -u2 "Don't know where the test data is rooted";
+    exit 1;
+fi
+
+make -f ${ELF_TESTS}/tests/tls/x64/ie/Makefile.test
+
+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 ${ELF_TESTS}/tests/tls/x64/ie/Makefile.test 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-24 19:19:26.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x86/Makefile	2019-02-24 19:19:26.100001689 +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-24 19:19:26.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x86/ld/Makefile	2019-02-24 19:19:26.300803141 +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 =	x86-ld-test
+
+DATAFILES =		\
+	Makefile.test	\
+	half-ldm.s	\
+
+ROOTOPTPKG = $(ROOT)/opt/elf-tests
+TESTDIR = $(ROOTOPTPKG)/tests/tls/x86/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-24 19:19:26.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x86/ld/Makefile.test	2019-02-24 19:19:26.494133971 +0000
@@ -0,0 +1,44 @@
+#
+# 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.c = $(CC) $(CFLAGS) -c -o $@ $^
+COMPILE.s = $(CC) $(CFLAGS) -c -o $@ $^
+
+.KEEP_STATE:
+
+install default: all
+
+%.o: $(ELF_TESTS)/tests/tls/x86/ld/%.c
+	$(COMPILE.c)
+%.o: $(ELF_TESTS)/tests/tls/x86/ld/%.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) $(STYLE1OBJS) $(STYLE1R13OBJS) $(STYLE1R12OBJS) \
+	    $(STYLE2OBJS) $(STYLE2R13OBJS) $(STYLE2R12OBJS) $(STYLE2BADNESSOBJS)
+
+fail: style2-with-badness FRC
+
+FRC:
--- /dev/null	2019-02-24 19:19:26.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x86/ld/half-ldm.s	2019-02-24 19:19:26.695076835 +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-24 19:19:26.000000000 +0000
+++ new/usr/src/test/elf-tests/tests/tls/x86/ld/x86-ld-test.sh	2019-02-24 19:19:26.897725741 +0000
@@ -0,0 +1,47 @@
+#!/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}"
+}
+
+if [[ -z $ELF_TESTS ]]; then
+    print -u2 "Don't know where the test data is rooted";
+    exit 1;
+fi
+
+make -f ${ELF_TESTS}/tests/tls/x86/ld/Makefile.test
+
+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]*)$'
--- old/usr/src/uts/common/sys/link.h	2019-02-24 19:19:27.090579179 +0000
+++ new/usr/src/uts/common/sys/link.h	2019-02-24 19:19:27.105619267 +0000
@@ -161,6 +161,7 @@
 #define	DT_SUNW_CAPCHAINSZ	0x6000001f	/* capabilities chain size */
 /* 0x60000021 would be DT_SUNW_PARENT */
 #define	DT_SUNW_ASLR		0x60000023	/* executable ASLR desire */
+#define	DT_SUNW_KMOD		0x60000027	/* object is a kernel module */
 
 /*
  * DT_* encoding rules do not apply between DT_HIOS and DT_LOPROC
@@ -230,7 +231,7 @@
 #define	DT_VERDEF	0x6ffffffc	/* version definition table and */
 #define	DT_VERDEFNUM	0x6ffffffd	/*	associated no. of entries */
 #define	DT_VERNEED	0x6ffffffe	/* version needed table and */
-#define	DT_VERNEEDNUM	0x6fffffff	/* 	associated no. of entries */
+#define	DT_VERNEEDNUM	0x6fffffff	/*	associated no. of entries */
 
 /*
  * DT_* entries between DT_HIPROC and DT_LOPROC are reserved for processor
@@ -366,7 +367,7 @@
 	Elf32_Word	vna_next;	/* no. of bytes from start of this */
 } Elf32_Vernaux;			/*	vernaux to next vernaux entry */
 
-typedef	Elf32_Half 	Elf32_Versym;	/* Version symbol index array */
+typedef	Elf32_Half	Elf32_Versym;	/* Version symbol index array */
 
 typedef struct {
 	Elf32_Half	si_boundto;	/* direct bindings - symbol bound to */
@@ -464,7 +465,7 @@
 #define	SYMINFO_FLG_DIRECT	0x0001	/* symbol ref has direct association */
 					/*	to object containing defn. */
 #define	SYMINFO_FLG_FILTER	0x0002	/* symbol ref is associated to a */
-					/* 	standard filter */
+					/*	standard filter */
 #define	SYMINFO_FLG_PASSTHRU	SYMINFO_FLG_FILTER /* unused obsolete name */
 #define	SYMINFO_FLG_COPY	0x0004	/* symbol is a copy-reloc */
 #define	SYMINFO_FLG_LAZYLOAD	0x0008	/* object containing defn. should be */
@@ -474,7 +475,7 @@
 #define	SYMINFO_FLG_NOEXTDIRECT	0x0020	/* don't let an external reference */
 					/*	directly bind to this symbol */
 #define	SYMINFO_FLG_AUXILIARY	0x0040	/* symbol ref is associated to a */
-					/* 	auxiliary filter */
+					/*	auxiliary filter */
 #define	SYMINFO_FLG_INTERPOSE	0x0080	/* symbol defines an interposer */
 #define	SYMINFO_FLG_CAP		0x0100	/* symbol is capabilities specific */
 #define	SYMINFO_FLG_DEFERRED	0x0200	/* symbol should not be included in */
@@ -506,7 +507,7 @@
 
 struct link_map {
 	unsigned long	l_addr;		/* address at which object is mapped */
-	char 		*l_name;	/* full name of loaded object */
+	char		*l_name;	/* full name of loaded object */
 #ifdef _LP64
 	Elf64_Dyn	*l_ld;		/* dynamic structure of object */
 #else
