--- old/usr/src/cmd/sgs/libld/common/_libld.h	2019-02-07 01:35:55.409415005 +0000
+++ new/usr/src/cmd/sgs/libld/common/_libld.h	2019-02-07 01:35:55.426507049 +0000
@@ -199,7 +199,7 @@
 	const Rel_entry	*mr_reloc_table;
 
 	Word		(* mr_init_rel)(Rel_desc *, Word *, void *);
-	void 		(* mr_mach_eflags)(Ehdr *, Ofl_desc *);
+	void		(* mr_mach_eflags)(Ehdr *, Ofl_desc *);
 	void		(* mr_mach_make_dynamic)(Ofl_desc *, size_t *);
 	void		(* mr_mach_update_odynamic)(Ofl_desc *, Dyn **);
 	Xword		(* mr_calc_plt_addr)(Sym_desc *, Ofl_desc *);
@@ -754,6 +754,7 @@
 #define	ld_sym_nodirect		ld64_sym_nodirect
 #define	ld_sym_process		ld64_sym_process
 #define	ld_sym_resolve		ld64_sym_resolve
+#define	ld_sym_reducable	ld64_sym_reducable
 #define	ld_sym_spec		ld64_sym_spec
 #define	ld_targ			ld64_targ
 #define	ld_targ_init_sparc	ld64_targ_init_sparc
@@ -852,6 +853,7 @@
 #define	ld_sym_nodirect		ld32_sym_nodirect
 #define	ld_sym_process		ld32_sym_process
 #define	ld_sym_resolve		ld32_sym_resolve
+#define	ld_sym_reducable	ld32_sym_reducable
 #define	ld_sym_spec		ld32_sym_spec
 #define	ld_targ			ld32_targ
 #define	ld_targ_init_sparc	ld32_targ_init_sparc
@@ -878,8 +880,8 @@
 
 extern uintptr_t	ld_add_actrel(Word, Rel_desc *, Ofl_desc *);
 extern uintptr_t	ld_add_libdir(Ofl_desc *, const char *);
-extern void 		ld_adj_movereloc(Ofl_desc *, Rel_desc *);
-extern Sym_desc * 	ld_am_I_partial(Rel_desc *, Xword);
+extern void		ld_adj_movereloc(Ofl_desc *, Rel_desc *);
+extern Sym_desc *	ld_am_I_partial(Rel_desc *, Xword);
 extern void		ld_ar_member(Ar_desc *, Elf_Arsym *, Ar_aux *,
 			    Ar_mem *);
 extern Ar_desc		*ld_ar_setup(const char *, Elf *, Ofl_desc *);
@@ -997,6 +999,7 @@
 extern uintptr_t	ld_sym_process(Is_desc *, Ifl_desc *, Ofl_desc *);
 extern uintptr_t	ld_sym_resolve(Sym_desc *, Sym *, Ifl_desc *,
 			    Ofl_desc *, int, Word, sd_flag_t);
+extern Boolean		ld_sym_reducable(Ofl_desc *, Sym_desc *);
 extern uintptr_t	ld_sym_spec(Ofl_desc *);
 
 extern Target		ld_targ;
--- old/usr/src/cmd/sgs/libld/common/syms.c	2019-02-07 01:35:55.852540503 +0000
+++ new/usr/src/cmd/sgs/libld/common/syms.c	2019-02-07 01:35:55.870892217 +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;
@@ -795,7 +795,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
@@ -991,6 +991,9 @@
 	case STV_SINGLETON:
 		sdflags |= FLG_SY_SINGLE;
 		break;
+	case STV_HIDDEN:
+		sdflags |= FLG_SY_HIDDEN;
+		break;
 	}
 
 	/*
@@ -1133,7 +1136,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 +1144,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
@@ -1516,7 +1519,7 @@
 		 */
 		if ((sym->st_shndx == SHN_COMMON) &&
 		    (((oflags & FLG_OF_RELOBJ) == 0) ||
-		    (SYM_IS_HIDDEN(sdp) && (oflags & FLG_OF_PROCRED)))) {
+		    ld_sym_reducable(ofl, sdp))) {
 			if ((sdp->sd_move == NULL) ||
 			    ((sdp->sd_flags & FLG_SY_PAREXPN) == 0)) {
 				if (type != STT_TLS) {
@@ -1568,7 +1571,7 @@
 		 * hidden requirement and ensures the symbol isn't made globally
 		 * available at runtime.
 		 */
-		if (SYM_IS_HIDDEN(sdp) && (oflags & FLG_OF_PROCRED)) {
+		if (ld_sym_reducable(ofl, sdp)) {
 			/*
 			 * If any reductions are being processed, keep a count
 			 * of eliminated symbols, and if the symbol is being
@@ -1890,7 +1893,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
@@ -3133,3 +3136,26 @@
 
 	return (isp->is_sym_name);
 }
+
+/*
+ * If we're producing a relocatable object and the symbol is eligible for
+ * COMDAT section, it shouldn't be reduced in scope as that will break the
+ * COMDAT matching when the output object is later consumed.  Leave it alone,
+ * and any reduction (and COMDAT) processing will occur then.
+ *
+ * Otherwise, any hidden symbol is reduced when reductions are being processed.
+ */
+Boolean
+ld_sym_reducable(Ofl_desc *ofl, Sym_desc *sdp)
+{
+	Is_desc *isc = sdp->sd_isc;
+
+	if (((ofl->ofl_flags & FLG_OF_RELOBJ) != 0) &&
+	    (isc != NULL) &&
+	    ((isc->is_flags & FLG_IS_COMDAT) != 0)) {
+		return (FALSE);
+	} else {
+		return (SYM_IS_HIDDEN(sdp) &&
+		    (ofl->ofl_flags & FLG_OF_PROCRED));
+	}
+}
--- old/usr/src/cmd/sgs/libld/common/update.c	2019-02-07 01:35:56.480349845 +0000
+++ new/usr/src/cmd/sgs/libld/common/update.c	2019-02-07 01:35:56.499798695 +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;
@@ -1013,7 +1013,7 @@
 		if (sdp->sd_ref == REF_DYN_SEEN)
 			continue;
 
-		if (SYM_IS_HIDDEN(sdp) && (flags & FLG_OF_PROCRED))
+		if (ld_sym_reducable(ofl, sdp))
 			local = 1;
 		else
 			local = 0;
@@ -1224,7 +1224,7 @@
 		 * of the .symtab.  Retain the appropriate index for use in
 		 * version symbol indexing and relocation.
 		 */
-		if (SYM_IS_HIDDEN(sdp) && (flags & FLG_OF_PROCRED)) {
+		if (ld_sym_reducable(ofl, sdp)) {
 			local = 1;
 			if (!(sdp->sd_flags & FLG_SY_ELIM) && !dynsym)
 				sdp->sd_symndx = scopesym_ndx;
@@ -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
@@ -1889,7 +1889,7 @@
 		 * to maintain the binding of the original reference.
 		 */
 		if (SYM_IS_HIDDEN(sdp)) {
-			if (flags & FLG_OF_PROCRED)
+			if (ld_sym_reducable(ofl, sdp))
 				bind = STB_LOCAL;
 			else
 				bind = STB_WEAK;
@@ -3157,7 +3157,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 +3652,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 +3872,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-07 01:35:57.172487736 +0000
+++ new/usr/src/cmd/sgs/packages/common/SUNWonld-README	2019-02-07 01:35:57.190296154 +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
+10346	ld(1) should not reduce symbol visibility of COMDAT symbols when
+	producing relocatable objects
