xref: /illumos-gate/usr/src/cmd/sgs/libld/common/update.c (revision 9039eeaf)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *	Copyright (c) 1988 AT&T
247c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
257c478bd9Sstevel@tonic-gate  *
265aefb655Srie  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
277c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Update the new output file image, perform virtual address, offset and
337c478bd9Sstevel@tonic-gate  * displacement calculations on the program headers and sections headers,
347c478bd9Sstevel@tonic-gate  * and generate any new output section information.
357c478bd9Sstevel@tonic-gate  */
367c478bd9Sstevel@tonic-gate #include	<stdio.h>
377c478bd9Sstevel@tonic-gate #include	<string.h>
38fdf855a7Sseizo #include	<unistd.h>
395aefb655Srie #include	<debug.h>
407c478bd9Sstevel@tonic-gate #include	"msg.h"
417c478bd9Sstevel@tonic-gate #include	"_libld.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
44*9039eeafSab  * Comparison routine used by qsort() for sorting of the global symbol list
457c478bd9Sstevel@tonic-gate  * based off of the hashbuckets the symbol will eventually be deposited in.
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate static int
487c478bd9Sstevel@tonic-gate sym_hash_compare(Sym_s_list * s1, Sym_s_list * s2)
497c478bd9Sstevel@tonic-gate {
507c478bd9Sstevel@tonic-gate 	return (s1->sl_hval - s2->sl_hval);
517c478bd9Sstevel@tonic-gate }
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /*
547c478bd9Sstevel@tonic-gate  * Build and update any output symbol tables.  Here we work on all the symbol
557c478bd9Sstevel@tonic-gate  * tables at once to reduce the duplication of symbol and string manipulation.
567c478bd9Sstevel@tonic-gate  * Symbols and their associated strings are copied from the read-only input
577c478bd9Sstevel@tonic-gate  * file images to the output image and their values and index's updated in the
587c478bd9Sstevel@tonic-gate  * output image.
597c478bd9Sstevel@tonic-gate  */
605aefb655Srie static Addr
617c478bd9Sstevel@tonic-gate update_osym(Ofl_desc *ofl)
627c478bd9Sstevel@tonic-gate {
630bc07c75Srie 	Listnode	*lnp1;
647c478bd9Sstevel@tonic-gate 	Sym_desc	*sdp;
657c478bd9Sstevel@tonic-gate 	Sym_avlnode	*sav;
667c478bd9Sstevel@tonic-gate 	Sg_desc		*sgp, *tsgp = 0, *dsgp = 0, *esgp = 0;
67c1c6f601Srie 	Os_desc		*osp, *iosp = 0, *fosp = 0;
687c478bd9Sstevel@tonic-gate 	Ifl_desc	*ifl;
697c478bd9Sstevel@tonic-gate 	Word		bssndx, etext_ndx, edata_ndx = 0, end_ndx, start_ndx;
707c478bd9Sstevel@tonic-gate 	Word		end_abs = 0, etext_abs = 0, edata_abs;
717c478bd9Sstevel@tonic-gate 	Word		tlsbssndx = 0, sunwbssndx = 0, sunwdata1ndx;
7254d82594Sseizo #if	(defined(__i386) || defined(__amd64)) && defined(_ELF64)
7354d82594Sseizo 	Word		lbssndx = 0;
7454d82594Sseizo 	Addr		lbssaddr = 0;
7554d82594Sseizo #endif
767c478bd9Sstevel@tonic-gate 	Addr		bssaddr, etext = 0, edata = 0, end = 0, start = 0;
777c478bd9Sstevel@tonic-gate 	Addr		tlsbssaddr = 0;
787c478bd9Sstevel@tonic-gate 	Addr 		sunwbssaddr = 0, sunwdata1addr;
797c478bd9Sstevel@tonic-gate 	int		start_set = 0;
80*9039eeafSab 	Sym		_sym = {0}, *sym, *symtab = 0;
81*9039eeafSab 	Sym		*dynsym = 0, *ldynsym = 0;
827c478bd9Sstevel@tonic-gate 	Word		symtab_ndx = 0;	/* index into .symtab */
83*9039eeafSab 	Word		ldynsym_ndx = 0;	/* index into .SUNW_ldynsym */
84*9039eeafSab 	Word		dynsym_ndx = 0;		/* index into .dynsym */
857c478bd9Sstevel@tonic-gate 	Word		scopesym_ndx = 0; /* index into scoped symbols */
86*9039eeafSab 	Word		ldynscopesym_ndx = 0; /* index to ldynsym scoped syms */
87*9039eeafSab 	Word		*symndx;	/* Symbol index (for relocation use) */
887c478bd9Sstevel@tonic-gate 	Word		*symshndx = 0;	/* .symtab_shndx table */
897c478bd9Sstevel@tonic-gate 	Word		*dynshndx = 0;	/* .dynsym_shndx table */
90*9039eeafSab 	Word		*ldynshndx = 0;	/* .SUNW_ldynsym_shndx table */
917c478bd9Sstevel@tonic-gate 	Str_tbl		*shstrtab;
927c478bd9Sstevel@tonic-gate 	Str_tbl		*strtab;
937c478bd9Sstevel@tonic-gate 	Str_tbl		*dynstr;
947c478bd9Sstevel@tonic-gate 	Word		*hashtab;	/* hash table pointer */
957c478bd9Sstevel@tonic-gate 	Word		*hashbkt;	/* hash table bucket pointer */
967c478bd9Sstevel@tonic-gate 	Word		*hashchain;	/* hash table chain pointer */
977c478bd9Sstevel@tonic-gate 	Word		hashval;	/* value of hash function */
987c478bd9Sstevel@tonic-gate 	Wk_desc		*wkp;
997c478bd9Sstevel@tonic-gate 	List		weak = {NULL, NULL};
1007c478bd9Sstevel@tonic-gate 	Word		flags = ofl->ofl_flags;
1017c478bd9Sstevel@tonic-gate 	Word		dtflags_1 = ofl->ofl_dtflags_1;
1027c478bd9Sstevel@tonic-gate 	Versym		*versym;
1037c478bd9Sstevel@tonic-gate 	Gottable	*gottable;	/* used for display got debugging */
1047c478bd9Sstevel@tonic-gate 					/*	information */
1057c478bd9Sstevel@tonic-gate 	Syminfo		*syminfo;
1067c478bd9Sstevel@tonic-gate 	Sym_s_list	*sorted_syms;	/* table to hold sorted symbols */
1077c478bd9Sstevel@tonic-gate 	Word		ssndx;		/* global index into sorted_syms */
1087c478bd9Sstevel@tonic-gate 	Word		scndx;		/* scoped index into sorted_syms */
1097c478bd9Sstevel@tonic-gate 	uint_t		stoff;		/* string offset */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	/*
1127c478bd9Sstevel@tonic-gate 	 * Initialize pointers to the symbol table entries and the symbol
1137c478bd9Sstevel@tonic-gate 	 * table strings.  Skip the first symbol entry and the first string
1147c478bd9Sstevel@tonic-gate 	 * table byte.  Note that if we are not generating any output symbol
1157c478bd9Sstevel@tonic-gate 	 * tables we must still generate and update an internal copies so
1167c478bd9Sstevel@tonic-gate 	 * that the relocation phase has the correct information.
1177c478bd9Sstevel@tonic-gate 	 */
1187c478bd9Sstevel@tonic-gate 	if (!(flags & FLG_OF_STRIP) || (flags & FLG_OF_RELOBJ) ||
1197c478bd9Sstevel@tonic-gate 	    ((flags & FLG_OF_STATIC) && ofl->ofl_osversym)) {
1207c478bd9Sstevel@tonic-gate 		symtab = (Sym *)ofl->ofl_ossymtab->os_outdata->d_buf;
1217c478bd9Sstevel@tonic-gate 		symtab[symtab_ndx++] = _sym;
1227c478bd9Sstevel@tonic-gate 		if (ofl->ofl_ossymshndx)
1237c478bd9Sstevel@tonic-gate 		    symshndx = (Word *)ofl->ofl_ossymshndx->os_outdata->d_buf;
1247c478bd9Sstevel@tonic-gate 	}
125*9039eeafSab 	if (OFL_ALLOW_DYNSYM(ofl)) {
1267c478bd9Sstevel@tonic-gate 		dynsym = (Sym *)ofl->ofl_osdynsym->os_outdata->d_buf;
1277c478bd9Sstevel@tonic-gate 		dynsym[dynsym_ndx++] = _sym;
128*9039eeafSab 		/*
129*9039eeafSab 		 * If we are also constructing a .SUNW_ldynsym section
130*9039eeafSab 		 * to contain local function symbols, then set it up too.
131*9039eeafSab 		 */
132*9039eeafSab 		if (ofl->ofl_osldynsym) {
133*9039eeafSab 			ldynsym = (Sym *)ofl->ofl_osldynsym->os_outdata->d_buf;
134*9039eeafSab 			ldynsym[ldynsym_ndx++] = _sym;
135*9039eeafSab 		}
136*9039eeafSab 
1377c478bd9Sstevel@tonic-gate 		/*
1387c478bd9Sstevel@tonic-gate 		 * Initialize the hash table.
1397c478bd9Sstevel@tonic-gate 		 */
1407c478bd9Sstevel@tonic-gate 		hashtab = (Word *)(ofl->ofl_oshash->os_outdata->d_buf);
1417c478bd9Sstevel@tonic-gate 		hashbkt = &hashtab[2];
1427c478bd9Sstevel@tonic-gate 		hashchain = &hashtab[2 + ofl->ofl_hashbkts];
1437c478bd9Sstevel@tonic-gate 		hashtab[0] = ofl->ofl_hashbkts;
1447c478bd9Sstevel@tonic-gate 		hashtab[1] = ofl->ofl_dynshdrcnt + ofl->ofl_globcnt +
1457c478bd9Sstevel@tonic-gate 		    ofl->ofl_lregsymcnt + 1;
1467c478bd9Sstevel@tonic-gate 		if (ofl->ofl_osdynshndx)
1477c478bd9Sstevel@tonic-gate 		    dynshndx = (Word *)ofl->ofl_osdynshndx->os_outdata->d_buf;
148*9039eeafSab 		if (ofl->ofl_osldynshndx)
149*9039eeafSab 		    ldynshndx = (Word *)ofl->ofl_osldynshndx->os_outdata->d_buf;
1507c478bd9Sstevel@tonic-gate 	}
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	/*
1537c478bd9Sstevel@tonic-gate 	 * symndx is the symbol index to be used for relocation processing.  It
1547c478bd9Sstevel@tonic-gate 	 * points to the relevant symtab's (.dynsym or .symtab) symbol ndx.
1557c478bd9Sstevel@tonic-gate 	 */
1567c478bd9Sstevel@tonic-gate 	if (dynsym)
1577c478bd9Sstevel@tonic-gate 		symndx = &dynsym_ndx;
1587c478bd9Sstevel@tonic-gate 	else
1597c478bd9Sstevel@tonic-gate 		symndx = &symtab_ndx;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 	/*
1627c478bd9Sstevel@tonic-gate 	 * If we have version definitions initialize the version symbol index
1637c478bd9Sstevel@tonic-gate 	 * table.  There is one entry for each symbol which contains the symbols
1647c478bd9Sstevel@tonic-gate 	 * version index.
1657c478bd9Sstevel@tonic-gate 	 */
1667c478bd9Sstevel@tonic-gate 	if ((flags & (FLG_OF_VERDEF | FLG_OF_NOVERSEC)) == FLG_OF_VERDEF) {
1677c478bd9Sstevel@tonic-gate 		versym = (Versym *)ofl->ofl_osversym->os_outdata->d_buf;
1687c478bd9Sstevel@tonic-gate 		versym[0] = 0;
1697c478bd9Sstevel@tonic-gate 	} else
1707c478bd9Sstevel@tonic-gate 		versym = 0;
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	/*
1737c478bd9Sstevel@tonic-gate 	 * If syminfo section exists be prepared to fill it in.
1747c478bd9Sstevel@tonic-gate 	 */
1757c478bd9Sstevel@tonic-gate 	if (ofl->ofl_ossyminfo) {
1767c478bd9Sstevel@tonic-gate 		syminfo = ofl->ofl_ossyminfo->os_outdata->d_buf;
1777c478bd9Sstevel@tonic-gate 		syminfo[0].si_flags = SYMINFO_CURRENT;
1787c478bd9Sstevel@tonic-gate 	} else
1797c478bd9Sstevel@tonic-gate 		syminfo = 0;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	/*
1827c478bd9Sstevel@tonic-gate 	 * Setup our string tables.
1837c478bd9Sstevel@tonic-gate 	 */
1847c478bd9Sstevel@tonic-gate 	shstrtab = ofl->ofl_shdrsttab;
1857c478bd9Sstevel@tonic-gate 	strtab = ofl->ofl_strtab;
1867c478bd9Sstevel@tonic-gate 	dynstr = ofl->ofl_dynstrtab;
1877c478bd9Sstevel@tonic-gate 
1885aefb655Srie 	DBG_CALL(Dbg_syms_sec_title(ofl->ofl_lml));
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	/*
191*9039eeafSab 	 * Put output file name to the first .symtab and .SUNW_ldynsym symbol.
1927c478bd9Sstevel@tonic-gate 	 */
1937c478bd9Sstevel@tonic-gate 	if (symtab) {
1947c478bd9Sstevel@tonic-gate 		(void) st_setstring(strtab, ofl->ofl_name, &stoff);
1957c478bd9Sstevel@tonic-gate 		sym = &symtab[symtab_ndx++];
1967c478bd9Sstevel@tonic-gate 		/* LINTED */
1977c478bd9Sstevel@tonic-gate 		sym->st_name = stoff;
1987c478bd9Sstevel@tonic-gate 		sym->st_value = 0;
1997c478bd9Sstevel@tonic-gate 		sym->st_size = 0;
2007c478bd9Sstevel@tonic-gate 		sym->st_info = ELF_ST_INFO(STB_LOCAL, STT_FILE);
2017c478bd9Sstevel@tonic-gate 		sym->st_other = 0;
2027c478bd9Sstevel@tonic-gate 		sym->st_shndx = SHN_ABS;
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate 		if (versym && !dynsym)
2057c478bd9Sstevel@tonic-gate 			versym[1] = 0;
2067c478bd9Sstevel@tonic-gate 	}
207*9039eeafSab 	if (ldynsym && ofl->ofl_dynscopecnt) {
208*9039eeafSab 		(void) st_setstring(dynstr, ofl->ofl_name, &stoff);
209*9039eeafSab 		sym = &ldynsym[ldynsym_ndx];
210*9039eeafSab 		/* LINTED */
211*9039eeafSab 		sym->st_name = stoff;
212*9039eeafSab 		sym->st_value = 0;
213*9039eeafSab 		sym->st_size = 0;
214*9039eeafSab 		sym->st_info = ELF_ST_INFO(STB_LOCAL, STT_FILE);
215*9039eeafSab 		sym->st_other = 0;
216*9039eeafSab 		sym->st_shndx = SHN_ABS;
217*9039eeafSab 
218*9039eeafSab 		/* Scoped symbols get filled in global loop below */
219*9039eeafSab 		ldynscopesym_ndx = ldynsym_ndx + 1;
220*9039eeafSab 		ldynsym_ndx += ofl->ofl_dynscopecnt;
221*9039eeafSab 	}
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	/*
2247c478bd9Sstevel@tonic-gate 	 * If we are to display GOT summary information, then allocate
2257c478bd9Sstevel@tonic-gate 	 * the buffer to 'cache' the GOT symbols into now.
2267c478bd9Sstevel@tonic-gate 	 */
2275aefb655Srie 	if (DBG_ENABLED) {
228d326b23bSrie 		if ((ofl->ofl_gottable = gottable =
229d326b23bSrie 		    libld_calloc(ofl->ofl_gotcnt, sizeof (Gottable))) == 0)
2307c478bd9Sstevel@tonic-gate 		return ((Addr)S_ERROR);
2317c478bd9Sstevel@tonic-gate 	}
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	/*
2347c478bd9Sstevel@tonic-gate 	 * Traverse the program headers.  Determine the last executable segment
2357c478bd9Sstevel@tonic-gate 	 * and the last data segment so that we can update etext and edata. If
2367c478bd9Sstevel@tonic-gate 	 * we have empty segments (reservations) record them for setting _end.
2377c478bd9Sstevel@tonic-gate 	 */
2387c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_segs, lnp1, sgp)) {
2390bc07c75Srie 		Phdr	*phd = &(sgp->sg_phdr);
2400bc07c75Srie 		Os_desc	**ospp;
2410bc07c75Srie 		Aliste	off;
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 		if (phd->p_type == PT_LOAD) {
2440bc07c75Srie 			if (sgp->sg_osdescs != NULL) {
2450bc07c75Srie 			    Word	_flags = phd->p_flags & (PF_W | PF_R);
2460bc07c75Srie 
247fdf855a7Sseizo 			    if (_flags == PF_R)
24854d82594Sseizo 				tsgp = sgp;
249fdf855a7Sseizo 			    else if (_flags == (PF_W | PF_R))
25054d82594Sseizo 				dsgp = sgp;
2517c478bd9Sstevel@tonic-gate 			} else if (sgp->sg_flags & FLG_SG_EMPTY)
25254d82594Sseizo 			    esgp = sgp;
2537c478bd9Sstevel@tonic-gate 		}
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 		/*
2567c478bd9Sstevel@tonic-gate 		 * Generate a section symbol for each output section.
2577c478bd9Sstevel@tonic-gate 		 */
2580bc07c75Srie 		for (ALIST_TRAVERSE(sgp->sg_osdescs, off, ospp)) {
2597c478bd9Sstevel@tonic-gate 			Word	sectndx;
2607c478bd9Sstevel@tonic-gate 
2610bc07c75Srie 			osp = *ospp;
2620bc07c75Srie 
2637c478bd9Sstevel@tonic-gate 			sym = &_sym;
2647c478bd9Sstevel@tonic-gate 			sym->st_value = osp->os_shdr->sh_addr;
2657c478bd9Sstevel@tonic-gate 			sym->st_info = ELF_ST_INFO(STB_LOCAL, STT_SECTION);
2667c478bd9Sstevel@tonic-gate 			/* LINTED */
2677c478bd9Sstevel@tonic-gate 			sectndx = elf_ndxscn(osp->os_scn);
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 			if (symtab) {
2707c478bd9Sstevel@tonic-gate 				if (sectndx >= SHN_LORESERVE) {
2717c478bd9Sstevel@tonic-gate 					symshndx[symtab_ndx] = sectndx;
2727c478bd9Sstevel@tonic-gate 					sym->st_shndx = SHN_XINDEX;
2737c478bd9Sstevel@tonic-gate 				} else {
2747c478bd9Sstevel@tonic-gate 					/* LINTED */
2757c478bd9Sstevel@tonic-gate 					sym->st_shndx = (Half)sectndx;
2767c478bd9Sstevel@tonic-gate 				}
2777c478bd9Sstevel@tonic-gate 				symtab[symtab_ndx++] = *sym;
2787c478bd9Sstevel@tonic-gate 			}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 			if (dynsym && (osp->os_flags & FLG_OS_OUTREL))
2817c478bd9Sstevel@tonic-gate 				dynsym[dynsym_ndx++] = *sym;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 			if ((dynsym == 0) || (osp->os_flags & FLG_OS_OUTREL)) {
2847c478bd9Sstevel@tonic-gate 				if (versym)
2857c478bd9Sstevel@tonic-gate 					versym[*symndx - 1] = 0;
2867c478bd9Sstevel@tonic-gate 				osp->os_scnsymndx = *symndx - 1;
2875aefb655Srie 				DBG_CALL(Dbg_syms_sec_entry(ofl->ofl_lml,
2885aefb655Srie 				    osp->os_scnsymndx, sgp, osp));
2897c478bd9Sstevel@tonic-gate 			}
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 			/*
2927c478bd9Sstevel@tonic-gate 			 * Generate the .shstrtab for this section.
2937c478bd9Sstevel@tonic-gate 			 */
2947c478bd9Sstevel@tonic-gate 			(void) st_setstring(shstrtab, osp->os_name, &stoff);
2957c478bd9Sstevel@tonic-gate 			osp->os_shdr->sh_name = (Word)stoff;
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 			/*
2987c478bd9Sstevel@tonic-gate 			 * Find the section index for our special symbols.
2997c478bd9Sstevel@tonic-gate 			 */
3007c478bd9Sstevel@tonic-gate 			if (sgp == tsgp) {
3017c478bd9Sstevel@tonic-gate 				/* LINTED */
3027c478bd9Sstevel@tonic-gate 				etext_ndx = elf_ndxscn(osp->os_scn);
3037c478bd9Sstevel@tonic-gate 			} else if (dsgp == sgp) {
3047c478bd9Sstevel@tonic-gate 				if (osp->os_shdr->sh_type != SHT_NOBITS) {
3057c478bd9Sstevel@tonic-gate 					/* LINTED */
3067c478bd9Sstevel@tonic-gate 					edata_ndx = elf_ndxscn(osp->os_scn);
3077c478bd9Sstevel@tonic-gate 				}
3087c478bd9Sstevel@tonic-gate 			}
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 			if (start_set == 0) {
3117c478bd9Sstevel@tonic-gate 				start = sgp->sg_phdr.p_vaddr;
3127c478bd9Sstevel@tonic-gate 				/* LINTED */
3137c478bd9Sstevel@tonic-gate 				start_ndx = elf_ndxscn(osp->os_scn);
3147c478bd9Sstevel@tonic-gate 				start_set++;
3157c478bd9Sstevel@tonic-gate 			}
316c1c6f601Srie 
317c1c6f601Srie 			/*
318c1c6f601Srie 			 * While we're here, determine whether a .init or .fini
319c1c6f601Srie 			 * section exist.
320c1c6f601Srie 			 */
321c1c6f601Srie 			if ((iosp == 0) && (strcmp(osp->os_name,
322c1c6f601Srie 			    MSG_ORIG(MSG_SCN_INIT)) == 0))
323c1c6f601Srie 				iosp = osp;
324c1c6f601Srie 			if ((fosp == 0) && (strcmp(osp->os_name,
325c1c6f601Srie 			    MSG_ORIG(MSG_SCN_FINI)) == 0))
326c1c6f601Srie 				fosp = osp;
3277c478bd9Sstevel@tonic-gate 		}
3287c478bd9Sstevel@tonic-gate 	}
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	/*
3317c478bd9Sstevel@tonic-gate 	 * Add local register symbols to the .dynsym.  These are required as
3327c478bd9Sstevel@tonic-gate 	 * DT_REGISTER .dynamic entries must have a symbol to reference.
3337c478bd9Sstevel@tonic-gate 	 */
3347c478bd9Sstevel@tonic-gate 	if (ofl->ofl_regsyms && dynsym) {
3357c478bd9Sstevel@tonic-gate 		int	ndx;
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate 		for (ndx = 0; ndx < ofl->ofl_regsymsno; ndx++) {
3387c478bd9Sstevel@tonic-gate 			Sym_desc *	rsdp;
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 			if ((rsdp = ofl->ofl_regsyms[ndx]) == 0)
3417c478bd9Sstevel@tonic-gate 				continue;
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 			if (((rsdp->sd_flags1 & FLG_SY1_LOCL) == 0) &&
3447c478bd9Sstevel@tonic-gate 			    (ELF_ST_BIND(rsdp->sd_sym->st_info) != STB_LOCAL))
3457c478bd9Sstevel@tonic-gate 				continue;
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 			dynsym[dynsym_ndx] = *(rsdp->sd_sym);
3487c478bd9Sstevel@tonic-gate 			rsdp->sd_symndx = *symndx;
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 			if (dynsym[dynsym_ndx].st_name) {
3517c478bd9Sstevel@tonic-gate 				(void) st_setstring(dynstr, rsdp->sd_name,
3527c478bd9Sstevel@tonic-gate 				    &stoff);
3537c478bd9Sstevel@tonic-gate 				dynsym[dynsym_ndx].st_name = stoff;
3547c478bd9Sstevel@tonic-gate 			}
3557c478bd9Sstevel@tonic-gate 			dynsym_ndx++;
3567c478bd9Sstevel@tonic-gate 		}
3577c478bd9Sstevel@tonic-gate 	}
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	/*
3607c478bd9Sstevel@tonic-gate 	 * Having traversed all the output segments, warn the user if the
3617c478bd9Sstevel@tonic-gate 	 * traditional text or data segments don't exist.  Otherwise from these
3627c478bd9Sstevel@tonic-gate 	 * segments establish the values for `etext', `edata', `end', `END',
3637c478bd9Sstevel@tonic-gate 	 * and `START'.
3647c478bd9Sstevel@tonic-gate 	 */
3657c478bd9Sstevel@tonic-gate 	if (!(flags & FLG_OF_RELOBJ)) {
3667c478bd9Sstevel@tonic-gate 		Sg_desc *	sgp;
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 		if (tsgp)
3697c478bd9Sstevel@tonic-gate 			etext = tsgp->sg_phdr.p_vaddr + tsgp->sg_phdr.p_filesz;
3707c478bd9Sstevel@tonic-gate 		else {
3717c478bd9Sstevel@tonic-gate 			etext = (Addr)0;
3727c478bd9Sstevel@tonic-gate 			etext_ndx = SHN_ABS;
3737c478bd9Sstevel@tonic-gate 			etext_abs = 1;
3747c478bd9Sstevel@tonic-gate 			if (ofl->ofl_flags & FLG_OF_VERBOSE)
3755aefb655Srie 				eprintf(ofl->ofl_lml, ERR_WARNING,
3767c478bd9Sstevel@tonic-gate 				    MSG_INTL(MSG_UPD_NOREADSEG));
3777c478bd9Sstevel@tonic-gate 		}
3787c478bd9Sstevel@tonic-gate 		if (dsgp) {
3797c478bd9Sstevel@tonic-gate 			edata = dsgp->sg_phdr.p_vaddr + dsgp->sg_phdr.p_filesz;
3807c478bd9Sstevel@tonic-gate 		} else {
3817c478bd9Sstevel@tonic-gate 			edata = (Addr)0;
3827c478bd9Sstevel@tonic-gate 			edata_ndx = SHN_ABS;
3837c478bd9Sstevel@tonic-gate 			edata_abs = 1;
3847c478bd9Sstevel@tonic-gate 			if (ofl->ofl_flags & FLG_OF_VERBOSE)
3855aefb655Srie 				eprintf(ofl->ofl_lml, ERR_WARNING,
3867c478bd9Sstevel@tonic-gate 				    MSG_INTL(MSG_UPD_NORDWRSEG));
3877c478bd9Sstevel@tonic-gate 		}
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 		if (dsgp == 0) {
3907c478bd9Sstevel@tonic-gate 			if (tsgp)
3917c478bd9Sstevel@tonic-gate 				sgp = tsgp;
3927c478bd9Sstevel@tonic-gate 			else
3937c478bd9Sstevel@tonic-gate 				sgp = 0;
3947c478bd9Sstevel@tonic-gate 		} else if (tsgp == 0)
3957c478bd9Sstevel@tonic-gate 			sgp = dsgp;
3967c478bd9Sstevel@tonic-gate 		else if (dsgp->sg_phdr.p_vaddr > tsgp->sg_phdr.p_vaddr)
3977c478bd9Sstevel@tonic-gate 			sgp = dsgp;
3987c478bd9Sstevel@tonic-gate 		else if (dsgp->sg_phdr.p_vaddr < tsgp->sg_phdr.p_vaddr)
3997c478bd9Sstevel@tonic-gate 			sgp = tsgp;
4007c478bd9Sstevel@tonic-gate 		else {
4017c478bd9Sstevel@tonic-gate 			/*
4027c478bd9Sstevel@tonic-gate 			 * One of the segments must be of zero size.
4037c478bd9Sstevel@tonic-gate 			 */
4047c478bd9Sstevel@tonic-gate 			if (tsgp->sg_phdr.p_memsz)
4057c478bd9Sstevel@tonic-gate 				sgp = tsgp;
4067c478bd9Sstevel@tonic-gate 			else
4077c478bd9Sstevel@tonic-gate 				sgp = dsgp;
4087c478bd9Sstevel@tonic-gate 		}
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 		if (esgp && (esgp->sg_phdr.p_vaddr > sgp->sg_phdr.p_vaddr))
4117c478bd9Sstevel@tonic-gate 			sgp = esgp;
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate 		if (sgp) {
4147c478bd9Sstevel@tonic-gate 			end = sgp->sg_phdr.p_vaddr + sgp->sg_phdr.p_memsz;
4157c478bd9Sstevel@tonic-gate 
416fdf855a7Sseizo 			/*
417fdf855a7Sseizo 			 * If the last loadable segment is a read-only segment,
418fdf855a7Sseizo 			 * then the application which uses the symbol _end to
419fdf855a7Sseizo 			 * find the beginning of writable heap area may cause
420fdf855a7Sseizo 			 * segmentation violation. We adjust the value of the
421fdf855a7Sseizo 			 * _end to skip to the next page boundary.
422fdf855a7Sseizo 			 *
423fdf855a7Sseizo 			 * 6401812 System interface which returs beginning
424fdf855a7Sseizo 			 *	   heap would be nice.
425fdf855a7Sseizo 			 * When the above RFE is implemented, the changes below
426fdf855a7Sseizo 			 * could be changed in a better way.
427fdf855a7Sseizo 			 */
428fdf855a7Sseizo 			if ((sgp->sg_phdr.p_flags & PF_W) == 0)
429fdf855a7Sseizo 			    end = (Addr) S_ROUND(end, sysconf(_SC_PAGESIZE));
430fdf855a7Sseizo 
4317c478bd9Sstevel@tonic-gate 			/*
4327c478bd9Sstevel@tonic-gate 			 * If we're dealing with a memory reservation there are
4337c478bd9Sstevel@tonic-gate 			 * no sections to establish an index for _end, so assign
4347c478bd9Sstevel@tonic-gate 			 * it as an absolute.
4357c478bd9Sstevel@tonic-gate 			 */
4360bc07c75Srie 			if (sgp->sg_osdescs != NULL) {
4370bc07c75Srie 				Os_desc	**ospp;
4380bc07c75Srie 				Alist	*alp = sgp->sg_osdescs;
4390bc07c75Srie 				Aliste	last = alp->al_next - alp->al_size;
4407c478bd9Sstevel@tonic-gate 
4410bc07c75Srie 				/*
4420bc07c75Srie 				 * Determine the last section for this segment.
4430bc07c75Srie 				 */
4440bc07c75Srie 				/* LINTED */
4450bc07c75Srie 				ospp = (Os_desc **)((char *)alp + last);
4467c478bd9Sstevel@tonic-gate 				/* LINTED */
4470bc07c75Srie 				end_ndx = elf_ndxscn((*ospp)->os_scn);
4487c478bd9Sstevel@tonic-gate 			} else {
4497c478bd9Sstevel@tonic-gate 				end_ndx = SHN_ABS;
4507c478bd9Sstevel@tonic-gate 				end_abs = 1;
4517c478bd9Sstevel@tonic-gate 			}
4527c478bd9Sstevel@tonic-gate 		} else {
4537c478bd9Sstevel@tonic-gate 			end = (Addr) 0;
4547c478bd9Sstevel@tonic-gate 			end_ndx = SHN_ABS;
4557c478bd9Sstevel@tonic-gate 			end_abs = 1;
4565aefb655Srie 			eprintf(ofl->ofl_lml, ERR_WARNING,
4575aefb655Srie 			    MSG_INTL(MSG_UPD_NOSEG));
4587c478bd9Sstevel@tonic-gate 		}
4597c478bd9Sstevel@tonic-gate 	}
4607c478bd9Sstevel@tonic-gate 
4615aefb655Srie 	DBG_CALL(Dbg_syms_up_title(ofl->ofl_lml));
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 	/*
4647c478bd9Sstevel@tonic-gate 	 * Initialize the scoped symbol table entry point.  This is for all
4657c478bd9Sstevel@tonic-gate 	 * the global symbols that have been scoped to locals and will be
4667c478bd9Sstevel@tonic-gate 	 * filled in during global symbol processing so that we don't have
4677c478bd9Sstevel@tonic-gate 	 * to traverse the globals symbol hash array more than once.
4687c478bd9Sstevel@tonic-gate 	 */
4697c478bd9Sstevel@tonic-gate 	if (symtab) {
4707c478bd9Sstevel@tonic-gate 		scopesym_ndx = symtab_ndx;
4717c478bd9Sstevel@tonic-gate 		symtab_ndx += ofl->ofl_scopecnt;
4727c478bd9Sstevel@tonic-gate 	}
4737c478bd9Sstevel@tonic-gate 
4747c478bd9Sstevel@tonic-gate 	/*
4757c478bd9Sstevel@tonic-gate 	 * Assign .sunwdata1 information
4767c478bd9Sstevel@tonic-gate 	 */
4777c478bd9Sstevel@tonic-gate 	if (ofl->ofl_issunwdata1) {
4787c478bd9Sstevel@tonic-gate 		osp = ofl->ofl_issunwdata1->is_osdesc;
4797c478bd9Sstevel@tonic-gate 		sunwdata1addr = (Addr)(osp->os_shdr->sh_addr +
4807c478bd9Sstevel@tonic-gate 			ofl->ofl_issunwdata1->is_indata->d_off);
4817c478bd9Sstevel@tonic-gate 		/* LINTED */
4827c478bd9Sstevel@tonic-gate 		sunwdata1ndx = elf_ndxscn(osp->os_scn);
4837c478bd9Sstevel@tonic-gate 		ofl->ofl_sunwdata1ndx = osp->os_scnsymndx;
4847c478bd9Sstevel@tonic-gate 	}
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate 	/*
4877c478bd9Sstevel@tonic-gate 	 * If we are generating a .symtab collect all the local symbols,
4887c478bd9Sstevel@tonic-gate 	 * assigning a new virtual address or displacement (value).
4897c478bd9Sstevel@tonic-gate 	 */
4907c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_objs, lnp1, ifl)) {
4917c478bd9Sstevel@tonic-gate 		Xword		lndx, local;
4927c478bd9Sstevel@tonic-gate 		Is_desc *	isc;
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 		/*
4957c478bd9Sstevel@tonic-gate 		 * Check that we have local symbols to process.  If the user
4967c478bd9Sstevel@tonic-gate 		 * has indicated scoping then scan the global symbols also
4977c478bd9Sstevel@tonic-gate 		 * looking for entries from this file to reduce to locals.
4987c478bd9Sstevel@tonic-gate 		 */
4997c478bd9Sstevel@tonic-gate 		if ((local = ifl->ifl_locscnt) == 0)
5007c478bd9Sstevel@tonic-gate 			continue;
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 		for (lndx = 1; lndx < local; lndx++) {
5037c478bd9Sstevel@tonic-gate 			Listnode	*lnp2;
5047c478bd9Sstevel@tonic-gate 			Gotndx		*gnp;
5057c478bd9Sstevel@tonic-gate 			unsigned char	type;
5067c478bd9Sstevel@tonic-gate 			Word		*_symshndx;
507*9039eeafSab 			int		enter_in_symtab, enter_in_ldynsym;
508*9039eeafSab 			int		update_done;
5097c478bd9Sstevel@tonic-gate 
5107c478bd9Sstevel@tonic-gate 			sdp = ifl->ifl_oldndx[lndx];
5117c478bd9Sstevel@tonic-gate 			sym = sdp->sd_sym;
5127c478bd9Sstevel@tonic-gate 
5135aefb655Srie #if	defined(sparc) || defined(__sparcv9)
5147c478bd9Sstevel@tonic-gate 			/*
5157c478bd9Sstevel@tonic-gate 			 * Assign a got offset if necessary.
5167c478bd9Sstevel@tonic-gate 			 */
5175aefb655Srie 			if (ld_assign_got(ofl, sdp) == S_ERROR)
5187c478bd9Sstevel@tonic-gate 				return ((Addr)S_ERROR);
5197c478bd9Sstevel@tonic-gate #elif defined(i386) || defined(__amd64)
5207c478bd9Sstevel@tonic-gate /* nothing to do */
5217c478bd9Sstevel@tonic-gate #else
5227c478bd9Sstevel@tonic-gate #error Unknown architecture!
5237c478bd9Sstevel@tonic-gate #endif
5245aefb655Srie 			if (DBG_ENABLED) {
5257c478bd9Sstevel@tonic-gate 			    for (LIST_TRAVERSE(&sdp->sd_GOTndxs, lnp2, gnp)) {
526d326b23bSrie 				gottable->gt_sym = sdp;
527d326b23bSrie 				gottable->gt_gndx.gn_gotndx = gnp->gn_gotndx;
528d326b23bSrie 				gottable->gt_gndx.gn_addend = gnp->gn_addend;
529d326b23bSrie 				gottable++;
5307c478bd9Sstevel@tonic-gate 			    }
5317c478bd9Sstevel@tonic-gate 			}
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 			if ((type = ELF_ST_TYPE(sym->st_info)) == STT_SECTION)
5347c478bd9Sstevel@tonic-gate 				continue;
5357c478bd9Sstevel@tonic-gate 
5367c478bd9Sstevel@tonic-gate 			/*
5377c478bd9Sstevel@tonic-gate 			 * Ignore any symbols that have been marked as invalid
5387c478bd9Sstevel@tonic-gate 			 * during input processing.  Providing these aren't used
5397c478bd9Sstevel@tonic-gate 			 * for relocation they'll just be dropped from the
5407c478bd9Sstevel@tonic-gate 			 * output image.
5417c478bd9Sstevel@tonic-gate 			 */
5427c478bd9Sstevel@tonic-gate 			if (sdp->sd_flags & FLG_SY_INVALID)
5437c478bd9Sstevel@tonic-gate 				continue;
5447c478bd9Sstevel@tonic-gate 
5457c478bd9Sstevel@tonic-gate 			/*
5467c478bd9Sstevel@tonic-gate 			 * If the section that this symbol was associated
5477c478bd9Sstevel@tonic-gate 			 * with has been discarded - then we discard
5487c478bd9Sstevel@tonic-gate 			 * the local symbol along with it.
5497c478bd9Sstevel@tonic-gate 			 */
5507c478bd9Sstevel@tonic-gate 			if (sdp->sd_flags & FLG_SY_ISDISC)
5517c478bd9Sstevel@tonic-gate 				continue;
5527c478bd9Sstevel@tonic-gate 
5537c478bd9Sstevel@tonic-gate 			/*
5547c478bd9Sstevel@tonic-gate 			 * Generate an output symbol to represent this input
5557c478bd9Sstevel@tonic-gate 			 * symbol.  Even if the symbol table is to be stripped
5567c478bd9Sstevel@tonic-gate 			 * we still need to update any local symbols that are
5577c478bd9Sstevel@tonic-gate 			 * used during relocation.
5587c478bd9Sstevel@tonic-gate 			 */
559*9039eeafSab 			enter_in_symtab = symtab &&
560*9039eeafSab 			    (!(ofl->ofl_flags1 & FLG_OF1_REDLSYM) ||
561*9039eeafSab 			    (sdp->sd_psyminfo));
562*9039eeafSab 			enter_in_ldynsym = ldynsym && sdp->sd_name &&
563*9039eeafSab 			    ((type == STT_FUNC) || (type == STT_FILE));
5647c478bd9Sstevel@tonic-gate 			_symshndx = 0;
565*9039eeafSab 			if (enter_in_symtab) {
5667c478bd9Sstevel@tonic-gate 				if (!dynsym)
5677c478bd9Sstevel@tonic-gate 					sdp->sd_symndx = *symndx;
5687c478bd9Sstevel@tonic-gate 				symtab[symtab_ndx] = *sym;
5697c478bd9Sstevel@tonic-gate 				/*
5707c478bd9Sstevel@tonic-gate 				 * Provided this isn't an unnamed register
5717c478bd9Sstevel@tonic-gate 				 * symbol, update its name.
5727c478bd9Sstevel@tonic-gate 				 */
5737c478bd9Sstevel@tonic-gate 				if (((sdp->sd_flags & FLG_SY_REGSYM) == 0) ||
5747c478bd9Sstevel@tonic-gate 				    symtab[symtab_ndx].st_name) {
5757c478bd9Sstevel@tonic-gate 					(void) st_setstring(strtab,
5767c478bd9Sstevel@tonic-gate 					    sdp->sd_name, &stoff);
5777c478bd9Sstevel@tonic-gate 					symtab[symtab_ndx].st_name = stoff;
5787c478bd9Sstevel@tonic-gate 				}
5797c478bd9Sstevel@tonic-gate 				sdp->sd_flags &= ~FLG_SY_CLEAN;
5807c478bd9Sstevel@tonic-gate 				if (symshndx)
5817c478bd9Sstevel@tonic-gate 					_symshndx = &symshndx[symtab_ndx];
5827c478bd9Sstevel@tonic-gate 				sdp->sd_sym = sym = &symtab[symtab_ndx++];
5837c478bd9Sstevel@tonic-gate 
5847c478bd9Sstevel@tonic-gate 				if ((sdp->sd_flags & FLG_SY_SPECSEC) &&
585*9039eeafSab 				    (sym->st_shndx == SHN_ABS) &&
586*9039eeafSab 				    !enter_in_ldynsym)
5877c478bd9Sstevel@tonic-gate 					continue;
588*9039eeafSab 			} else if (enter_in_ldynsym) {
589*9039eeafSab 				/*
590*9039eeafSab 				 * Not using symtab, but we do have ldynsym
591*9039eeafSab 				 * available.
592*9039eeafSab 				 */
593*9039eeafSab 				ldynsym[ldynsym_ndx] = *sym;
594*9039eeafSab 				(void) st_setstring(dynstr, sdp->sd_name,
595*9039eeafSab 					&stoff);
596*9039eeafSab 				ldynsym[ldynsym_ndx].st_name = stoff;
597*9039eeafSab 
598*9039eeafSab 				sdp->sd_flags &= ~FLG_SY_CLEAN;
599*9039eeafSab 				if (ldynshndx)
600*9039eeafSab 					_symshndx = &ldynshndx[ldynsym_ndx];
601*9039eeafSab 				sdp->sd_sym = sym = &ldynsym[ldynsym_ndx++];
602*9039eeafSab 			} else {	/* Not using symtab or ldynsym */
6037c478bd9Sstevel@tonic-gate 				/*
6047c478bd9Sstevel@tonic-gate 				 * If this symbol requires modifying to provide
6057c478bd9Sstevel@tonic-gate 				 * for a relocation or move table update, make
6067c478bd9Sstevel@tonic-gate 				 * a copy of it.
6077c478bd9Sstevel@tonic-gate 				 */
6087c478bd9Sstevel@tonic-gate 				if (!(sdp->sd_flags & FLG_SY_UPREQD) &&
6097c478bd9Sstevel@tonic-gate 				    !(sdp->sd_psyminfo))
6107c478bd9Sstevel@tonic-gate 					continue;
6117c478bd9Sstevel@tonic-gate 				if ((sdp->sd_flags & FLG_SY_SPECSEC) &&
6127c478bd9Sstevel@tonic-gate 				    (sym->st_shndx == SHN_ABS))
6137c478bd9Sstevel@tonic-gate 					continue;
6147c478bd9Sstevel@tonic-gate 
6155aefb655Srie 				if (ld_sym_copy(sdp) == S_ERROR)
6167c478bd9Sstevel@tonic-gate 					return ((Addr)S_ERROR);
6177c478bd9Sstevel@tonic-gate 				sym = sdp->sd_sym;
6187c478bd9Sstevel@tonic-gate 			}
6197c478bd9Sstevel@tonic-gate 
6207c478bd9Sstevel@tonic-gate 			/*
6217c478bd9Sstevel@tonic-gate 			 * Update the symbols contents if necessary.
6227c478bd9Sstevel@tonic-gate 			 */
623*9039eeafSab 			update_done = 0;
6247c478bd9Sstevel@tonic-gate 			if (type == STT_FILE) {
6257c478bd9Sstevel@tonic-gate 				sdp->sd_shndx = sym->st_shndx = SHN_ABS;
6267c478bd9Sstevel@tonic-gate 				sdp->sd_flags |= FLG_SY_SPECSEC;
627*9039eeafSab 				update_done = 1;
6287c478bd9Sstevel@tonic-gate 			}
6297c478bd9Sstevel@tonic-gate 
6307c478bd9Sstevel@tonic-gate 			/*
6317c478bd9Sstevel@tonic-gate 			 * If we are expanding the locally bound partially
6327c478bd9Sstevel@tonic-gate 			 * initialized symbols, then update the address here.
6337c478bd9Sstevel@tonic-gate 			 */
6347c478bd9Sstevel@tonic-gate 			if (ofl->ofl_issunwdata1 &&
635*9039eeafSab 			    (sdp->sd_flags & FLG_SY_PAREXPN) && !update_done) {
6367c478bd9Sstevel@tonic-gate 				static	Addr	laddr = 0;
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate 				sym->st_shndx = sunwdata1ndx;
6397c478bd9Sstevel@tonic-gate 				sdp->sd_isc = ofl->ofl_issunwdata1;
640*9039eeafSab 				if (ofl->ofl_flags & FLG_OF_RELOBJ) {
6417c478bd9Sstevel@tonic-gate 					sym->st_value = sunwdata1addr;
642*9039eeafSab 				} else {
6437c478bd9Sstevel@tonic-gate 					sym->st_value = laddr;
6447c478bd9Sstevel@tonic-gate 					laddr += sym->st_size;
6457c478bd9Sstevel@tonic-gate 				}
6467c478bd9Sstevel@tonic-gate 				sunwdata1addr += sym->st_size;
6477c478bd9Sstevel@tonic-gate 			}
6487c478bd9Sstevel@tonic-gate 
6497c478bd9Sstevel@tonic-gate 			/*
6507c478bd9Sstevel@tonic-gate 			 * If this isn't an UNDEF symbol (ie. an input section
6517c478bd9Sstevel@tonic-gate 			 * is associated), update the symbols value and index.
6527c478bd9Sstevel@tonic-gate 			 */
653*9039eeafSab 			if (((isc = sdp->sd_isc) != 0) && !update_done) {
6547c478bd9Sstevel@tonic-gate 				Word	sectndx;
6557c478bd9Sstevel@tonic-gate 
6567c478bd9Sstevel@tonic-gate 				osp = isc->is_osdesc;
6577c478bd9Sstevel@tonic-gate 				/* LINTED */
6587c478bd9Sstevel@tonic-gate 				sym->st_value +=
6597c478bd9Sstevel@tonic-gate 				    (Off)_elf_getxoff(isc->is_indata);
6607c478bd9Sstevel@tonic-gate 				if (!(flags & FLG_OF_RELOBJ)) {
6617c478bd9Sstevel@tonic-gate 					sym->st_value += osp->os_shdr->sh_addr;
6627c478bd9Sstevel@tonic-gate 					/*
6637c478bd9Sstevel@tonic-gate 					 * TLS symbols are relative to
6647c478bd9Sstevel@tonic-gate 					 * the TLS segment.
6657c478bd9Sstevel@tonic-gate 					 */
6667c478bd9Sstevel@tonic-gate 					if ((ELF_ST_TYPE(sym->st_info) ==
667*9039eeafSab 					    STT_TLS) && (ofl->ofl_tlsphdr)) {
6687c478bd9Sstevel@tonic-gate 						sym->st_value -=
6697c478bd9Sstevel@tonic-gate 						    ofl->ofl_tlsphdr->p_vaddr;
670*9039eeafSab 					}
6717c478bd9Sstevel@tonic-gate 				}
6727c478bd9Sstevel@tonic-gate 				/* LINTED */
6737c478bd9Sstevel@tonic-gate 				if ((sdp->sd_shndx = sectndx =
6747c478bd9Sstevel@tonic-gate 				    elf_ndxscn(osp->os_scn)) >= SHN_LORESERVE) {
6757c478bd9Sstevel@tonic-gate 					if (_symshndx) {
6767c478bd9Sstevel@tonic-gate 						*_symshndx = sectndx;
6777c478bd9Sstevel@tonic-gate 					}
6787c478bd9Sstevel@tonic-gate 					sym->st_shndx = SHN_XINDEX;
6797c478bd9Sstevel@tonic-gate 				} else {
6807c478bd9Sstevel@tonic-gate 					/* LINTED */
6817c478bd9Sstevel@tonic-gate 					sym->st_shndx = sectndx;
6827c478bd9Sstevel@tonic-gate 				}
6837c478bd9Sstevel@tonic-gate 			}
684*9039eeafSab 
685*9039eeafSab 			/*
686*9039eeafSab 			 * If entering the symbol in both the symtab and the
687*9039eeafSab 			 * ldynsym, then the one in symtab needs to be
688*9039eeafSab 			 * copied to ldynsym. If it is only in the ldynsym,
689*9039eeafSab 			 * then the code above already set it up and we have
690*9039eeafSab 			 * nothing more to do here.
691*9039eeafSab 			 */
692*9039eeafSab 			if (enter_in_symtab && enter_in_ldynsym) {
693*9039eeafSab 				ldynsym[ldynsym_ndx] = *sym;
694*9039eeafSab 				(void) st_setstring(dynstr, sdp->sd_name,
695*9039eeafSab 					&stoff);
696*9039eeafSab 				ldynsym[ldynsym_ndx].st_name = stoff;
697*9039eeafSab 
698*9039eeafSab 				if (_symshndx && ldynshndx)
699*9039eeafSab 					ldynshndx[ldynsym_ndx] = *_symshndx;
700*9039eeafSab 
701*9039eeafSab 				ldynsym_ndx++;
702*9039eeafSab 			}
7037c478bd9Sstevel@tonic-gate 		}
7047c478bd9Sstevel@tonic-gate 	}
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 	/*
7077c478bd9Sstevel@tonic-gate 	 * Two special symbols are `_init' and `_fini'.  If these are supplied
7087c478bd9Sstevel@tonic-gate 	 * by crti.o then they are used to represent the total concatenation of
709c1c6f601Srie 	 * the `.init' and `.fini' sections.
710c1c6f601Srie 	 *
711c1c6f601Srie 	 * First, determine whether any .init or .fini sections exist.  If these
712c1c6f601Srie 	 * sections exist when a dynamic object is being built, but no `_init'
713c1c6f601Srie 	 * or `_fini' symbols are found, then the user is probably building this
714c1c6f601Srie 	 * object directly from ld(1) rather than using a compiler driver that
715c1c6f601Srie 	 * provides the symbols via crt's.
716c1c6f601Srie 	 *
717c1c6f601Srie 	 * If the .init or .fini section exist, and their associated symbols,
718c1c6f601Srie 	 * determine the size of the sections and updated the symbols value
719c1c6f601Srie 	 * accordingly.
7207c478bd9Sstevel@tonic-gate 	 */
7215aefb655Srie 	if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_INIT_U), SYM_NOHASH, 0,
7227c478bd9Sstevel@tonic-gate 	    ofl)) != NULL) && (sdp->sd_ref == REF_REL_NEED) && sdp->sd_isc &&
723c1c6f601Srie 	    (sdp->sd_isc->is_osdesc == iosp)) {
7245aefb655Srie 		if (ld_sym_copy(sdp) == S_ERROR)
7257c478bd9Sstevel@tonic-gate 			return ((Addr)S_ERROR);
7267c478bd9Sstevel@tonic-gate 		sdp->sd_sym->st_size =
7277c478bd9Sstevel@tonic-gate 			sdp->sd_isc->is_osdesc->os_shdr->sh_size;
728c1c6f601Srie 	} else if (iosp && !(flags & FLG_OF_RELOBJ)) {
729c1c6f601Srie 		eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_SYM_NOCRT),
730c1c6f601Srie 		    MSG_ORIG(MSG_SYM_INIT_U), MSG_ORIG(MSG_SCN_INIT));
7317c478bd9Sstevel@tonic-gate 	}
732c1c6f601Srie 
7335aefb655Srie 	if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_FINI_U), SYM_NOHASH, 0,
7347c478bd9Sstevel@tonic-gate 	    ofl)) != NULL) && (sdp->sd_ref == REF_REL_NEED) && sdp->sd_isc &&
735c1c6f601Srie 	    (sdp->sd_isc->is_osdesc == fosp)) {
7365aefb655Srie 		if (ld_sym_copy(sdp) == S_ERROR)
7377c478bd9Sstevel@tonic-gate 			return ((Addr)S_ERROR);
7387c478bd9Sstevel@tonic-gate 		sdp->sd_sym->st_size =
7397c478bd9Sstevel@tonic-gate 			sdp->sd_isc->is_osdesc->os_shdr->sh_size;
740c1c6f601Srie 	} else if (fosp && !(flags & FLG_OF_RELOBJ)) {
741c1c6f601Srie 		eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_SYM_NOCRT),
742c1c6f601Srie 		    MSG_ORIG(MSG_SYM_FINI_U), MSG_ORIG(MSG_SCN_FINI));
7437c478bd9Sstevel@tonic-gate 	}
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 	/*
7467c478bd9Sstevel@tonic-gate 	 * Assign .bss information for use with updating COMMON symbols.
7477c478bd9Sstevel@tonic-gate 	 */
7487c478bd9Sstevel@tonic-gate 	if (ofl->ofl_isbss) {
7497c478bd9Sstevel@tonic-gate 		osp = ofl->ofl_isbss->is_osdesc;
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate 		bssaddr = osp->os_shdr->sh_addr +
7527c478bd9Sstevel@tonic-gate 			(Off)_elf_getxoff(ofl->ofl_isbss->is_indata);
7537c478bd9Sstevel@tonic-gate 		/* LINTED */
7547c478bd9Sstevel@tonic-gate 		bssndx = elf_ndxscn(osp->os_scn);
7557c478bd9Sstevel@tonic-gate 	}
7567c478bd9Sstevel@tonic-gate 
75754d82594Sseizo #if	(defined(__i386) || defined(__amd64)) && defined(_ELF64)
75854d82594Sseizo 	/*
75954d82594Sseizo 	 * Assign .lbss information for use with updating LCOMMON symbols.
76054d82594Sseizo 	 */
76154d82594Sseizo 	if (ofl->ofl_islbss) {
76254d82594Sseizo 		osp = ofl->ofl_islbss->is_osdesc;
76354d82594Sseizo 
76454d82594Sseizo 		lbssaddr = osp->os_shdr->sh_addr +
76554d82594Sseizo 			(Off)_elf_getxoff(ofl->ofl_islbss->is_indata);
76654d82594Sseizo 		/* LINTED */
76754d82594Sseizo 		lbssndx = elf_ndxscn(osp->os_scn);
76854d82594Sseizo 	}
76954d82594Sseizo #endif
77054d82594Sseizo 
7717c478bd9Sstevel@tonic-gate 	/*
7727c478bd9Sstevel@tonic-gate 	 * Assign .tlsbss information for use with updating COMMON symbols.
7737c478bd9Sstevel@tonic-gate 	 */
7747c478bd9Sstevel@tonic-gate 	if (ofl->ofl_istlsbss) {
7757c478bd9Sstevel@tonic-gate 		osp = ofl->ofl_istlsbss->is_osdesc;
7767c478bd9Sstevel@tonic-gate 		tlsbssaddr = osp->os_shdr->sh_addr +
7777c478bd9Sstevel@tonic-gate 			(Off)_elf_getxoff(ofl->ofl_istlsbss->is_indata);
7787c478bd9Sstevel@tonic-gate 		/* LINTED */
7797c478bd9Sstevel@tonic-gate 		tlsbssndx = elf_ndxscn(osp->os_scn);
7807c478bd9Sstevel@tonic-gate 	}
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate 	/*
7837c478bd9Sstevel@tonic-gate 	 * Assign .SUNWbss information for use with updating COMMON symbols.
7847c478bd9Sstevel@tonic-gate 	 */
7857c478bd9Sstevel@tonic-gate 	if (ofl->ofl_issunwbss) {
7867c478bd9Sstevel@tonic-gate 		osp = ofl->ofl_issunwbss->is_osdesc;
7877c478bd9Sstevel@tonic-gate 		sunwbssaddr = (Addr)(osp->os_shdr->sh_addr +
7887c478bd9Sstevel@tonic-gate 			ofl->ofl_issunwbss->is_indata->d_off);
7897c478bd9Sstevel@tonic-gate 		/* LINTED */
7907c478bd9Sstevel@tonic-gate 		sunwbssndx = elf_ndxscn(osp->os_scn);
7917c478bd9Sstevel@tonic-gate 	}
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate 
7947c478bd9Sstevel@tonic-gate 	if ((sorted_syms = libld_calloc(ofl->ofl_globcnt +
7957c478bd9Sstevel@tonic-gate 	    ofl->ofl_elimcnt + ofl->ofl_scopecnt, sizeof (*sorted_syms))) == 0)
7967c478bd9Sstevel@tonic-gate 		return ((Addr)S_ERROR);
7977c478bd9Sstevel@tonic-gate 
7987c478bd9Sstevel@tonic-gate 	scndx = 0;
7997c478bd9Sstevel@tonic-gate 	ssndx = ofl->ofl_scopecnt + ofl->ofl_elimcnt;
8007c478bd9Sstevel@tonic-gate 
8017c478bd9Sstevel@tonic-gate 	/*
8027c478bd9Sstevel@tonic-gate 	 * Traverse the internal symbol table updating information and
8037c478bd9Sstevel@tonic-gate 	 * allocating common.
8047c478bd9Sstevel@tonic-gate 	 */
8057c478bd9Sstevel@tonic-gate 	for (sav = avl_first(&ofl->ofl_symavl); sav;
8067c478bd9Sstevel@tonic-gate 	    sav = AVL_NEXT(&ofl->ofl_symavl, sav)) {
8077c478bd9Sstevel@tonic-gate 		Sym *	symptr;
8087c478bd9Sstevel@tonic-gate 		int	local;
80954d82594Sseizo 		int	restore;
8107c478bd9Sstevel@tonic-gate 
8117c478bd9Sstevel@tonic-gate 		sdp = sav->sav_symdesc;
8127c478bd9Sstevel@tonic-gate 
8137c478bd9Sstevel@tonic-gate 		/*
8147c478bd9Sstevel@tonic-gate 		 * Ignore any symbols that have been marked as
8157c478bd9Sstevel@tonic-gate 		 * invalid during input processing.  Providing
8167c478bd9Sstevel@tonic-gate 		 * these aren't used for relocation they'll
8177c478bd9Sstevel@tonic-gate 		 * just be dropped from the output image.
8187c478bd9Sstevel@tonic-gate 		 */
8197c478bd9Sstevel@tonic-gate 		if (sdp->sd_flags & FLG_SY_INVALID) {
8205aefb655Srie 			DBG_CALL(Dbg_syms_old(ofl, sdp));
8215aefb655Srie 			DBG_CALL(Dbg_syms_ignore(ofl, sdp));
8227c478bd9Sstevel@tonic-gate 			continue;
8237c478bd9Sstevel@tonic-gate 		}
8247c478bd9Sstevel@tonic-gate 
8257c478bd9Sstevel@tonic-gate 		/*
8267c478bd9Sstevel@tonic-gate 		 * Only needed symbols will be copied to the
8277c478bd9Sstevel@tonic-gate 		 * output symbol table.
8287c478bd9Sstevel@tonic-gate 		 */
8297c478bd9Sstevel@tonic-gate 		if (sdp->sd_ref == REF_DYN_SEEN)
8307c478bd9Sstevel@tonic-gate 			continue;
8317c478bd9Sstevel@tonic-gate 
8327c478bd9Sstevel@tonic-gate 		if ((sdp->sd_flags1 & FLG_SY1_LOCL) &&
8337c478bd9Sstevel@tonic-gate 		    (flags & FLG_OF_PROCRED))
8347c478bd9Sstevel@tonic-gate 			local = 1;
8357c478bd9Sstevel@tonic-gate 		else
8367c478bd9Sstevel@tonic-gate 			local = 0;
8377c478bd9Sstevel@tonic-gate 
8387c478bd9Sstevel@tonic-gate 		if (local || (ofl->ofl_hashbkts == 0)) {
8397c478bd9Sstevel@tonic-gate 			sorted_syms[scndx++].sl_sdp = sdp;
8407c478bd9Sstevel@tonic-gate 		} else {
8417c478bd9Sstevel@tonic-gate 			sorted_syms[ssndx].sl_hval = sdp->sd_aux->sa_hash %
8427c478bd9Sstevel@tonic-gate 			    ofl->ofl_hashbkts;
8437c478bd9Sstevel@tonic-gate 			sorted_syms[ssndx].sl_sdp = sdp;
8447c478bd9Sstevel@tonic-gate 			ssndx++;
8457c478bd9Sstevel@tonic-gate 		}
8467c478bd9Sstevel@tonic-gate 
8477c478bd9Sstevel@tonic-gate 		/*
848c1c6f601Srie 		 * Note - expand the COMMON symbols here because an address
849c1c6f601Srie 		 * must be assigned to them in the same order that space was
850c1c6f601Srie 		 * calculated in sym_validate().  If this ordering isn't
851c1c6f601Srie 		 * followed differing alignment requirements can throw us all
852c1c6f601Srie 		 * out of whack.
8537c478bd9Sstevel@tonic-gate 		 *
854c1c6f601Srie 		 * The expanded .bss global symbol is handled here as well.
8557c478bd9Sstevel@tonic-gate 		 *
856c1c6f601Srie 		 * The actual adding entries into the symbol table still occurs
857c1c6f601Srie 		 * below in hashbucket order.
8587c478bd9Sstevel@tonic-gate 		 */
8597c478bd9Sstevel@tonic-gate 		symptr = sdp->sd_sym;
86054d82594Sseizo 		restore = 0;
8617c478bd9Sstevel@tonic-gate 		if ((sdp->sd_flags & FLG_SY_PAREXPN) ||
8627c478bd9Sstevel@tonic-gate 		    ((sdp->sd_flags & FLG_SY_SPECSEC) &&
8637c478bd9Sstevel@tonic-gate 		    (sdp->sd_shndx = symptr->st_shndx) == SHN_COMMON)) {
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate 			/*
866c1c6f601Srie 			 * An expanded symbol goes to .sunwdata1.
8677c478bd9Sstevel@tonic-gate 			 *
868c1c6f601Srie 			 * A partial initialized global symbol within a shared
869c1c6f601Srie 			 * object goes to .sunwbss.
8707c478bd9Sstevel@tonic-gate 			 *
871c1c6f601Srie 			 * Assign COMMON allocations to .bss.
8727c478bd9Sstevel@tonic-gate 			 *
8737c478bd9Sstevel@tonic-gate 			 * Otherwise leave it as is.
8747c478bd9Sstevel@tonic-gate 			 */
8757c478bd9Sstevel@tonic-gate 			if (sdp->sd_flags & FLG_SY_PAREXPN) {
8767c478bd9Sstevel@tonic-gate 				restore = 1;
8777c478bd9Sstevel@tonic-gate 				sdp->sd_shndx = sunwdata1ndx;
8787c478bd9Sstevel@tonic-gate 				sdp->sd_flags &= ~FLG_SY_SPECSEC;
8797c478bd9Sstevel@tonic-gate 				symptr->st_value = (Xword) S_ROUND(
8807c478bd9Sstevel@tonic-gate 				    sunwdata1addr, symptr->st_value);
8817c478bd9Sstevel@tonic-gate 				sunwdata1addr = symptr->st_value +
8827c478bd9Sstevel@tonic-gate 					symptr->st_size;
8837c478bd9Sstevel@tonic-gate 				sdp->sd_isc = ofl->ofl_issunwdata1;
8847c478bd9Sstevel@tonic-gate 				sdp->sd_flags |= FLG_SY_COMMEXP;
8857c478bd9Sstevel@tonic-gate 
8867c478bd9Sstevel@tonic-gate 			} else if ((sdp->sd_psyminfo != (Psym_info *)NULL) &&
8877c478bd9Sstevel@tonic-gate 			    (ofl->ofl_flags & FLG_OF_SHAROBJ) &&
8887c478bd9Sstevel@tonic-gate 			    (ELF_ST_BIND(symptr->st_info) != STB_LOCAL)) {
8897c478bd9Sstevel@tonic-gate 				restore = 1;
8907c478bd9Sstevel@tonic-gate 				sdp->sd_shndx = sunwbssndx;
8917c478bd9Sstevel@tonic-gate 				sdp->sd_flags &= ~FLG_SY_SPECSEC;
8927c478bd9Sstevel@tonic-gate 				symptr->st_value = (Xword)
8937c478bd9Sstevel@tonic-gate 					S_ROUND(sunwbssaddr, symptr->st_value);
8947c478bd9Sstevel@tonic-gate 				sunwbssaddr = symptr->st_value +
8957c478bd9Sstevel@tonic-gate 					symptr->st_size;
8967c478bd9Sstevel@tonic-gate 				sdp->sd_isc = ofl->ofl_issunwbss;
8977c478bd9Sstevel@tonic-gate 				sdp->sd_flags |= FLG_SY_COMMEXP;
898c1c6f601Srie 
8997c478bd9Sstevel@tonic-gate 			} else if (ELF_ST_TYPE(symptr->st_info) != STT_TLS &&
9007c478bd9Sstevel@tonic-gate 			    (local || !(flags & FLG_OF_RELOBJ))) {
9017c478bd9Sstevel@tonic-gate 				restore = 1;
9027c478bd9Sstevel@tonic-gate 				sdp->sd_shndx = bssndx;
9037c478bd9Sstevel@tonic-gate 				sdp->sd_flags &= ~FLG_SY_SPECSEC;
9047c478bd9Sstevel@tonic-gate 				symptr->st_value = (Xword) S_ROUND(bssaddr,
9057c478bd9Sstevel@tonic-gate 					symptr->st_value);
9067c478bd9Sstevel@tonic-gate 				bssaddr = symptr->st_value + symptr->st_size;
9077c478bd9Sstevel@tonic-gate 				sdp->sd_isc = ofl->ofl_isbss;
9087c478bd9Sstevel@tonic-gate 				sdp->sd_flags |= FLG_SY_COMMEXP;
909c1c6f601Srie 
9107c478bd9Sstevel@tonic-gate 			} else if (ELF_ST_TYPE(symptr->st_info) == STT_TLS &&
9117c478bd9Sstevel@tonic-gate 			    (local || !(flags & FLG_OF_RELOBJ))) {
9127c478bd9Sstevel@tonic-gate 				restore = 1;
9137c478bd9Sstevel@tonic-gate 				sdp->sd_shndx = tlsbssndx;
9147c478bd9Sstevel@tonic-gate 				sdp->sd_flags &= ~FLG_SY_SPECSEC;
9157c478bd9Sstevel@tonic-gate 				symptr->st_value = (Xword)S_ROUND(tlsbssaddr,
9167c478bd9Sstevel@tonic-gate 					symptr->st_value);
9177c478bd9Sstevel@tonic-gate 				tlsbssaddr = symptr->st_value + symptr->st_size;
9187c478bd9Sstevel@tonic-gate 				sdp->sd_isc = ofl->ofl_istlsbss;
9197c478bd9Sstevel@tonic-gate 				sdp->sd_flags |= FLG_SY_COMMEXP;
9207c478bd9Sstevel@tonic-gate 				/*
921dd94ecefSrie 				 * TLS symbols are relative to the TLS segment.
9227c478bd9Sstevel@tonic-gate 				 */
9237c478bd9Sstevel@tonic-gate 				symptr->st_value -= ofl->ofl_tlsphdr->p_vaddr;
9247c478bd9Sstevel@tonic-gate 			}
92554d82594Sseizo #if	(defined(__i386) || defined(__amd64)) && defined(_ELF64)
92654d82594Sseizo 		} else if ((sdp->sd_flags & FLG_SY_SPECSEC) &&
92754d82594Sseizo 		    ((sdp->sd_shndx = symptr->st_shndx) ==
92854d82594Sseizo 		    SHN_X86_64_LCOMMON) &&
92954d82594Sseizo 		    ((local || !(flags & FLG_OF_RELOBJ)))) {
93054d82594Sseizo 			restore = 1;
93154d82594Sseizo 			sdp->sd_shndx = lbssndx;
93254d82594Sseizo 			sdp->sd_flags &= ~FLG_SY_SPECSEC;
93354d82594Sseizo 			symptr->st_value = (Xword) S_ROUND(lbssaddr,
93454d82594Sseizo 				symptr->st_value);
93554d82594Sseizo 			lbssaddr = symptr->st_value + symptr->st_size;
93654d82594Sseizo 			sdp->sd_isc = ofl->ofl_islbss;
93754d82594Sseizo 			sdp->sd_flags |= FLG_SY_COMMEXP;
93854d82594Sseizo #endif
93954d82594Sseizo 		}
9407c478bd9Sstevel@tonic-gate 
94154d82594Sseizo 		if (restore != 0) {
942c1c6f601Srie 			unsigned char	type, bind;
943c1c6f601Srie 
94454d82594Sseizo 			/*
945c1c6f601Srie 			 * Make sure this COMMON symbol is returned to the same
946c1c6f601Srie 			 * binding as was defined in the original relocatable
94754d82594Sseizo 			 * object reference.
94854d82594Sseizo 			 */
94954d82594Sseizo 			type = ELF_ST_TYPE(symptr->st_info);
95054d82594Sseizo 			if (sdp->sd_flags & FLG_SY_GLOBREF)
95154d82594Sseizo 				bind = STB_GLOBAL;
95254d82594Sseizo 			else
95354d82594Sseizo 				bind = STB_WEAK;
9547c478bd9Sstevel@tonic-gate 
95554d82594Sseizo 			symptr->st_info = ELF_ST_INFO(bind, type);
9567c478bd9Sstevel@tonic-gate 		}
9577c478bd9Sstevel@tonic-gate 	}
9587c478bd9Sstevel@tonic-gate 
9597c478bd9Sstevel@tonic-gate 	if (ofl->ofl_hashbkts) {
9607c478bd9Sstevel@tonic-gate 		qsort(sorted_syms + ofl->ofl_scopecnt + ofl->ofl_elimcnt,
9617c478bd9Sstevel@tonic-gate 		    ofl->ofl_globcnt, sizeof (Sym_s_list),
9627c478bd9Sstevel@tonic-gate 		    (int (*)(const void *, const void *))sym_hash_compare);
9637c478bd9Sstevel@tonic-gate 	}
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	for (ssndx = 0; ssndx < (ofl->ofl_elimcnt + ofl->ofl_scopecnt +
9667c478bd9Sstevel@tonic-gate 	    ofl->ofl_globcnt); ssndx++) {
9677c478bd9Sstevel@tonic-gate 		const char	*name;
9687c478bd9Sstevel@tonic-gate 		Sym		*sym;
9697c478bd9Sstevel@tonic-gate 		Sym_aux		*sap;
9707c478bd9Sstevel@tonic-gate 		Half		spec;
971*9039eeafSab 		int		local = 0, dynlocal = 0, enter_in_symtab;
9727c478bd9Sstevel@tonic-gate 		Listnode	*lnp2;
9737c478bd9Sstevel@tonic-gate 		Gotndx		*gnp;
9747c478bd9Sstevel@tonic-gate 		Word		sectndx;
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 		sdp = sorted_syms[ssndx].sl_sdp;
9777c478bd9Sstevel@tonic-gate 		sectndx = 0;
9787c478bd9Sstevel@tonic-gate 
9797c478bd9Sstevel@tonic-gate 		if (symtab)
9807c478bd9Sstevel@tonic-gate 			enter_in_symtab = 1;
9817c478bd9Sstevel@tonic-gate 		else
9827c478bd9Sstevel@tonic-gate 			enter_in_symtab = 0;
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate 		/*
9857c478bd9Sstevel@tonic-gate 		 * Assign a got offset if necessary.
9867c478bd9Sstevel@tonic-gate 		 */
9875aefb655Srie #if	defined(sparc) || defined(__sparcv9)
9885aefb655Srie 		if (ld_assign_got(ofl, sdp) == S_ERROR)
9897c478bd9Sstevel@tonic-gate 			return ((Addr)S_ERROR);
9905aefb655Srie #elif	defined(i386) || defined(__amd64)
9917c478bd9Sstevel@tonic-gate /* nothing to do */
9927c478bd9Sstevel@tonic-gate #else
9937c478bd9Sstevel@tonic-gate #error Unknown architecture!
9947c478bd9Sstevel@tonic-gate #endif
995c1c6f601Srie 
9965aefb655Srie 		if (DBG_ENABLED) {
9977c478bd9Sstevel@tonic-gate 			for (LIST_TRAVERSE(&sdp->sd_GOTndxs, lnp2, gnp)) {
998d326b23bSrie 				gottable->gt_sym = sdp;
999d326b23bSrie 				gottable->gt_gndx.gn_gotndx = gnp->gn_gotndx;
1000d326b23bSrie 				gottable->gt_gndx.gn_addend = gnp->gn_addend;
1001d326b23bSrie 				gottable++;
10027c478bd9Sstevel@tonic-gate 			}
10037c478bd9Sstevel@tonic-gate 
10047c478bd9Sstevel@tonic-gate 			if (sdp->sd_aux && sdp->sd_aux->sa_PLTGOTndx) {
1005d326b23bSrie 				gottable->gt_sym = sdp;
1006d326b23bSrie 				gottable->gt_gndx.gn_gotndx =
10077c478bd9Sstevel@tonic-gate 				    sdp->sd_aux->sa_PLTGOTndx;
1008d326b23bSrie 				gottable++;
10097c478bd9Sstevel@tonic-gate 			}
10107c478bd9Sstevel@tonic-gate 		}
10117c478bd9Sstevel@tonic-gate 
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate 		/*
10147c478bd9Sstevel@tonic-gate 		 * If this symbol has been marked as being reduced to local
10157c478bd9Sstevel@tonic-gate 		 * scope then it will have to be placed in the scoped portion
10167c478bd9Sstevel@tonic-gate 		 * of the .symtab.  Retain the appropriate index for use in
10177c478bd9Sstevel@tonic-gate 		 * version symbol indexing and relocation.
10187c478bd9Sstevel@tonic-gate 		 */
10197c478bd9Sstevel@tonic-gate 		if ((sdp->sd_flags1 & FLG_SY1_LOCL) &&
10207c478bd9Sstevel@tonic-gate 		    (flags & FLG_OF_PROCRED)) {
10217c478bd9Sstevel@tonic-gate 			local = 1;
10227c478bd9Sstevel@tonic-gate 			if (!(sdp->sd_flags1 & FLG_SY1_ELIM) && !dynsym)
10237c478bd9Sstevel@tonic-gate 				sdp->sd_symndx = scopesym_ndx;
10247c478bd9Sstevel@tonic-gate 			else
10257c478bd9Sstevel@tonic-gate 				sdp->sd_symndx = 0;
10267c478bd9Sstevel@tonic-gate 
1027*9039eeafSab 			if (sdp->sd_flags1 & FLG_SY1_ELIM) {
10287c478bd9Sstevel@tonic-gate 				enter_in_symtab = 0;
1029*9039eeafSab 			} else if (ldynsym && sdp->sd_sym->st_name &&
1030*9039eeafSab 			    (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_FUNC)) {
1031*9039eeafSab 				dynlocal = 1;
1032*9039eeafSab 			}
1033*9039eeafSab 		} else {
10347c478bd9Sstevel@tonic-gate 			sdp->sd_symndx = *symndx;
1035*9039eeafSab 		}
10367c478bd9Sstevel@tonic-gate 
10377c478bd9Sstevel@tonic-gate 		/*
10387c478bd9Sstevel@tonic-gate 		 * Copy basic symbol and string information.
10397c478bd9Sstevel@tonic-gate 		 */
10407c478bd9Sstevel@tonic-gate 		name = sdp->sd_name;
10417c478bd9Sstevel@tonic-gate 		sap = sdp->sd_aux;
10427c478bd9Sstevel@tonic-gate 
10437c478bd9Sstevel@tonic-gate 		/*
10447c478bd9Sstevel@tonic-gate 		 * If we require to record version symbol indexes, update the
10457c478bd9Sstevel@tonic-gate 		 * associated version symbol information for all defined
10467c478bd9Sstevel@tonic-gate 		 * symbols.  If a version definition is required any zero value
10477c478bd9Sstevel@tonic-gate 		 * symbol indexes would have been flagged as undefined symbol
10487c478bd9Sstevel@tonic-gate 		 * errors, however if we're just scoping these need to fall into
10497c478bd9Sstevel@tonic-gate 		 * the base of global symbols.
10507c478bd9Sstevel@tonic-gate 		 */
10517c478bd9Sstevel@tonic-gate 		if (sdp->sd_symndx && versym) {
10527c478bd9Sstevel@tonic-gate 			Half	vndx = 0;
10537c478bd9Sstevel@tonic-gate 
10547c478bd9Sstevel@tonic-gate 			if (sdp->sd_flags & FLG_SY_MVTOCOMM)
10557c478bd9Sstevel@tonic-gate 				vndx = VER_NDX_GLOBAL;
10567c478bd9Sstevel@tonic-gate 			else if (sdp->sd_ref == REF_REL_NEED) {
10577c478bd9Sstevel@tonic-gate 				Half	symflags1 = sdp->sd_flags1;
10587c478bd9Sstevel@tonic-gate 
10597c478bd9Sstevel@tonic-gate 				vndx = sap->sa_overndx;
10607c478bd9Sstevel@tonic-gate 				if ((vndx == 0) &&
10617c478bd9Sstevel@tonic-gate 				    (sdp->sd_sym->st_shndx != SHN_UNDEF)) {
10627c478bd9Sstevel@tonic-gate 					if (symflags1 & FLG_SY1_ELIM)
10637c478bd9Sstevel@tonic-gate 						vndx = VER_NDX_ELIMINATE;
10647c478bd9Sstevel@tonic-gate 					else if (symflags1 & FLG_SY1_LOCL)
10657c478bd9Sstevel@tonic-gate 						vndx = VER_NDX_LOCAL;
10667c478bd9Sstevel@tonic-gate 					else
10677c478bd9Sstevel@tonic-gate 						vndx = VER_NDX_GLOBAL;
10687c478bd9Sstevel@tonic-gate 				}
10697c478bd9Sstevel@tonic-gate 			}
10707c478bd9Sstevel@tonic-gate 			versym[sdp->sd_symndx] = vndx;
10717c478bd9Sstevel@tonic-gate 		}
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate 		/*
10747c478bd9Sstevel@tonic-gate 		 * If we are creating the .syminfo section then set per symbol
10757c478bd9Sstevel@tonic-gate 		 * flags here.
10767c478bd9Sstevel@tonic-gate 		 */
10777c478bd9Sstevel@tonic-gate 		if (sdp->sd_symndx && syminfo &&
10787c478bd9Sstevel@tonic-gate 		    !(sdp->sd_flags & FLG_SY_NOTAVAIL)) {
10797c478bd9Sstevel@tonic-gate 			int	ndx = sdp->sd_symndx;
10807c478bd9Sstevel@tonic-gate 			List	*sip = &(ofl->ofl_syminfsyms);
10817c478bd9Sstevel@tonic-gate 
10827c478bd9Sstevel@tonic-gate 			if (sdp->sd_flags & FLG_SY_MVTOCOMM)
10837c478bd9Sstevel@tonic-gate 				/*
10847c478bd9Sstevel@tonic-gate 				 * Identify a copy relocation symbol.
10857c478bd9Sstevel@tonic-gate 				 */
10867c478bd9Sstevel@tonic-gate 				syminfo[ndx].si_flags |= SYMINFO_FLG_COPY;
10877c478bd9Sstevel@tonic-gate 
10887c478bd9Sstevel@tonic-gate 			if (sdp->sd_ref == REF_DYN_NEED) {
10897c478bd9Sstevel@tonic-gate 				/*
10907c478bd9Sstevel@tonic-gate 				 * A reference is bound to a needed dependency.
10917c478bd9Sstevel@tonic-gate 				 * Save this symbol descriptor, as its boundto
10927c478bd9Sstevel@tonic-gate 				 * element will need updating after the .dynamic
10937c478bd9Sstevel@tonic-gate 				 * section has been created.  Flag whether this
10947c478bd9Sstevel@tonic-gate 				 * reference is lazy loadable, and if a direct
10957c478bd9Sstevel@tonic-gate 				 * binding is to be established.
10967c478bd9Sstevel@tonic-gate 				 */
10977c478bd9Sstevel@tonic-gate 				if (list_appendc(sip, sdp) == 0)
10987c478bd9Sstevel@tonic-gate 					return (0);
10997c478bd9Sstevel@tonic-gate 
11007c478bd9Sstevel@tonic-gate 				syminfo[ndx].si_flags |= SYMINFO_FLG_DIRECT;
11017c478bd9Sstevel@tonic-gate 				if (sdp->sd_flags & FLG_SY_LAZYLD)
11027c478bd9Sstevel@tonic-gate 					syminfo[ndx].si_flags |=
11037c478bd9Sstevel@tonic-gate 					    SYMINFO_FLG_LAZYLOAD;
11047c478bd9Sstevel@tonic-gate 
11057c478bd9Sstevel@tonic-gate 				/*
11067c478bd9Sstevel@tonic-gate 				 * Enable direct symbol bindings if:
11077c478bd9Sstevel@tonic-gate 				 *
11087c478bd9Sstevel@tonic-gate 				 *  .	Symbol was identified with the DIRECT
11097c478bd9Sstevel@tonic-gate 				 *	keyword in a mapfile.
11107c478bd9Sstevel@tonic-gate 				 *
11117c478bd9Sstevel@tonic-gate 				 *  .	Symbol reference has been bound to a
11127c478bd9Sstevel@tonic-gate 				 * 	dependency which was specified as
11137c478bd9Sstevel@tonic-gate 				 *	requiring direct bindings with -zdirect.
11147c478bd9Sstevel@tonic-gate 				 *
11157c478bd9Sstevel@tonic-gate 				 *  .	All symbol references are required to
11167c478bd9Sstevel@tonic-gate 				 *	use direct bindings via -Bdirect.
11177c478bd9Sstevel@tonic-gate 				 */
11187c478bd9Sstevel@tonic-gate 				if (sdp->sd_flags1 & FLG_SY1_DIR)
11197c478bd9Sstevel@tonic-gate 					syminfo[ndx].si_flags |=
11207c478bd9Sstevel@tonic-gate 					    SYMINFO_FLG_DIRECTBIND;
11217c478bd9Sstevel@tonic-gate 
11227c478bd9Sstevel@tonic-gate 			} else if ((sdp->sd_flags & FLG_SY_EXTERN) &&
11237c478bd9Sstevel@tonic-gate 			    (sdp->sd_sym->st_shndx == SHN_UNDEF)) {
11247c478bd9Sstevel@tonic-gate 				/*
11257c478bd9Sstevel@tonic-gate 				 * If this symbol has been explicitly defined
11267c478bd9Sstevel@tonic-gate 				 * as external, and remains unresolved, mark
11277c478bd9Sstevel@tonic-gate 				 * it as external.
11287c478bd9Sstevel@tonic-gate 				 */
11297c478bd9Sstevel@tonic-gate 				syminfo[ndx].si_boundto = SYMINFO_BT_EXTERN;
11307c478bd9Sstevel@tonic-gate 
11317c478bd9Sstevel@tonic-gate 			} else if (sdp->sd_flags & FLG_SY_PARENT) {
11327c478bd9Sstevel@tonic-gate 				/*
11337c478bd9Sstevel@tonic-gate 				 * A reference to a parent object.  Indicate
11347c478bd9Sstevel@tonic-gate 				 * whether a direct binding should be
11357c478bd9Sstevel@tonic-gate 				 * established.
11367c478bd9Sstevel@tonic-gate 				 */
11377c478bd9Sstevel@tonic-gate 				syminfo[ndx].si_flags |= SYMINFO_FLG_DIRECT;
11387c478bd9Sstevel@tonic-gate 				syminfo[ndx].si_boundto = SYMINFO_BT_PARENT;
11397c478bd9Sstevel@tonic-gate 				if (sdp->sd_flags1 & FLG_SY1_DIR)
11407c478bd9Sstevel@tonic-gate 					syminfo[ndx].si_flags |=
11417c478bd9Sstevel@tonic-gate 					    SYMINFO_FLG_DIRECTBIND;
11427c478bd9Sstevel@tonic-gate 
11437c478bd9Sstevel@tonic-gate 			} else if (sdp->sd_flags & FLG_SY_STDFLTR) {
11447c478bd9Sstevel@tonic-gate 				/*
11457c478bd9Sstevel@tonic-gate 				 * A filter definition.  Although this symbol
11467c478bd9Sstevel@tonic-gate 				 * can only be a stub, it might be necessary to
11477c478bd9Sstevel@tonic-gate 				 * prevent external direct bindings.
11487c478bd9Sstevel@tonic-gate 				 */
11497c478bd9Sstevel@tonic-gate 				syminfo[ndx].si_flags |= SYMINFO_FLG_FILTER;
11507c478bd9Sstevel@tonic-gate 				if (sdp->sd_flags1 & FLG_SY1_NDIR)
11517c478bd9Sstevel@tonic-gate 					syminfo[ndx].si_flags |=
11527c478bd9Sstevel@tonic-gate 					    SYMINFO_FLG_NOEXTDIRECT;
11537c478bd9Sstevel@tonic-gate 
11547c478bd9Sstevel@tonic-gate 			} else if (sdp->sd_flags & FLG_SY_AUXFLTR) {
11557c478bd9Sstevel@tonic-gate 				/*
11567c478bd9Sstevel@tonic-gate 				 * An auxiliary filter definition.  By nature,
11577c478bd9Sstevel@tonic-gate 				 * this definition is direct, in that should the
11587c478bd9Sstevel@tonic-gate 				 * filtee lookup fail, we'll fall back to this
11597c478bd9Sstevel@tonic-gate 				 * object.  It may still be necesssary to
11607c478bd9Sstevel@tonic-gate 				 * prevent external direct bindings.
11617c478bd9Sstevel@tonic-gate 				 */
11627c478bd9Sstevel@tonic-gate 				syminfo[ndx].si_flags |= SYMINFO_FLG_AUXILIARY;
11637c478bd9Sstevel@tonic-gate 				if (sdp->sd_flags1 & FLG_SY1_NDIR)
11647c478bd9Sstevel@tonic-gate 					syminfo[ndx].si_flags |=
11657c478bd9Sstevel@tonic-gate 					    SYMINFO_FLG_NOEXTDIRECT;
11667c478bd9Sstevel@tonic-gate 
11677c478bd9Sstevel@tonic-gate 			} else if ((sdp->sd_ref == REF_REL_NEED) &&
11687c478bd9Sstevel@tonic-gate 			    (sdp->sd_sym->st_shndx != SHN_UNDEF)) {
11697c478bd9Sstevel@tonic-gate 				/*
11707c478bd9Sstevel@tonic-gate 				 * This definition exists within the object
11717c478bd9Sstevel@tonic-gate 				 * being created.  Flag whether it is necessary
11727c478bd9Sstevel@tonic-gate 				 * to prevent external direct bindings.
11737c478bd9Sstevel@tonic-gate 				 */
11747c478bd9Sstevel@tonic-gate 				if (sdp->sd_flags1 & FLG_SY1_NDIR) {
11757c478bd9Sstevel@tonic-gate 					syminfo[ndx].si_boundto =
11767c478bd9Sstevel@tonic-gate 					    SYMINFO_BT_NONE;
11777c478bd9Sstevel@tonic-gate 					syminfo[ndx].si_flags |=
11787c478bd9Sstevel@tonic-gate 					    SYMINFO_FLG_NOEXTDIRECT;
11797c478bd9Sstevel@tonic-gate 				}
11807c478bd9Sstevel@tonic-gate 
11817c478bd9Sstevel@tonic-gate 				/*
11827c478bd9Sstevel@tonic-gate 				 * If external bindings are allowed, or this is
11837c478bd9Sstevel@tonic-gate 				 * a translator symbol, indicate the binding,
11847c478bd9Sstevel@tonic-gate 				 * and a direct binding if necessary.
11857c478bd9Sstevel@tonic-gate 				 */
11867c478bd9Sstevel@tonic-gate 				if (((sdp->sd_flags1 & FLG_SY1_NDIR) == 0) ||
11877c478bd9Sstevel@tonic-gate 				    ((dtflags_1 & DF_1_TRANS) && sdp->sd_aux &&
11887c478bd9Sstevel@tonic-gate 				    sdp->sd_aux->sa_bindto)) {
11897c478bd9Sstevel@tonic-gate 
11907c478bd9Sstevel@tonic-gate 					syminfo[ndx].si_flags |=
11917c478bd9Sstevel@tonic-gate 					    SYMINFO_FLG_DIRECT;
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate 					if (sdp->sd_flags1 & FLG_SY1_DIR)
11947c478bd9Sstevel@tonic-gate 						syminfo[ndx].si_flags |=
11957c478bd9Sstevel@tonic-gate 						    SYMINFO_FLG_DIRECTBIND;
11967c478bd9Sstevel@tonic-gate 
11977c478bd9Sstevel@tonic-gate 					/*
11987c478bd9Sstevel@tonic-gate 					 * If this is a translator, the symbols
11997c478bd9Sstevel@tonic-gate 					 * boundto element will indicate the
12007c478bd9Sstevel@tonic-gate 					 * dependency to which it should resolve
12017c478bd9Sstevel@tonic-gate 					 * rather than itself.  Save this info
12027c478bd9Sstevel@tonic-gate 					 * for updating after the .dynamic
12037c478bd9Sstevel@tonic-gate 					 * section has been created.
12047c478bd9Sstevel@tonic-gate 					 */
12057c478bd9Sstevel@tonic-gate 					if ((dtflags_1 & DF_1_TRANS) &&
12067c478bd9Sstevel@tonic-gate 					    sdp->sd_aux &&
12077c478bd9Sstevel@tonic-gate 					    sdp->sd_aux->sa_bindto) {
12087c478bd9Sstevel@tonic-gate 						if (list_appendc(sip, sdp) == 0)
12097c478bd9Sstevel@tonic-gate 							return (0);
12107c478bd9Sstevel@tonic-gate 					} else {
12117c478bd9Sstevel@tonic-gate 						syminfo[ndx].si_boundto =
12127c478bd9Sstevel@tonic-gate 						    SYMINFO_BT_SELF;
12137c478bd9Sstevel@tonic-gate 					}
12147c478bd9Sstevel@tonic-gate 				}
12157c478bd9Sstevel@tonic-gate 			}
12167c478bd9Sstevel@tonic-gate 		}
12177c478bd9Sstevel@tonic-gate 
12187c478bd9Sstevel@tonic-gate 		/*
12197c478bd9Sstevel@tonic-gate 		 * Note that the `sym' value is reset to be one of the new
12207c478bd9Sstevel@tonic-gate 		 * symbol table entries.  This symbol will be updated further
12217c478bd9Sstevel@tonic-gate 		 * depending on the type of the symbol.  Process the .symtab
12227c478bd9Sstevel@tonic-gate 		 * first, followed by the .dynsym, thus the `sym' value will
12237c478bd9Sstevel@tonic-gate 		 * remain as the .dynsym value when the .dynsym is present.
1224c1c6f601Srie 		 * This ensures that any versioning symbols st_name value will
1225*9039eeafSab 		 * be appropriate for the string table used by version
12267c478bd9Sstevel@tonic-gate 		 * entries.
12277c478bd9Sstevel@tonic-gate 		 */
12287c478bd9Sstevel@tonic-gate 		if (enter_in_symtab) {
12297c478bd9Sstevel@tonic-gate 			Word	_symndx;
12307c478bd9Sstevel@tonic-gate 
12317c478bd9Sstevel@tonic-gate 			if (local)
12327c478bd9Sstevel@tonic-gate 				_symndx = scopesym_ndx;
12337c478bd9Sstevel@tonic-gate 			else
12347c478bd9Sstevel@tonic-gate 				_symndx = symtab_ndx;
1235*9039eeafSab 
12367c478bd9Sstevel@tonic-gate 			symtab[_symndx] = *sdp->sd_sym;
12377c478bd9Sstevel@tonic-gate 			sdp->sd_sym = sym = &symtab[_symndx];
12387c478bd9Sstevel@tonic-gate 			(void) st_setstring(strtab, name, &stoff);
12397c478bd9Sstevel@tonic-gate 			sym->st_name = stoff;
12407c478bd9Sstevel@tonic-gate 		}
1241*9039eeafSab 		if (dynlocal) {
1242*9039eeafSab 			ldynsym[ldynscopesym_ndx] = *sdp->sd_sym;
1243*9039eeafSab 			sdp->sd_sym = sym = &ldynsym[ldynscopesym_ndx];
1244*9039eeafSab 			(void) st_setstring(dynstr, name, &stoff);
1245*9039eeafSab 			ldynsym[ldynscopesym_ndx].st_name = stoff;
1246*9039eeafSab 		}
12477c478bd9Sstevel@tonic-gate 
12487c478bd9Sstevel@tonic-gate 		if (dynsym && !local) {
12497c478bd9Sstevel@tonic-gate 			dynsym[dynsym_ndx] = *sdp->sd_sym;
12507c478bd9Sstevel@tonic-gate 			/*
12517c478bd9Sstevel@tonic-gate 			 * Provided this isn't an unnamed register symbol,
12527c478bd9Sstevel@tonic-gate 			 * update its name and hash value.
12537c478bd9Sstevel@tonic-gate 			 */
12547c478bd9Sstevel@tonic-gate 			if (((sdp->sd_flags & FLG_SY_REGSYM) == 0) ||
12557c478bd9Sstevel@tonic-gate 			    dynsym[dynsym_ndx].st_name) {
1256*9039eeafSab 			    (void) st_setstring(dynstr, name, &stoff);
1257*9039eeafSab 			    dynsym[dynsym_ndx].st_name = stoff;
1258*9039eeafSab 			    if (stoff) {
1259*9039eeafSab 				Word _hashndx;
1260*9039eeafSab 				hashval = sap->sa_hash % ofl->ofl_hashbkts;
1261*9039eeafSab 				/* LINTED */
1262*9039eeafSab 				if (_hashndx = hashbkt[hashval]) {
1263*9039eeafSab 				    while (hashchain[_hashndx])
1264*9039eeafSab 					_hashndx = hashchain[_hashndx];
1265*9039eeafSab 					hashchain[_hashndx] = sdp->sd_symndx;
1266*9039eeafSab 				} else {
1267*9039eeafSab 					hashbkt[hashval] = sdp->sd_symndx;
12687c478bd9Sstevel@tonic-gate 				}
1269*9039eeafSab 			    }
12707c478bd9Sstevel@tonic-gate 			}
12717c478bd9Sstevel@tonic-gate 			sdp->sd_sym = sym = &dynsym[dynsym_ndx];
12727c478bd9Sstevel@tonic-gate 		}
1273*9039eeafSab 		if (!enter_in_symtab && (!dynsym || (local && !dynlocal))) {
12747c478bd9Sstevel@tonic-gate 			if (!(sdp->sd_flags & FLG_SY_UPREQD))
12757c478bd9Sstevel@tonic-gate 				continue;
12767c478bd9Sstevel@tonic-gate 			sym = sdp->sd_sym;
12777c478bd9Sstevel@tonic-gate 		} else
12787c478bd9Sstevel@tonic-gate 			sdp->sd_flags &= ~FLG_SY_CLEAN;
12797c478bd9Sstevel@tonic-gate 
12807c478bd9Sstevel@tonic-gate 
12817c478bd9Sstevel@tonic-gate 		/*
12827c478bd9Sstevel@tonic-gate 		 * If we have a weak data symbol for which we need the real
12837c478bd9Sstevel@tonic-gate 		 * symbol also, save this processing until later.
12847c478bd9Sstevel@tonic-gate 		 *
12857c478bd9Sstevel@tonic-gate 		 * The exception to this is if the weak/strong have PLT's
12867c478bd9Sstevel@tonic-gate 		 * assigned to them.  In that case we don't do the post-weak
12877c478bd9Sstevel@tonic-gate 		 * processing because the PLT's must be maintained so that we
12887c478bd9Sstevel@tonic-gate 		 * can do 'interpositioning' on both of the symbols.
12897c478bd9Sstevel@tonic-gate 		 */
12907c478bd9Sstevel@tonic-gate 		if ((sap->sa_linkndx) &&
12917c478bd9Sstevel@tonic-gate 		    (ELF_ST_BIND(sym->st_info) == STB_WEAK) &&
12927c478bd9Sstevel@tonic-gate 		    (!sap->sa_PLTndx)) {
12937c478bd9Sstevel@tonic-gate 			Sym_desc *	_sdp =
12947c478bd9Sstevel@tonic-gate 			    sdp->sd_file->ifl_oldndx[sap->sa_linkndx];
12957c478bd9Sstevel@tonic-gate 
12967c478bd9Sstevel@tonic-gate 			if (_sdp->sd_ref != REF_DYN_SEEN) {
12977c478bd9Sstevel@tonic-gate 				if ((wkp =
12987c478bd9Sstevel@tonic-gate 				    libld_calloc(sizeof (Wk_desc), 1)) == 0)
12997c478bd9Sstevel@tonic-gate 					return ((Addr)S_ERROR);
13007c478bd9Sstevel@tonic-gate 
1301*9039eeafSab 				if (enter_in_symtab) {
13027c478bd9Sstevel@tonic-gate 					if (local)
13037c478bd9Sstevel@tonic-gate 						wkp->wk_symtab =
13047c478bd9Sstevel@tonic-gate 						    &symtab[scopesym_ndx];
13057c478bd9Sstevel@tonic-gate 					else
13067c478bd9Sstevel@tonic-gate 						wkp->wk_symtab =
13077c478bd9Sstevel@tonic-gate 						    &symtab[symtab_ndx];
1308*9039eeafSab 				}
1309*9039eeafSab 				if (dynsym) {
1310*9039eeafSab 					if (!local) {
1311*9039eeafSab 						wkp->wk_dynsym =
1312*9039eeafSab 						    &dynsym[dynsym_ndx];
1313*9039eeafSab 					} else if (dynlocal) {
1314*9039eeafSab 						wkp->wk_dynsym =
1315*9039eeafSab 						    &ldynsym[ldynscopesym_ndx];
1316*9039eeafSab 					}
1317*9039eeafSab 				}
13187c478bd9Sstevel@tonic-gate 				wkp->wk_weak = sdp;
13197c478bd9Sstevel@tonic-gate 				wkp->wk_alias = _sdp;
13207c478bd9Sstevel@tonic-gate 
13217c478bd9Sstevel@tonic-gate 				if (!(list_appendc(&weak, wkp)))
13227c478bd9Sstevel@tonic-gate 					return ((Addr)S_ERROR);
13237c478bd9Sstevel@tonic-gate 
13247c478bd9Sstevel@tonic-gate 				if (enter_in_symtab)
13257c478bd9Sstevel@tonic-gate 					if (local)
13267c478bd9Sstevel@tonic-gate 						scopesym_ndx++;
13277c478bd9Sstevel@tonic-gate 					else
13287c478bd9Sstevel@tonic-gate 						symtab_ndx++;
1329*9039eeafSab 				if (dynsym) {
1330*9039eeafSab 					if (!local) {
1331*9039eeafSab 						dynsym_ndx++;
1332*9039eeafSab 					} else if (dynlocal) {
1333*9039eeafSab 						ldynscopesym_ndx++;
1334*9039eeafSab 					}
1335*9039eeafSab 				}
13367c478bd9Sstevel@tonic-gate 				continue;
13377c478bd9Sstevel@tonic-gate 			}
13387c478bd9Sstevel@tonic-gate 		}
13397c478bd9Sstevel@tonic-gate 
13405aefb655Srie 		DBG_CALL(Dbg_syms_old(ofl, sdp));
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate 		spec = NULL;
13437c478bd9Sstevel@tonic-gate 		/*
13447c478bd9Sstevel@tonic-gate 		 * assign new symbol value.
13457c478bd9Sstevel@tonic-gate 		 */
13467c478bd9Sstevel@tonic-gate 		sectndx = sdp->sd_shndx;
13477c478bd9Sstevel@tonic-gate 		if (sectndx == SHN_UNDEF) {
13487c478bd9Sstevel@tonic-gate 			if (((sdp->sd_flags & FLG_SY_REGSYM) == 0) &&
13497c478bd9Sstevel@tonic-gate 			    (sym->st_value != 0)) {
13505aefb655Srie 				eprintf(ofl->ofl_lml, ERR_WARNING,
13515aefb655Srie 				    MSG_INTL(MSG_SYM_NOTNULL),
13527c478bd9Sstevel@tonic-gate 				    demangle(name), sdp->sd_file->ifl_name);
13537c478bd9Sstevel@tonic-gate 			}
13547c478bd9Sstevel@tonic-gate 
13557c478bd9Sstevel@tonic-gate 			/*
13567c478bd9Sstevel@tonic-gate 			 * Undefined weak global, if we are generating a static
13577c478bd9Sstevel@tonic-gate 			 * executable, output as an absolute zero.  Otherwise
13587c478bd9Sstevel@tonic-gate 			 * leave it as is, ld.so.1 will skip symbols of this
13597c478bd9Sstevel@tonic-gate 			 * type (this technique allows applications and
13607c478bd9Sstevel@tonic-gate 			 * libraries to test for the existence of a symbol as an
13617c478bd9Sstevel@tonic-gate 			 * indication of the presence or absence of certain
13627c478bd9Sstevel@tonic-gate 			 * functionality).
13637c478bd9Sstevel@tonic-gate 			 */
13647c478bd9Sstevel@tonic-gate 			if (((flags & (FLG_OF_STATIC | FLG_OF_EXEC)) ==
13657c478bd9Sstevel@tonic-gate 			    (FLG_OF_STATIC | FLG_OF_EXEC)) &&
13667c478bd9Sstevel@tonic-gate 			    (ELF_ST_BIND(sym->st_info) == STB_WEAK)) {
13677c478bd9Sstevel@tonic-gate 				sdp->sd_flags |= FLG_SY_SPECSEC;
13687c478bd9Sstevel@tonic-gate 				sdp->sd_shndx = sectndx = SHN_ABS;
13697c478bd9Sstevel@tonic-gate 			}
13707c478bd9Sstevel@tonic-gate 		} else if ((sdp->sd_flags & FLG_SY_SPECSEC) &&
13717c478bd9Sstevel@tonic-gate 		    (sectndx == SHN_COMMON)) {
13727c478bd9Sstevel@tonic-gate 			/* COMMONs have already been processed */
13737c478bd9Sstevel@tonic-gate 			/* EMPTY */
13747c478bd9Sstevel@tonic-gate 			;
13757c478bd9Sstevel@tonic-gate 		} else {
13767c478bd9Sstevel@tonic-gate 			if ((sdp->sd_flags & FLG_SY_SPECSEC) &&
13777c478bd9Sstevel@tonic-gate 			    (sectndx == SHN_ABS))
13787c478bd9Sstevel@tonic-gate 				spec = sdp->sd_aux->sa_symspec;
13797c478bd9Sstevel@tonic-gate 
13807c478bd9Sstevel@tonic-gate 			/* LINTED */
13817c478bd9Sstevel@tonic-gate 			if (sdp->sd_flags & FLG_SY_COMMEXP) {
13827c478bd9Sstevel@tonic-gate 				/*
13837c478bd9Sstevel@tonic-gate 				 * This is (or was) a COMMON symbol which was
13847c478bd9Sstevel@tonic-gate 				 * processed above - no processing
13857c478bd9Sstevel@tonic-gate 				 * required here.
13867c478bd9Sstevel@tonic-gate 				 */
13877c478bd9Sstevel@tonic-gate 				;
13887c478bd9Sstevel@tonic-gate 			} else if (sdp->sd_ref == REF_DYN_NEED) {
13897c478bd9Sstevel@tonic-gate 				unsigned char	type, bind;
13907c478bd9Sstevel@tonic-gate 
13917c478bd9Sstevel@tonic-gate 				sectndx = SHN_UNDEF;
13927c478bd9Sstevel@tonic-gate 				sym->st_value = 0;
13937c478bd9Sstevel@tonic-gate 				sym->st_size = 0;
13947c478bd9Sstevel@tonic-gate 
13957c478bd9Sstevel@tonic-gate 				/*
13967c478bd9Sstevel@tonic-gate 				 * Make sure this undefined symbol is returned
13977c478bd9Sstevel@tonic-gate 				 * to the same binding as was defined in the
13987c478bd9Sstevel@tonic-gate 				 * original relocatable object reference.
13997c478bd9Sstevel@tonic-gate 				 */
14007c478bd9Sstevel@tonic-gate 				type = ELF_ST_TYPE(sym-> st_info);
14017c478bd9Sstevel@tonic-gate 				if (sdp->sd_flags & FLG_SY_GLOBREF)
14027c478bd9Sstevel@tonic-gate 					bind = STB_GLOBAL;
14037c478bd9Sstevel@tonic-gate 				else
14047c478bd9Sstevel@tonic-gate 					bind = STB_WEAK;
14057c478bd9Sstevel@tonic-gate 
14067c478bd9Sstevel@tonic-gate 				sym->st_info = ELF_ST_INFO(bind, type);
14077c478bd9Sstevel@tonic-gate 
14087c478bd9Sstevel@tonic-gate 			} else if (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) &&
14097c478bd9Sstevel@tonic-gate 			    (sdp->sd_ref == REF_REL_NEED)) {
14107c478bd9Sstevel@tonic-gate 				osp = sdp->sd_isc->is_osdesc;
14117c478bd9Sstevel@tonic-gate 				/* LINTED */
14127c478bd9Sstevel@tonic-gate 				sectndx = elf_ndxscn(osp->os_scn);
14137c478bd9Sstevel@tonic-gate 
14147c478bd9Sstevel@tonic-gate 				/*
14157c478bd9Sstevel@tonic-gate 				 * In an executable, the new symbol value is the
14167c478bd9Sstevel@tonic-gate 				 * old value (offset into defining section) plus
14177c478bd9Sstevel@tonic-gate 				 * virtual address of defining section.  In a
14187c478bd9Sstevel@tonic-gate 				 * relocatable, the new value is the old value
14197c478bd9Sstevel@tonic-gate 				 * plus the displacement of the section within
14207c478bd9Sstevel@tonic-gate 				 * the file.
14217c478bd9Sstevel@tonic-gate 				 */
14227c478bd9Sstevel@tonic-gate 				/* LINTED */
14237c478bd9Sstevel@tonic-gate 				sym->st_value +=
14247c478bd9Sstevel@tonic-gate 				    (Off)_elf_getxoff(sdp->sd_isc->is_indata);
14257c478bd9Sstevel@tonic-gate 
14267c478bd9Sstevel@tonic-gate 				if (!(flags & FLG_OF_RELOBJ)) {
14277c478bd9Sstevel@tonic-gate 					sym->st_value += osp->os_shdr->sh_addr;
14287c478bd9Sstevel@tonic-gate 					/*
14297c478bd9Sstevel@tonic-gate 					 * TLS symbols are relative to
14307c478bd9Sstevel@tonic-gate 					 * the TLS segment.
14317c478bd9Sstevel@tonic-gate 					 */
14327c478bd9Sstevel@tonic-gate 					if ((ELF_ST_TYPE(sym->st_info) ==
14337c478bd9Sstevel@tonic-gate 					    STT_TLS) && (ofl->ofl_tlsphdr))
14347c478bd9Sstevel@tonic-gate 						sym->st_value -=
14357c478bd9Sstevel@tonic-gate 						    ofl->ofl_tlsphdr->p_vaddr;
14367c478bd9Sstevel@tonic-gate 				}
14377c478bd9Sstevel@tonic-gate 			}
14387c478bd9Sstevel@tonic-gate 		}
14397c478bd9Sstevel@tonic-gate 
14407c478bd9Sstevel@tonic-gate 		if (spec) {
14417c478bd9Sstevel@tonic-gate 			switch (spec) {
14427c478bd9Sstevel@tonic-gate 			case SDAUX_ID_ETEXT:
14437c478bd9Sstevel@tonic-gate 				sym->st_value = etext;
14447c478bd9Sstevel@tonic-gate 				sectndx = etext_ndx;
14457c478bd9Sstevel@tonic-gate 				if (etext_abs)
14467c478bd9Sstevel@tonic-gate 					sdp->sd_flags |= FLG_SY_SPECSEC;
14477c478bd9Sstevel@tonic-gate 				else
14487c478bd9Sstevel@tonic-gate 					sdp->sd_flags &= ~FLG_SY_SPECSEC;
14497c478bd9Sstevel@tonic-gate 				break;
14507c478bd9Sstevel@tonic-gate 			case SDAUX_ID_EDATA:
14517c478bd9Sstevel@tonic-gate 				sym->st_value = edata;
14527c478bd9Sstevel@tonic-gate 				sectndx = edata_ndx;
14537c478bd9Sstevel@tonic-gate 				if (edata_abs)
14547c478bd9Sstevel@tonic-gate 					sdp->sd_flags |= FLG_SY_SPECSEC;
14557c478bd9Sstevel@tonic-gate 				else
14567c478bd9Sstevel@tonic-gate 					sdp->sd_flags &= ~FLG_SY_SPECSEC;
14577c478bd9Sstevel@tonic-gate 				break;
14587c478bd9Sstevel@tonic-gate 			case SDAUX_ID_END:
14597c478bd9Sstevel@tonic-gate 				sym->st_value = end;
14607c478bd9Sstevel@tonic-gate 				sectndx = end_ndx;
14617c478bd9Sstevel@tonic-gate 				if (end_abs)
14627c478bd9Sstevel@tonic-gate 					sdp->sd_flags |= FLG_SY_SPECSEC;
14637c478bd9Sstevel@tonic-gate 				else
14647c478bd9Sstevel@tonic-gate 					sdp->sd_flags &= ~FLG_SY_SPECSEC;
14657c478bd9Sstevel@tonic-gate 				break;
14667c478bd9Sstevel@tonic-gate 			case SDAUX_ID_START:
14677c478bd9Sstevel@tonic-gate 				sym->st_value = start;
14687c478bd9Sstevel@tonic-gate 				sectndx = start_ndx;
14697c478bd9Sstevel@tonic-gate 				sdp->sd_flags &= ~FLG_SY_SPECSEC;
14707c478bd9Sstevel@tonic-gate 				break;
14717c478bd9Sstevel@tonic-gate 			case SDAUX_ID_DYN:
14727c478bd9Sstevel@tonic-gate 				if (flags & FLG_OF_DYNAMIC) {
14737c478bd9Sstevel@tonic-gate 					sym->st_value = ofl->
14747c478bd9Sstevel@tonic-gate 					    ofl_osdynamic->os_shdr->sh_addr;
14757c478bd9Sstevel@tonic-gate 					/* LINTED */
14767c478bd9Sstevel@tonic-gate 					sectndx = elf_ndxscn(
14777c478bd9Sstevel@tonic-gate 					    ofl->ofl_osdynamic->os_scn);
14787c478bd9Sstevel@tonic-gate 					sdp->sd_flags &= ~FLG_SY_SPECSEC;
14797c478bd9Sstevel@tonic-gate 				}
14807c478bd9Sstevel@tonic-gate 				break;
14817c478bd9Sstevel@tonic-gate 			case SDAUX_ID_PLT:
14827c478bd9Sstevel@tonic-gate 				if (ofl->ofl_osplt) {
14837c478bd9Sstevel@tonic-gate 					sym->st_value = ofl->
14847c478bd9Sstevel@tonic-gate 					    ofl_osplt->os_shdr->sh_addr;
14857c478bd9Sstevel@tonic-gate 					/* LINTED */
14867c478bd9Sstevel@tonic-gate 					sectndx = elf_ndxscn(
14877c478bd9Sstevel@tonic-gate 					    ofl->ofl_osplt->os_scn);
14887c478bd9Sstevel@tonic-gate 					sdp->sd_flags &= ~FLG_SY_SPECSEC;
14897c478bd9Sstevel@tonic-gate 				}
14907c478bd9Sstevel@tonic-gate 				break;
14917c478bd9Sstevel@tonic-gate 			case SDAUX_ID_GOT:
14927c478bd9Sstevel@tonic-gate 				/*
14937c478bd9Sstevel@tonic-gate 				 * Symbol bias for negative growing tables is
14947c478bd9Sstevel@tonic-gate 				 * stored in symbol's value during
14957c478bd9Sstevel@tonic-gate 				 * allocate_got().
14967c478bd9Sstevel@tonic-gate 				 */
14977c478bd9Sstevel@tonic-gate 				sym->st_value += ofl->
14987c478bd9Sstevel@tonic-gate 				    ofl_osgot->os_shdr->sh_addr;
14997c478bd9Sstevel@tonic-gate 				/* LINTED */
15007c478bd9Sstevel@tonic-gate 				sectndx = elf_ndxscn(ofl->
15017c478bd9Sstevel@tonic-gate 				    ofl_osgot->os_scn);
15027c478bd9Sstevel@tonic-gate 				sdp->sd_flags &= ~FLG_SY_SPECSEC;
15037c478bd9Sstevel@tonic-gate 				break;
15047c478bd9Sstevel@tonic-gate 			default:
15057c478bd9Sstevel@tonic-gate 				/* NOTHING */
15067c478bd9Sstevel@tonic-gate 				;
15077c478bd9Sstevel@tonic-gate 			}
15087c478bd9Sstevel@tonic-gate 		}
15097c478bd9Sstevel@tonic-gate 
15107c478bd9Sstevel@tonic-gate 		/*
15117c478bd9Sstevel@tonic-gate 		 * If a plt index has been assigned to an undefined function,
15127c478bd9Sstevel@tonic-gate 		 * update the symbols value to the appropriate .plt address.
15137c478bd9Sstevel@tonic-gate 		 */
15147c478bd9Sstevel@tonic-gate 		if ((flags & FLG_OF_DYNAMIC) && (flags & FLG_OF_EXEC) &&
15157c478bd9Sstevel@tonic-gate 		    (sdp->sd_file) &&
15167c478bd9Sstevel@tonic-gate 		    (sdp->sd_file->ifl_ehdr->e_type == ET_DYN) &&
15177c478bd9Sstevel@tonic-gate 		    (ELF_ST_TYPE(sym->st_info) == STT_FUNC) &&
15187c478bd9Sstevel@tonic-gate 		    !(flags & FLG_OF_BFLAG)) {
15197c478bd9Sstevel@tonic-gate 			if (sap->sa_PLTndx)
15205aefb655Srie 				sym->st_value = ld_calc_plt_addr(sdp, ofl);
15217c478bd9Sstevel@tonic-gate 		}
15227c478bd9Sstevel@tonic-gate 
15237c478bd9Sstevel@tonic-gate 		/*
15247c478bd9Sstevel@tonic-gate 		 * Finish updating the symbols.
15257c478bd9Sstevel@tonic-gate 		 */
15267c478bd9Sstevel@tonic-gate 
15277c478bd9Sstevel@tonic-gate 		/*
15287c478bd9Sstevel@tonic-gate 		 * Sym Update: if scoped local - set local binding
15297c478bd9Sstevel@tonic-gate 		 */
15307c478bd9Sstevel@tonic-gate 		if (local)
15317c478bd9Sstevel@tonic-gate 			sym->st_info = ELF_ST_INFO(STB_LOCAL,
15327c478bd9Sstevel@tonic-gate 			    ELF_ST_TYPE(sym->st_info));
15337c478bd9Sstevel@tonic-gate 
15347c478bd9Sstevel@tonic-gate 		/*
15357c478bd9Sstevel@tonic-gate 		 * Sym Updated: If both the .symtab and .dynsym
15367c478bd9Sstevel@tonic-gate 		 * are present then we've actually updated the information in
15377c478bd9Sstevel@tonic-gate 		 * the .dynsym, therefore copy this same information to the
15387c478bd9Sstevel@tonic-gate 		 * .symtab entry.
15397c478bd9Sstevel@tonic-gate 		 */
15407c478bd9Sstevel@tonic-gate 		sdp->sd_shndx = sectndx;
1541*9039eeafSab 		if (enter_in_symtab && dynsym && (!local || dynlocal)) {
1542*9039eeafSab 			Word _symndx = dynlocal ? scopesym_ndx : symtab_ndx;
1543*9039eeafSab 
1544*9039eeafSab 			symtab[_symndx].st_value = sym->st_value;
1545*9039eeafSab 			symtab[_symndx].st_size = sym->st_size;
1546*9039eeafSab 			symtab[_symndx].st_info = sym->st_info;
1547*9039eeafSab 			symtab[_symndx].st_other = sym->st_other;
15487c478bd9Sstevel@tonic-gate 		}
15497c478bd9Sstevel@tonic-gate 
15507c478bd9Sstevel@tonic-gate 
15517c478bd9Sstevel@tonic-gate 		if (enter_in_symtab) {
15527c478bd9Sstevel@tonic-gate 			Word	_symndx;
15537c478bd9Sstevel@tonic-gate 
15547c478bd9Sstevel@tonic-gate 			if (local)
15557c478bd9Sstevel@tonic-gate 				_symndx = scopesym_ndx++;
15567c478bd9Sstevel@tonic-gate 			else
15577c478bd9Sstevel@tonic-gate 				_symndx = symtab_ndx++;
15587c478bd9Sstevel@tonic-gate 			if (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) &&
15597c478bd9Sstevel@tonic-gate 			    (sectndx >= SHN_LORESERVE)) {
15607c478bd9Sstevel@tonic-gate 				assert(symshndx != 0);
15617c478bd9Sstevel@tonic-gate 				symshndx[_symndx] = sectndx;
15627c478bd9Sstevel@tonic-gate 				symtab[_symndx].st_shndx = SHN_XINDEX;
15637c478bd9Sstevel@tonic-gate 			} else {
15647c478bd9Sstevel@tonic-gate 				/* LINTED */
15657c478bd9Sstevel@tonic-gate 				symtab[_symndx].st_shndx = (Half)sectndx;
15667c478bd9Sstevel@tonic-gate 			}
15677c478bd9Sstevel@tonic-gate 		}
15687c478bd9Sstevel@tonic-gate 
1569*9039eeafSab 		if (dynsym && (!local || dynlocal)) {
1570*9039eeafSab 			/*
1571*9039eeafSab 			 * dynsym and ldynsym are distinct tables, so
1572*9039eeafSab 			 * we use indirection to access the right one
1573*9039eeafSab 			 * and the related extended section index array.
1574*9039eeafSab 			 */
1575*9039eeafSab 			Word	_symndx;
1576*9039eeafSab 			Sym	*_dynsym;
1577*9039eeafSab 			Word	*_dynshndx;
1578*9039eeafSab 
1579*9039eeafSab 			if (!local) {
1580*9039eeafSab 				_symndx = dynsym_ndx++;
1581*9039eeafSab 				_dynsym = dynsym;
1582*9039eeafSab 				_dynshndx = dynshndx;
1583*9039eeafSab 			} else {
1584*9039eeafSab 				_symndx = ldynscopesym_ndx++;
1585*9039eeafSab 				_dynsym = ldynsym;
1586*9039eeafSab 				_dynshndx = ldynshndx;
1587*9039eeafSab 			}
15887c478bd9Sstevel@tonic-gate 			if (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) &&
15897c478bd9Sstevel@tonic-gate 			    (sectndx >= SHN_LORESERVE)) {
1590*9039eeafSab 				assert(_dynshndx != 0);
1591*9039eeafSab 				_dynshndx[_symndx] = sectndx;
1592*9039eeafSab 				_dynsym[_symndx].st_shndx = SHN_XINDEX;
15937c478bd9Sstevel@tonic-gate 			} else {
15947c478bd9Sstevel@tonic-gate 				/* LINTED */
1595*9039eeafSab 				_dynsym[_symndx].st_shndx = (Half)sectndx;
15967c478bd9Sstevel@tonic-gate 			}
15977c478bd9Sstevel@tonic-gate 		}
15987c478bd9Sstevel@tonic-gate 
15995aefb655Srie 		DBG_CALL(Dbg_syms_new(ofl, sym, sdp));
16007c478bd9Sstevel@tonic-gate 	}
16017c478bd9Sstevel@tonic-gate 
16027c478bd9Sstevel@tonic-gate 	/*
16037c478bd9Sstevel@tonic-gate 	 * Now that all the symbols have been processed update any weak symbols
16047c478bd9Sstevel@tonic-gate 	 * information (ie. copy all information except `st_name').  As both
16057c478bd9Sstevel@tonic-gate 	 * symbols will be represented in the output, return the weak symbol to
16067c478bd9Sstevel@tonic-gate 	 * its correct type.
16077c478bd9Sstevel@tonic-gate 	 */
16087c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&weak, lnp1, wkp)) {
16097c478bd9Sstevel@tonic-gate 		Sym_desc *	sdp, * _sdp;
16107c478bd9Sstevel@tonic-gate 		Sym *		sym, * _sym, * __sym;
16117c478bd9Sstevel@tonic-gate 		unsigned char	bind;
16127c478bd9Sstevel@tonic-gate 
16137c478bd9Sstevel@tonic-gate 		sdp = wkp->wk_weak;
16147c478bd9Sstevel@tonic-gate 		_sdp = wkp->wk_alias;
16157c478bd9Sstevel@tonic-gate 		_sym = _sdp->sd_sym;
16167c478bd9Sstevel@tonic-gate 
16177c478bd9Sstevel@tonic-gate 		sdp->sd_flags |= FLG_SY_WEAKDEF;
16187c478bd9Sstevel@tonic-gate 
16197c478bd9Sstevel@tonic-gate 		/*
16207c478bd9Sstevel@tonic-gate 		 * If the symbol definition has been scoped then assign it to
16217c478bd9Sstevel@tonic-gate 		 * be local, otherwise if it's from a shared object then we need
16227c478bd9Sstevel@tonic-gate 		 * to maintain the binding of the original reference.
16237c478bd9Sstevel@tonic-gate 		 */
16247c478bd9Sstevel@tonic-gate 		if (sdp->sd_flags1 & FLG_SY1_LOCL) {
16257c478bd9Sstevel@tonic-gate 			if (flags & FLG_OF_PROCRED)
16267c478bd9Sstevel@tonic-gate 				bind = STB_LOCAL;
16277c478bd9Sstevel@tonic-gate 			else
16287c478bd9Sstevel@tonic-gate 				bind = STB_WEAK;
16297c478bd9Sstevel@tonic-gate 		} else if ((sdp->sd_ref == REF_DYN_NEED) &&
16307c478bd9Sstevel@tonic-gate 		    (sdp->sd_flags & FLG_SY_GLOBREF))
16317c478bd9Sstevel@tonic-gate 			bind = STB_GLOBAL;
16327c478bd9Sstevel@tonic-gate 		else
16337c478bd9Sstevel@tonic-gate 			bind = STB_WEAK;
16347c478bd9Sstevel@tonic-gate 
16355aefb655Srie 		DBG_CALL(Dbg_syms_old(ofl, sdp));
16367c478bd9Sstevel@tonic-gate 		if ((sym = wkp->wk_symtab) != 0) {
16377c478bd9Sstevel@tonic-gate 			sym = wkp->wk_symtab;
16387c478bd9Sstevel@tonic-gate 			sym->st_value = _sym->st_value;
16397c478bd9Sstevel@tonic-gate 			sym->st_size = _sym->st_size;
16407c478bd9Sstevel@tonic-gate 			sym->st_other = _sym->st_other;
16417c478bd9Sstevel@tonic-gate 			sym->st_shndx = _sym->st_shndx;
16427c478bd9Sstevel@tonic-gate 			sym->st_info = ELF_ST_INFO(bind,
16437c478bd9Sstevel@tonic-gate 			    ELF_ST_TYPE(sym->st_info));
16447c478bd9Sstevel@tonic-gate 			__sym = sym;
16457c478bd9Sstevel@tonic-gate 		}
16467c478bd9Sstevel@tonic-gate 		if ((sym = wkp->wk_dynsym) != 0) {
16477c478bd9Sstevel@tonic-gate 			sym = wkp->wk_dynsym;
16487c478bd9Sstevel@tonic-gate 			sym->st_value = _sym->st_value;
16497c478bd9Sstevel@tonic-gate 			sym->st_size = _sym->st_size;
16507c478bd9Sstevel@tonic-gate 			sym->st_other = _sym->st_other;
16517c478bd9Sstevel@tonic-gate 			sym->st_shndx = _sym->st_shndx;
16527c478bd9Sstevel@tonic-gate 			sym->st_info = ELF_ST_INFO(bind,
16537c478bd9Sstevel@tonic-gate 			    ELF_ST_TYPE(sym->st_info));
16547c478bd9Sstevel@tonic-gate 			__sym = sym;
16557c478bd9Sstevel@tonic-gate 		}
16565aefb655Srie 		DBG_CALL(Dbg_syms_new(ofl, __sym, sdp));
16577c478bd9Sstevel@tonic-gate 	}
16587c478bd9Sstevel@tonic-gate 
16597c478bd9Sstevel@tonic-gate 	/*
16605aefb655Srie 	 * Now display GOT debugging information if required.
16617c478bd9Sstevel@tonic-gate 	 */
1662d326b23bSrie 	DBG_CALL(Dbg_got_display(ofl, 0, 0));
16637c478bd9Sstevel@tonic-gate 
16647c478bd9Sstevel@tonic-gate 	/*
1665*9039eeafSab 	 * Update the section headers information. sh_info is
1666*9039eeafSab 	 * supposed to contain the offset at which the first
1667*9039eeafSab 	 * global symbol resides in the symbol table, while
1668*9039eeafSab 	 * sh_link contains the section index of the associated
1669*9039eeafSab 	 * string table.
16707c478bd9Sstevel@tonic-gate 	 */
16717c478bd9Sstevel@tonic-gate 	if (symtab) {
16727c478bd9Sstevel@tonic-gate 		Shdr *	shdr = ofl->ofl_ossymtab->os_shdr;
16737c478bd9Sstevel@tonic-gate 
16747c478bd9Sstevel@tonic-gate 		shdr->sh_info = ofl->ofl_shdrcnt + ofl->ofl_locscnt +
16757c478bd9Sstevel@tonic-gate 			ofl->ofl_scopecnt + 2;
16767c478bd9Sstevel@tonic-gate 		/* LINTED */
16777c478bd9Sstevel@tonic-gate 		shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_osstrtab->os_scn);
16787c478bd9Sstevel@tonic-gate 		if (symshndx) {
16797c478bd9Sstevel@tonic-gate 			shdr = ofl->ofl_ossymshndx->os_shdr;
16807c478bd9Sstevel@tonic-gate 			shdr->sh_link =
16817c478bd9Sstevel@tonic-gate 				(Word)elf_ndxscn(ofl->ofl_ossymtab->os_scn);
16827c478bd9Sstevel@tonic-gate 		}
16837c478bd9Sstevel@tonic-gate 	}
16847c478bd9Sstevel@tonic-gate 	if (dynsym) {
16857c478bd9Sstevel@tonic-gate 		Shdr *	shdr = ofl->ofl_osdynsym->os_shdr;
16867c478bd9Sstevel@tonic-gate 
1687*9039eeafSab 		shdr->sh_info = 1 + ofl->ofl_dynshdrcnt + ofl->ofl_lregsymcnt;
16887c478bd9Sstevel@tonic-gate 		/* LINTED */
16897c478bd9Sstevel@tonic-gate 		shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn);
16907c478bd9Sstevel@tonic-gate 
16917c478bd9Sstevel@tonic-gate 		ofl->ofl_oshash->os_shdr->sh_link =
16927c478bd9Sstevel@tonic-gate 		    /* LINTED */
16937c478bd9Sstevel@tonic-gate 		    (Word)elf_ndxscn(ofl->ofl_osdynsym->os_scn);
16947c478bd9Sstevel@tonic-gate 		if (dynshndx) {
16957c478bd9Sstevel@tonic-gate 			shdr = ofl->ofl_osdynshndx->os_shdr;
16967c478bd9Sstevel@tonic-gate 			shdr->sh_link =
16977c478bd9Sstevel@tonic-gate 				(Word)elf_ndxscn(ofl->ofl_osdynsym->os_scn);
16987c478bd9Sstevel@tonic-gate 		}
16997c478bd9Sstevel@tonic-gate 	}
1700*9039eeafSab 	if (ldynsym) {
1701*9039eeafSab 		Shdr *	shdr = ofl->ofl_osldynsym->os_shdr;
1702*9039eeafSab 
1703*9039eeafSab 		/* ldynsym has no globals, so give index one past the end */
1704*9039eeafSab 		shdr->sh_info = ldynsym_ndx;
1705*9039eeafSab 
1706*9039eeafSab 		/*
1707*9039eeafSab 		 * The ldynsym and dynsym must be adjacent. The
1708*9039eeafSab 		 * idea is that rtld should be able to start with
1709*9039eeafSab 		 * the ldynsym and march straight through the end
1710*9039eeafSab 		 * of dynsym, seeing them as a single symbol table,
1711*9039eeafSab 		 * despite the fact that they are in distinct sections.
1712*9039eeafSab 		 * Ensure that this happened correctly.
1713*9039eeafSab 		 *
1714*9039eeafSab 		 * Note that I use ldynsym_ndx here instead of the
1715*9039eeafSab 		 * computation I used to set the section size
1716*9039eeafSab 		 * (1 + ofl->ofl_dynlocscnt + ofl->ofl_dynscopecnt).
1717*9039eeafSab 		 * The two will agree, unless we somehow miscounted symbols
1718*9039eeafSab 		 * or failed to insert them all. Using ldynsym_ndx here
1719*9039eeafSab 		 * catches that error in addition to checking for adjacency.
1720*9039eeafSab 		 */
1721*9039eeafSab 		assert(dynsym == (ldynsym + ldynsym_ndx));
1722*9039eeafSab 
1723*9039eeafSab 
1724*9039eeafSab 		/* LINTED */
1725*9039eeafSab 		shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn);
1726*9039eeafSab 
1727*9039eeafSab 		if (ldynshndx) {
1728*9039eeafSab 			shdr = ofl->ofl_osldynshndx->os_shdr;
1729*9039eeafSab 			shdr->sh_link =
1730*9039eeafSab 				(Word)elf_ndxscn(ofl->ofl_osldynsym->os_scn);
1731*9039eeafSab 		}
1732*9039eeafSab 	}
17337c478bd9Sstevel@tonic-gate 
17347c478bd9Sstevel@tonic-gate 	/*
17357c478bd9Sstevel@tonic-gate 	 * Used by ld.so.1 only.
17367c478bd9Sstevel@tonic-gate 	 */
17377c478bd9Sstevel@tonic-gate 	return (etext);
17387c478bd9Sstevel@tonic-gate }
17397c478bd9Sstevel@tonic-gate 
17407c478bd9Sstevel@tonic-gate /*
17417c478bd9Sstevel@tonic-gate  * Build the dynamic section.
17427c478bd9Sstevel@tonic-gate  */
17435aefb655Srie static int
17447c478bd9Sstevel@tonic-gate update_odynamic(Ofl_desc *ofl)
17457c478bd9Sstevel@tonic-gate {
17467c478bd9Sstevel@tonic-gate 	Listnode	*lnp;
17477c478bd9Sstevel@tonic-gate 	Ifl_desc	*ifl;
17487c478bd9Sstevel@tonic-gate 	Sym_desc	*sdp;
17497c478bd9Sstevel@tonic-gate 	Shdr		*shdr;
17507c478bd9Sstevel@tonic-gate 	Dyn		*_dyn = (Dyn *)ofl->ofl_osdynamic->os_outdata->d_buf;
17517c478bd9Sstevel@tonic-gate 	Dyn		*dyn;
17527c478bd9Sstevel@tonic-gate 	Str_tbl		*dynstr;
17537c478bd9Sstevel@tonic-gate 	uint_t		stoff;
17547c478bd9Sstevel@tonic-gate 	Word		flags = ofl->ofl_flags;
17557c478bd9Sstevel@tonic-gate 
17567c478bd9Sstevel@tonic-gate 	dynstr = ofl->ofl_dynstrtab;
17577c478bd9Sstevel@tonic-gate 	ofl->ofl_osdynamic->os_shdr->sh_link =
17587c478bd9Sstevel@tonic-gate 	    /* LINTED */
17597c478bd9Sstevel@tonic-gate 	    (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn);
17607c478bd9Sstevel@tonic-gate 
17617c478bd9Sstevel@tonic-gate 	dyn = _dyn;
17627c478bd9Sstevel@tonic-gate 
17637c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_sos, lnp, ifl)) {
17647c478bd9Sstevel@tonic-gate 		if ((ifl->ifl_flags &
17657c478bd9Sstevel@tonic-gate 		    (FLG_IF_IGNORE | FLG_IF_DEPREQD)) == FLG_IF_IGNORE)
17667c478bd9Sstevel@tonic-gate 			continue;
17677c478bd9Sstevel@tonic-gate 
17687c478bd9Sstevel@tonic-gate 		/*
17697c478bd9Sstevel@tonic-gate 		 * Create and set up the DT_POSFLAG_1 entry here if required.
17707c478bd9Sstevel@tonic-gate 		 */
17717c478bd9Sstevel@tonic-gate 		if ((ifl->ifl_flags & (FLG_IF_LAZYLD|FLG_IF_GRPPRM)) &&
17727c478bd9Sstevel@tonic-gate 		    (ifl->ifl_flags & (FLG_IF_NEEDED))) {
17737c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_POSFLAG_1;
17747c478bd9Sstevel@tonic-gate 			if (ifl->ifl_flags & FLG_IF_LAZYLD)
17757c478bd9Sstevel@tonic-gate 				dyn->d_un.d_val = DF_P1_LAZYLOAD;
17767c478bd9Sstevel@tonic-gate 			if (ifl->ifl_flags & FLG_IF_GRPPRM)
17777c478bd9Sstevel@tonic-gate 				dyn->d_un.d_val |= DF_P1_GROUPPERM;
17787c478bd9Sstevel@tonic-gate 			dyn++;
17797c478bd9Sstevel@tonic-gate 		}
17807c478bd9Sstevel@tonic-gate 
17817c478bd9Sstevel@tonic-gate 		if (ifl->ifl_flags & (FLG_IF_NEEDED | FLG_IF_NEEDSTR))
17827c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_NEEDED;
17837c478bd9Sstevel@tonic-gate 		else
17847c478bd9Sstevel@tonic-gate 			continue;
17857c478bd9Sstevel@tonic-gate 
17867c478bd9Sstevel@tonic-gate 		(void) st_setstring(dynstr, ifl->ifl_soname, &stoff);
17877c478bd9Sstevel@tonic-gate 		dyn->d_un.d_val = stoff;
17887c478bd9Sstevel@tonic-gate 		/* LINTED */
17897c478bd9Sstevel@tonic-gate 		ifl->ifl_neededndx = (Half)(((uintptr_t)dyn - (uintptr_t)_dyn) /
17907c478bd9Sstevel@tonic-gate 		    sizeof (Dyn));
17917c478bd9Sstevel@tonic-gate 		dyn++;
17927c478bd9Sstevel@tonic-gate 	}
17937c478bd9Sstevel@tonic-gate 
17947c478bd9Sstevel@tonic-gate 	if (ofl->ofl_dtsfltrs) {
17957c478bd9Sstevel@tonic-gate 		Dfltr_desc *	dftp;
17967c478bd9Sstevel@tonic-gate 		Aliste		off;
17977c478bd9Sstevel@tonic-gate 
17987c478bd9Sstevel@tonic-gate 		for (ALIST_TRAVERSE(ofl->ofl_dtsfltrs, off, dftp)) {
17997c478bd9Sstevel@tonic-gate 			if (dftp->dft_flag == FLG_SY_AUXFLTR)
18007c478bd9Sstevel@tonic-gate 				dyn->d_tag = DT_SUNW_AUXILIARY;
18017c478bd9Sstevel@tonic-gate 			else
18027c478bd9Sstevel@tonic-gate 				dyn->d_tag = DT_SUNW_FILTER;
18037c478bd9Sstevel@tonic-gate 
18047c478bd9Sstevel@tonic-gate 			(void) st_setstring(dynstr, dftp->dft_str, &stoff);
18057c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = stoff;
18067c478bd9Sstevel@tonic-gate 			dftp->dft_ndx = (Half)(((uintptr_t)dyn -
18077c478bd9Sstevel@tonic-gate 			    (uintptr_t)_dyn) / sizeof (Dyn));
18087c478bd9Sstevel@tonic-gate 			dyn++;
18097c478bd9Sstevel@tonic-gate 		}
18107c478bd9Sstevel@tonic-gate 	}
18115aefb655Srie 	if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_INIT_U),
18127c478bd9Sstevel@tonic-gate 	    SYM_NOHASH, 0, ofl)) != NULL) &&
18137c478bd9Sstevel@tonic-gate 		sdp->sd_ref == REF_REL_NEED) {
18147c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_INIT;
18157c478bd9Sstevel@tonic-gate 		dyn->d_un.d_ptr = sdp->sd_sym->st_value;
18167c478bd9Sstevel@tonic-gate 		dyn++;
18177c478bd9Sstevel@tonic-gate 	}
18185aefb655Srie 	if (((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_FINI_U),
18197c478bd9Sstevel@tonic-gate 	    SYM_NOHASH, 0, ofl)) != NULL) &&
18207c478bd9Sstevel@tonic-gate 		sdp->sd_ref == REF_REL_NEED) {
18217c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_FINI;
18227c478bd9Sstevel@tonic-gate 		dyn->d_un.d_ptr = sdp->sd_sym->st_value;
18237c478bd9Sstevel@tonic-gate 		dyn++;
18247c478bd9Sstevel@tonic-gate 	}
18257c478bd9Sstevel@tonic-gate 	if (ofl->ofl_soname) {
18267c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_SONAME;
18277c478bd9Sstevel@tonic-gate 		(void) st_setstring(dynstr, ofl->ofl_soname, &stoff);
18287c478bd9Sstevel@tonic-gate 		dyn->d_un.d_val = stoff;
18297c478bd9Sstevel@tonic-gate 		dyn++;
18307c478bd9Sstevel@tonic-gate 	}
18317c478bd9Sstevel@tonic-gate 	if (ofl->ofl_filtees) {
18327c478bd9Sstevel@tonic-gate 		if (flags & FLG_OF_AUX) {
18337c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_AUXILIARY;
18347c478bd9Sstevel@tonic-gate 		} else {
18357c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_FILTER;
18367c478bd9Sstevel@tonic-gate 		}
18377c478bd9Sstevel@tonic-gate 		(void) st_setstring(dynstr, ofl->ofl_filtees, &stoff);
18387c478bd9Sstevel@tonic-gate 		dyn->d_un.d_val = stoff;
18397c478bd9Sstevel@tonic-gate 		dyn++;
18407c478bd9Sstevel@tonic-gate 	}
18417c478bd9Sstevel@tonic-gate 	if (ofl->ofl_rpath) {
18427c478bd9Sstevel@tonic-gate 		(void) st_setstring(dynstr, ofl->ofl_rpath, &stoff);
18437c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_RUNPATH;
18447c478bd9Sstevel@tonic-gate 		dyn->d_un.d_val = stoff;
18457c478bd9Sstevel@tonic-gate 		dyn++;
18467c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_RPATH;
18477c478bd9Sstevel@tonic-gate 		dyn->d_un.d_val = stoff;
18487c478bd9Sstevel@tonic-gate 		dyn++;
18497c478bd9Sstevel@tonic-gate 	}
18507c478bd9Sstevel@tonic-gate 	if (ofl->ofl_config) {
18517c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_CONFIG;
18527c478bd9Sstevel@tonic-gate 		(void) st_setstring(dynstr, ofl->ofl_config, &stoff);
18537c478bd9Sstevel@tonic-gate 		dyn->d_un.d_val = stoff;
18547c478bd9Sstevel@tonic-gate 		dyn++;
18557c478bd9Sstevel@tonic-gate 	}
18567c478bd9Sstevel@tonic-gate 	if (ofl->ofl_depaudit) {
18577c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_DEPAUDIT;
18587c478bd9Sstevel@tonic-gate 		(void) st_setstring(dynstr, ofl->ofl_depaudit, &stoff);
18597c478bd9Sstevel@tonic-gate 		dyn->d_un.d_val = stoff;
18607c478bd9Sstevel@tonic-gate 		dyn++;
18617c478bd9Sstevel@tonic-gate 	}
18627c478bd9Sstevel@tonic-gate 	if (ofl->ofl_audit) {
18637c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_AUDIT;
18647c478bd9Sstevel@tonic-gate 		(void) st_setstring(dynstr, ofl->ofl_audit, &stoff);
18657c478bd9Sstevel@tonic-gate 		dyn->d_un.d_val = stoff;
18667c478bd9Sstevel@tonic-gate 		dyn++;
18677c478bd9Sstevel@tonic-gate 	}
18687c478bd9Sstevel@tonic-gate 
18697c478bd9Sstevel@tonic-gate 	/*
18707c478bd9Sstevel@tonic-gate 	 * The following DT_* entries do not apply to relocatable objects.
18717c478bd9Sstevel@tonic-gate 	 */
18727c478bd9Sstevel@tonic-gate 	if (!(flags & FLG_OF_RELOBJ)) {
18737c478bd9Sstevel@tonic-gate 
18747c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_HASH;
18757c478bd9Sstevel@tonic-gate 		dyn->d_un.d_ptr = ofl->ofl_oshash->os_shdr->sh_addr;
18767c478bd9Sstevel@tonic-gate 		dyn++;
18777c478bd9Sstevel@tonic-gate 
18787c478bd9Sstevel@tonic-gate 		shdr = ofl->ofl_osdynstr->os_shdr;
18797c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_STRTAB;
18807c478bd9Sstevel@tonic-gate 		dyn->d_un.d_ptr = shdr->sh_addr;
18817c478bd9Sstevel@tonic-gate 		dyn++;
18827c478bd9Sstevel@tonic-gate 
18837c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_STRSZ;
18847c478bd9Sstevel@tonic-gate 		dyn->d_un.d_ptr = shdr->sh_size;
18857c478bd9Sstevel@tonic-gate 		dyn++;
18867c478bd9Sstevel@tonic-gate 
18877c478bd9Sstevel@tonic-gate 		shdr = ofl->ofl_osdynsym->os_shdr;
18887c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_SYMTAB;
18897c478bd9Sstevel@tonic-gate 		dyn->d_un.d_ptr = shdr->sh_addr;
18907c478bd9Sstevel@tonic-gate 		dyn++;
18917c478bd9Sstevel@tonic-gate 
18927c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_SYMENT;
18937c478bd9Sstevel@tonic-gate 		dyn->d_un.d_ptr = shdr->sh_entsize;
18947c478bd9Sstevel@tonic-gate 		dyn++;
18957c478bd9Sstevel@tonic-gate 
1896*9039eeafSab 		if (ofl->ofl_osldynsym) {
1897*9039eeafSab 			/*
1898*9039eeafSab 			 * We have arranged for the .SUNW_ldynsym data to be
1899*9039eeafSab 			 * immediately in front of the .dynsym data.
1900*9039eeafSab 			 * This means that you could start at the top
1901*9039eeafSab 			 * of .SUNW_ldynsym and see the data for both tables
1902*9039eeafSab 			 * without a break. This is the view we want to
1903*9039eeafSab 			 * provide for DT_SUNW_SYMTAB, which is why we
1904*9039eeafSab 			 * add the lengths together.
1905*9039eeafSab 			 */
1906*9039eeafSab 			Shdr *lshdr = ofl->ofl_osldynsym->os_shdr;
1907*9039eeafSab 			dyn->d_tag = DT_SUNW_SYMTAB;
1908*9039eeafSab 			dyn->d_un.d_ptr = lshdr->sh_addr;
1909*9039eeafSab 			dyn++;
1910*9039eeafSab 
1911*9039eeafSab 			dyn->d_tag = DT_SUNW_SYMSZ;
1912*9039eeafSab 			dyn->d_un.d_val = lshdr->sh_size + shdr->sh_size;
1913*9039eeafSab 			dyn++;
1914*9039eeafSab 		}
1915*9039eeafSab 
19167c478bd9Sstevel@tonic-gate 		/*
19177c478bd9Sstevel@tonic-gate 		 * Reserve the DT_CHECKSUM entry.  Its value will be filled in
19187c478bd9Sstevel@tonic-gate 		 * after the complete image is built.
19197c478bd9Sstevel@tonic-gate 		 */
19207c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_CHECKSUM;
19217c478bd9Sstevel@tonic-gate 		ofl->ofl_checksum = &dyn->d_un.d_val;
19227c478bd9Sstevel@tonic-gate 		dyn++;
19237c478bd9Sstevel@tonic-gate 
19247c478bd9Sstevel@tonic-gate 		if ((flags & (FLG_OF_VERDEF | FLG_OF_NOVERSEC)) ==
19257c478bd9Sstevel@tonic-gate 		    FLG_OF_VERDEF) {
19267c478bd9Sstevel@tonic-gate 			shdr = ofl->ofl_osverdef->os_shdr;
19277c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_VERDEF;
19287c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_addr;
19297c478bd9Sstevel@tonic-gate 			dyn++;
19307c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_VERDEFNUM;
19317c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_info;
19327c478bd9Sstevel@tonic-gate 			dyn++;
19337c478bd9Sstevel@tonic-gate 		}
19347c478bd9Sstevel@tonic-gate 		if ((flags & (FLG_OF_VERNEED | FLG_OF_NOVERSEC)) ==
19357c478bd9Sstevel@tonic-gate 		    FLG_OF_VERNEED) {
19367c478bd9Sstevel@tonic-gate 			shdr = ofl->ofl_osverneed->os_shdr;
19377c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_VERNEED;
19387c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_addr;
19397c478bd9Sstevel@tonic-gate 			dyn++;
19407c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_VERNEEDNUM;
19417c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_info;
19427c478bd9Sstevel@tonic-gate 			dyn++;
19437c478bd9Sstevel@tonic-gate 		}
19447c478bd9Sstevel@tonic-gate 		if ((ofl->ofl_flags1 & FLG_OF1_RELCNT) &&
19457c478bd9Sstevel@tonic-gate 		    ofl->ofl_relocrelcnt) {
19467c478bd9Sstevel@tonic-gate 			dyn->d_tag = M_REL_DT_COUNT;
19477c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = ofl->ofl_relocrelcnt;
19487c478bd9Sstevel@tonic-gate 			dyn++;
19497c478bd9Sstevel@tonic-gate 		}
19507c478bd9Sstevel@tonic-gate 		if (flags & FLG_OF_TEXTREL) {
19517c478bd9Sstevel@tonic-gate 			/*
19527c478bd9Sstevel@tonic-gate 			 * Only the presence of this entry is used in this
19537c478bd9Sstevel@tonic-gate 			 * implementation, not the value stored.
19547c478bd9Sstevel@tonic-gate 			 */
19557c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_TEXTREL;
19567c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = 0;
19577c478bd9Sstevel@tonic-gate 			dyn++;
19587c478bd9Sstevel@tonic-gate 		}
19597c478bd9Sstevel@tonic-gate 
19607c478bd9Sstevel@tonic-gate 		if (ofl->ofl_osfiniarray) {
19617c478bd9Sstevel@tonic-gate 			shdr = ofl->ofl_osfiniarray->os_shdr;
19627c478bd9Sstevel@tonic-gate 
19637c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_FINI_ARRAY;
19647c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_addr;
19657c478bd9Sstevel@tonic-gate 			dyn++;
19667c478bd9Sstevel@tonic-gate 
19677c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_FINI_ARRAYSZ;
19687c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = shdr->sh_size;
19697c478bd9Sstevel@tonic-gate 			dyn++;
19707c478bd9Sstevel@tonic-gate 		}
19717c478bd9Sstevel@tonic-gate 
19727c478bd9Sstevel@tonic-gate 		if (ofl->ofl_osinitarray) {
19737c478bd9Sstevel@tonic-gate 			shdr = ofl->ofl_osinitarray->os_shdr;
19747c478bd9Sstevel@tonic-gate 
19757c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_INIT_ARRAY;
19767c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_addr;
19777c478bd9Sstevel@tonic-gate 			dyn++;
19787c478bd9Sstevel@tonic-gate 
19797c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_INIT_ARRAYSZ;
19807c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = shdr->sh_size;
19817c478bd9Sstevel@tonic-gate 			dyn++;
19827c478bd9Sstevel@tonic-gate 		}
19837c478bd9Sstevel@tonic-gate 
19847c478bd9Sstevel@tonic-gate 		if (ofl->ofl_ospreinitarray) {
19857c478bd9Sstevel@tonic-gate 			shdr = ofl->ofl_ospreinitarray->os_shdr;
19867c478bd9Sstevel@tonic-gate 
19877c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_PREINIT_ARRAY;
19887c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_addr;
19897c478bd9Sstevel@tonic-gate 			dyn++;
19907c478bd9Sstevel@tonic-gate 
19917c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_PREINIT_ARRAYSZ;
19927c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = shdr->sh_size;
19937c478bd9Sstevel@tonic-gate 			dyn++;
19947c478bd9Sstevel@tonic-gate 		}
19957c478bd9Sstevel@tonic-gate 
19967c478bd9Sstevel@tonic-gate 		if (ofl->ofl_pltcnt) {
19977c478bd9Sstevel@tonic-gate 			shdr =  ofl->ofl_osplt->os_relosdesc->os_shdr;
19987c478bd9Sstevel@tonic-gate 
19997c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_PLTRELSZ;
20007c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_size;
20017c478bd9Sstevel@tonic-gate 			dyn++;
20027c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_PLTREL;
20037c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = M_REL_DT_TYPE;
20047c478bd9Sstevel@tonic-gate 			dyn++;
20057c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_JMPREL;
20067c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_addr;
20077c478bd9Sstevel@tonic-gate 			dyn++;
20087c478bd9Sstevel@tonic-gate 		}
20097c478bd9Sstevel@tonic-gate 		if (ofl->ofl_pltpad) {
20107c478bd9Sstevel@tonic-gate 			shdr =  ofl->ofl_osplt->os_shdr;
20117c478bd9Sstevel@tonic-gate 
20127c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_PLTPAD;
20137c478bd9Sstevel@tonic-gate 			if (ofl->ofl_pltcnt)
20147c478bd9Sstevel@tonic-gate 				dyn->d_un.d_ptr = shdr->sh_addr +
20157c478bd9Sstevel@tonic-gate 					M_PLT_RESERVSZ +
20167c478bd9Sstevel@tonic-gate 					ofl->ofl_pltcnt * M_PLT_ENTSIZE;
20177c478bd9Sstevel@tonic-gate 			else
20187c478bd9Sstevel@tonic-gate 				dyn->d_un.d_ptr = shdr->sh_addr;
20197c478bd9Sstevel@tonic-gate 			dyn++;
20207c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_PLTPADSZ;
20217c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = ofl->ofl_pltpad *
20227c478bd9Sstevel@tonic-gate 				M_PLT_ENTSIZE;
20237c478bd9Sstevel@tonic-gate 			dyn++;
20247c478bd9Sstevel@tonic-gate 		}
20257c478bd9Sstevel@tonic-gate 		if (ofl->ofl_relocsz) {
20267c478bd9Sstevel@tonic-gate 			dyn->d_tag = M_REL_DT_TYPE;
20277c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = ofl->ofl_osrelhead->os_shdr->sh_addr;
20287c478bd9Sstevel@tonic-gate 			dyn++;
20297c478bd9Sstevel@tonic-gate 			dyn->d_tag = M_REL_DT_SIZE;
20307c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = ofl->ofl_relocsz;
20317c478bd9Sstevel@tonic-gate 			dyn++;
20327c478bd9Sstevel@tonic-gate 			dyn->d_tag = M_REL_DT_ENT;
20337c478bd9Sstevel@tonic-gate 			if (ofl->ofl_osrelhead->os_shdr->sh_type == SHT_REL)
20347c478bd9Sstevel@tonic-gate 				dyn->d_un.d_ptr = sizeof (Rel);
20357c478bd9Sstevel@tonic-gate 			else
20367c478bd9Sstevel@tonic-gate 				dyn->d_un.d_ptr = sizeof (Rela);
20377c478bd9Sstevel@tonic-gate 			dyn++;
20387c478bd9Sstevel@tonic-gate 		}
20397c478bd9Sstevel@tonic-gate 		if (ofl->ofl_ossyminfo) {
20407c478bd9Sstevel@tonic-gate 			shdr = ofl->ofl_ossyminfo->os_shdr;
20417c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_SYMINFO;
20427c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = shdr->sh_addr;
20437c478bd9Sstevel@tonic-gate 			dyn++;
20447c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_SYMINSZ;
20457c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = shdr->sh_size;
20467c478bd9Sstevel@tonic-gate 			dyn++;
20477c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_SYMINENT;
20487c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = sizeof (Syminfo);
20497c478bd9Sstevel@tonic-gate 			dyn++;
20507c478bd9Sstevel@tonic-gate 		}
20517c478bd9Sstevel@tonic-gate 		if (ofl->ofl_osmove) {
20527c478bd9Sstevel@tonic-gate 			Os_desc *	osp;
20537c478bd9Sstevel@tonic-gate 
20547c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_MOVEENT;
20557c478bd9Sstevel@tonic-gate 			osp = ofl->ofl_osmove;
20567c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = osp->os_shdr->sh_entsize;
20577c478bd9Sstevel@tonic-gate 			dyn++;
20587c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_MOVESZ;
20597c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = osp->os_shdr->sh_size;
20607c478bd9Sstevel@tonic-gate 			dyn++;
20617c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_MOVETAB;
20627c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = osp->os_shdr->sh_addr;
20637c478bd9Sstevel@tonic-gate 			dyn++;
20647c478bd9Sstevel@tonic-gate 		}
20657c478bd9Sstevel@tonic-gate 		if (ofl->ofl_regsymcnt) {
20667c478bd9Sstevel@tonic-gate 			int	ndx;
20677c478bd9Sstevel@tonic-gate 
20687c478bd9Sstevel@tonic-gate 			for (ndx = 0; ndx < ofl->ofl_regsymsno; ndx++) {
20697c478bd9Sstevel@tonic-gate 				if ((sdp = ofl->ofl_regsyms[ndx]) == 0)
20707c478bd9Sstevel@tonic-gate 					continue;
20717c478bd9Sstevel@tonic-gate 
20727c478bd9Sstevel@tonic-gate 				dyn->d_tag = M_DT_REGISTER;
20737c478bd9Sstevel@tonic-gate 				dyn->d_un.d_val = sdp->sd_symndx;
20747c478bd9Sstevel@tonic-gate 				dyn++;
20757c478bd9Sstevel@tonic-gate 			}
20767c478bd9Sstevel@tonic-gate 		}
20777c478bd9Sstevel@tonic-gate 
20787c478bd9Sstevel@tonic-gate 		for (LIST_TRAVERSE(&ofl->ofl_rtldinfo, lnp, sdp)) {
20797c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_SUNW_RTLDINF;
20807c478bd9Sstevel@tonic-gate 			dyn->d_un.d_ptr = sdp->sd_sym->st_value;
20817c478bd9Sstevel@tonic-gate 			dyn++;
20827c478bd9Sstevel@tonic-gate 		}
20837c478bd9Sstevel@tonic-gate 
20847c478bd9Sstevel@tonic-gate 		if (ofl->ofl_osdynamic->os_sgdesc &&
20857c478bd9Sstevel@tonic-gate 		    (ofl->ofl_osdynamic->os_sgdesc->sg_phdr.p_flags & PF_W)) {
20867c478bd9Sstevel@tonic-gate 			if (ofl->ofl_osinterp) {
20877c478bd9Sstevel@tonic-gate 				dyn->d_tag = DT_DEBUG;
20887c478bd9Sstevel@tonic-gate 				dyn->d_un.d_ptr = 0;
20897c478bd9Sstevel@tonic-gate 				dyn++;
20907c478bd9Sstevel@tonic-gate 			}
20917c478bd9Sstevel@tonic-gate 
20927c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_FEATURE_1;
20937c478bd9Sstevel@tonic-gate 			if (ofl->ofl_osmove)
20947c478bd9Sstevel@tonic-gate 				dyn->d_un.d_val = 0;
20957c478bd9Sstevel@tonic-gate 			else
20967c478bd9Sstevel@tonic-gate 				dyn->d_un.d_val = DTF_1_PARINIT;
20977c478bd9Sstevel@tonic-gate 			dyn++;
20987c478bd9Sstevel@tonic-gate 		}
20997c478bd9Sstevel@tonic-gate 
21007c478bd9Sstevel@tonic-gate 		if (ofl->ofl_oscap) {
21017c478bd9Sstevel@tonic-gate 			dyn->d_tag = DT_SUNW_CAP;
21027c478bd9Sstevel@tonic-gate 			dyn->d_un.d_val = ofl->ofl_oscap->os_shdr->sh_addr;
21037c478bd9Sstevel@tonic-gate 			dyn++;
21047c478bd9Sstevel@tonic-gate 		}
21057c478bd9Sstevel@tonic-gate 	}
21067c478bd9Sstevel@tonic-gate 
21077c478bd9Sstevel@tonic-gate 	if (flags & FLG_OF_SYMBOLIC) {
21087c478bd9Sstevel@tonic-gate 		dyn->d_tag = DT_SYMBOLIC;
21097c478bd9Sstevel@tonic-gate 		dyn->d_un.d_val = 0;
21107c478bd9Sstevel@tonic-gate 		dyn++;
21117c478bd9Sstevel@tonic-gate 	}
21127c478bd9Sstevel@tonic-gate 	dyn->d_tag = DT_FLAGS;
21137c478bd9Sstevel@tonic-gate 	dyn->d_un.d_val = ofl->ofl_dtflags;
21147c478bd9Sstevel@tonic-gate 	dyn++;
21157c478bd9Sstevel@tonic-gate 
21167c478bd9Sstevel@tonic-gate 	/*
21177c478bd9Sstevel@tonic-gate 	 * If -Bdirect was specified, but some NODIRECT symbols were specified
21187c478bd9Sstevel@tonic-gate 	 * via a mapfile, or -znodirect was used on the command line, then
21197c478bd9Sstevel@tonic-gate 	 * clear the DF_1_DIRECT flag.  The resultant object will use per-symbol
21207c478bd9Sstevel@tonic-gate 	 * direct bindings rather than be enabled for global direct bindings.
21217c478bd9Sstevel@tonic-gate 	 */
21227c478bd9Sstevel@tonic-gate 	if (ofl->ofl_flags1 & FLG_OF1_NDIRECT)
21237c478bd9Sstevel@tonic-gate 		ofl->ofl_dtflags_1 &= ~DF_1_DIRECT;
21247c478bd9Sstevel@tonic-gate 
21257c478bd9Sstevel@tonic-gate 	dyn->d_tag = DT_FLAGS_1;
21267c478bd9Sstevel@tonic-gate 	dyn->d_un.d_val = ofl->ofl_dtflags_1;
21277c478bd9Sstevel@tonic-gate 	dyn++;
21287c478bd9Sstevel@tonic-gate 
21295aefb655Srie 	ld_mach_update_odynamic(ofl, &dyn);
21307c478bd9Sstevel@tonic-gate 
21317c478bd9Sstevel@tonic-gate 	dyn->d_tag = DT_NULL;
21327c478bd9Sstevel@tonic-gate 	dyn->d_un.d_val = 0;
21337c478bd9Sstevel@tonic-gate 
21347c478bd9Sstevel@tonic-gate 	return (1);
21357c478bd9Sstevel@tonic-gate }
21367c478bd9Sstevel@tonic-gate 
21377c478bd9Sstevel@tonic-gate /*
21387c478bd9Sstevel@tonic-gate  * Build the version definition section
21397c478bd9Sstevel@tonic-gate  */
21405aefb655Srie static int
21417c478bd9Sstevel@tonic-gate update_overdef(Ofl_desc *ofl)
21427c478bd9Sstevel@tonic-gate {
21437c478bd9Sstevel@tonic-gate 	Listnode	*lnp1, *lnp2;
21447c478bd9Sstevel@tonic-gate 	Ver_desc	*vdp, *_vdp;
21457c478bd9Sstevel@tonic-gate 	Verdef		*vdf, *_vdf;
21467c478bd9Sstevel@tonic-gate 	int		num = 0;
21477c478bd9Sstevel@tonic-gate 	Os_desc		*strosp, *symosp;
21487c478bd9Sstevel@tonic-gate 
21497c478bd9Sstevel@tonic-gate 	/*
21507c478bd9Sstevel@tonic-gate 	 * Traverse the version descriptors and update the version structures
21517c478bd9Sstevel@tonic-gate 	 * to point to the dynstr name in preparation for building the version
21527c478bd9Sstevel@tonic-gate 	 * section structure.
21537c478bd9Sstevel@tonic-gate 	 */
21547c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_verdesc, lnp1, vdp)) {
21557c478bd9Sstevel@tonic-gate 		Sym_desc *	sdp;
21567c478bd9Sstevel@tonic-gate 
21577c478bd9Sstevel@tonic-gate 		if (vdp->vd_flags & VER_FLG_BASE) {
21587c478bd9Sstevel@tonic-gate 			const char	*name = vdp->vd_name;
21597c478bd9Sstevel@tonic-gate 			uint_t		stoff;
21607c478bd9Sstevel@tonic-gate 
21617c478bd9Sstevel@tonic-gate 			/*
21627c478bd9Sstevel@tonic-gate 			 * Create a new string table entry to represent the base
21637c478bd9Sstevel@tonic-gate 			 * version name (there is no corresponding symbol for
21647c478bd9Sstevel@tonic-gate 			 * this).
21657c478bd9Sstevel@tonic-gate 			 */
21667c478bd9Sstevel@tonic-gate 			if (!(ofl->ofl_flags & FLG_OF_DYNAMIC)) {
21677c478bd9Sstevel@tonic-gate 				(void) st_setstring(ofl->ofl_strtab,
21687c478bd9Sstevel@tonic-gate 					name, &stoff);
21697c478bd9Sstevel@tonic-gate 				/* LINTED */
21707c478bd9Sstevel@tonic-gate 				vdp->vd_name = (const char *)(uintptr_t)stoff;
21717c478bd9Sstevel@tonic-gate 			} else {
21727c478bd9Sstevel@tonic-gate 				(void) st_setstring(ofl->ofl_dynstrtab,
21737c478bd9Sstevel@tonic-gate 					name, &stoff);
21747c478bd9Sstevel@tonic-gate 				/* LINTED */
21757c478bd9Sstevel@tonic-gate 				vdp->vd_name = (const char *)(uintptr_t)stoff;
21767c478bd9Sstevel@tonic-gate 			}
21777c478bd9Sstevel@tonic-gate 		} else {
21785aefb655Srie 			sdp = ld_sym_find(vdp->vd_name, vdp->vd_hash, 0, ofl);
21797c478bd9Sstevel@tonic-gate 			/* LINTED */
21807c478bd9Sstevel@tonic-gate 			vdp->vd_name = (const char *)
21817c478bd9Sstevel@tonic-gate 				(uintptr_t)sdp->sd_sym->st_name;
21827c478bd9Sstevel@tonic-gate 		}
21837c478bd9Sstevel@tonic-gate 	}
21847c478bd9Sstevel@tonic-gate 
21857c478bd9Sstevel@tonic-gate 	_vdf = vdf = (Verdef *)ofl->ofl_osverdef->os_outdata->d_buf;
21867c478bd9Sstevel@tonic-gate 
21877c478bd9Sstevel@tonic-gate 	/*
21887c478bd9Sstevel@tonic-gate 	 * Traverse the version descriptors and update the version section to
21897c478bd9Sstevel@tonic-gate 	 * reflect each version and its associated dependencies.
21907c478bd9Sstevel@tonic-gate 	 */
21917c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_verdesc, lnp1, vdp)) {
21927c478bd9Sstevel@tonic-gate 		Half		cnt = 1;
21937c478bd9Sstevel@tonic-gate 		Verdaux *	vdap, * _vdap;
21947c478bd9Sstevel@tonic-gate 
21957c478bd9Sstevel@tonic-gate 		_vdap = vdap = (Verdaux *)(vdf + 1);
21967c478bd9Sstevel@tonic-gate 
21977c478bd9Sstevel@tonic-gate 		vdf->vd_version = VER_DEF_CURRENT;
21987c478bd9Sstevel@tonic-gate 		vdf->vd_flags	= vdp->vd_flags & MSK_VER_USER;
21997c478bd9Sstevel@tonic-gate 		vdf->vd_ndx	= vdp->vd_ndx;
22007c478bd9Sstevel@tonic-gate 		vdf->vd_hash	= vdp->vd_hash;
22017c478bd9Sstevel@tonic-gate 
22027c478bd9Sstevel@tonic-gate 		/* LINTED */
22037c478bd9Sstevel@tonic-gate 		vdap->vda_name = (uintptr_t)vdp->vd_name;
22047c478bd9Sstevel@tonic-gate 		vdap++;
22057c478bd9Sstevel@tonic-gate 		/* LINTED */
22067c478bd9Sstevel@tonic-gate 		_vdap->vda_next = (Word)((uintptr_t)vdap - (uintptr_t)_vdap);
22077c478bd9Sstevel@tonic-gate 
22087c478bd9Sstevel@tonic-gate 		/*
22097c478bd9Sstevel@tonic-gate 		 * Traverse this versions dependency list generating the
22107c478bd9Sstevel@tonic-gate 		 * appropriate version dependency entries.
22117c478bd9Sstevel@tonic-gate 		 */
22127c478bd9Sstevel@tonic-gate 		for (LIST_TRAVERSE(&vdp->vd_deps, lnp2, _vdp)) {
22137c478bd9Sstevel@tonic-gate 			/* LINTED */
22147c478bd9Sstevel@tonic-gate 			vdap->vda_name = (uintptr_t)_vdp->vd_name;
22157c478bd9Sstevel@tonic-gate 			_vdap = vdap;
22167c478bd9Sstevel@tonic-gate 			vdap++, cnt++;
22177c478bd9Sstevel@tonic-gate 			/* LINTED */
22187c478bd9Sstevel@tonic-gate 			_vdap->vda_next = (Word)((uintptr_t)vdap -
22197c478bd9Sstevel@tonic-gate 			    (uintptr_t)_vdap);
22207c478bd9Sstevel@tonic-gate 		}
22217c478bd9Sstevel@tonic-gate 		_vdap->vda_next = 0;
22227c478bd9Sstevel@tonic-gate 
22237c478bd9Sstevel@tonic-gate 		/*
22247c478bd9Sstevel@tonic-gate 		 * Record the versions auxiliary array offset and the associated
22257c478bd9Sstevel@tonic-gate 		 * dependency count.
22267c478bd9Sstevel@tonic-gate 		 */
22277c478bd9Sstevel@tonic-gate 		/* LINTED */
22287c478bd9Sstevel@tonic-gate 		vdf->vd_aux = (Word)((uintptr_t)(vdf + 1) - (uintptr_t)vdf);
22297c478bd9Sstevel@tonic-gate 		vdf->vd_cnt = cnt;
22307c478bd9Sstevel@tonic-gate 
22317c478bd9Sstevel@tonic-gate 		/*
22327c478bd9Sstevel@tonic-gate 		 * Record the next versions offset and update the version
22337c478bd9Sstevel@tonic-gate 		 * pointer.  Remember the previous version offset as the very
22347c478bd9Sstevel@tonic-gate 		 * last structures next pointer should be null.
22357c478bd9Sstevel@tonic-gate 		 */
22367c478bd9Sstevel@tonic-gate 		_vdf = vdf;
22377c478bd9Sstevel@tonic-gate 		vdf = (Verdef *)vdap, num++;
22387c478bd9Sstevel@tonic-gate 		/* LINTED */
22397c478bd9Sstevel@tonic-gate 		_vdf->vd_next = (Word)((uintptr_t)vdf - (uintptr_t)_vdf);
22407c478bd9Sstevel@tonic-gate 	}
22417c478bd9Sstevel@tonic-gate 	_vdf->vd_next = 0;
22427c478bd9Sstevel@tonic-gate 
22437c478bd9Sstevel@tonic-gate 	/*
22447c478bd9Sstevel@tonic-gate 	 * Record the string table association with the version definition
22457c478bd9Sstevel@tonic-gate 	 * section, and the symbol table associated with the version symbol
22467c478bd9Sstevel@tonic-gate 	 * table (the actual contents of the version symbol table are filled
22477c478bd9Sstevel@tonic-gate 	 * in during symbol update).
22487c478bd9Sstevel@tonic-gate 	 */
22497c478bd9Sstevel@tonic-gate 	if ((ofl->ofl_flags & FLG_OF_RELOBJ) ||
22507c478bd9Sstevel@tonic-gate 	    (ofl->ofl_flags & FLG_OF_STATIC)) {
22517c478bd9Sstevel@tonic-gate 		strosp = ofl->ofl_osstrtab;
22527c478bd9Sstevel@tonic-gate 		symosp = ofl->ofl_ossymtab;
22537c478bd9Sstevel@tonic-gate 	} else {
22547c478bd9Sstevel@tonic-gate 		strosp = ofl->ofl_osdynstr;
22557c478bd9Sstevel@tonic-gate 		symosp = ofl->ofl_osdynsym;
22567c478bd9Sstevel@tonic-gate 	}
22577c478bd9Sstevel@tonic-gate 	/* LINTED */
22587c478bd9Sstevel@tonic-gate 	ofl->ofl_osverdef->os_shdr->sh_link = (Word)elf_ndxscn(strosp->os_scn);
22597c478bd9Sstevel@tonic-gate 	/* LINTED */
22607c478bd9Sstevel@tonic-gate 	ofl->ofl_osversym->os_shdr->sh_link = (Word)elf_ndxscn(symosp->os_scn);
22617c478bd9Sstevel@tonic-gate 
22627c478bd9Sstevel@tonic-gate 	/*
22637c478bd9Sstevel@tonic-gate 	 * The version definition sections `info' field is used to indicate the
22647c478bd9Sstevel@tonic-gate 	 * number of entries in this section.
22657c478bd9Sstevel@tonic-gate 	 */
22667c478bd9Sstevel@tonic-gate 	ofl->ofl_osverdef->os_shdr->sh_info = num;
22677c478bd9Sstevel@tonic-gate 
22687c478bd9Sstevel@tonic-gate 	return (1);
22697c478bd9Sstevel@tonic-gate }
22707c478bd9Sstevel@tonic-gate 
22717c478bd9Sstevel@tonic-gate /*
22727c478bd9Sstevel@tonic-gate  * Build the version needed section
22737c478bd9Sstevel@tonic-gate  */
22745aefb655Srie static int
22757c478bd9Sstevel@tonic-gate update_overneed(Ofl_desc *ofl)
22767c478bd9Sstevel@tonic-gate {
22777c478bd9Sstevel@tonic-gate 	Listnode	*lnp;
22787c478bd9Sstevel@tonic-gate 	Ifl_desc	*ifl;
22797c478bd9Sstevel@tonic-gate 	Verneed		*vnd, *_vnd;
22807c478bd9Sstevel@tonic-gate 	Str_tbl		*dynstr;
22817c478bd9Sstevel@tonic-gate 	Word		num = 0, cnt = 0;
22827c478bd9Sstevel@tonic-gate 
22837c478bd9Sstevel@tonic-gate 	dynstr = ofl->ofl_dynstrtab;
22847c478bd9Sstevel@tonic-gate 	_vnd = vnd = (Verneed *)ofl->ofl_osverneed->os_outdata->d_buf;
22857c478bd9Sstevel@tonic-gate 
22867c478bd9Sstevel@tonic-gate 	/*
22877c478bd9Sstevel@tonic-gate 	 * Traverse the shared object list looking for dependencies that have
22887c478bd9Sstevel@tonic-gate 	 * versions defined within them.
22897c478bd9Sstevel@tonic-gate 	 */
22907c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_sos, lnp, ifl)) {
22917c478bd9Sstevel@tonic-gate 		Half		_cnt;
22927c478bd9Sstevel@tonic-gate 		Vernaux		*_vnap, *vnap;
22937c478bd9Sstevel@tonic-gate 		Sdf_desc	*sdf = ifl->ifl_sdfdesc;
22947c478bd9Sstevel@tonic-gate 		uint_t		stoff;
22957c478bd9Sstevel@tonic-gate 
22967c478bd9Sstevel@tonic-gate 		if (!(ifl->ifl_flags & FLG_IF_VERNEED))
22977c478bd9Sstevel@tonic-gate 			continue;
22987c478bd9Sstevel@tonic-gate 
22997c478bd9Sstevel@tonic-gate 		vnd->vn_version = VER_NEED_CURRENT;
23007c478bd9Sstevel@tonic-gate 
23017c478bd9Sstevel@tonic-gate 		(void) st_setstring(dynstr, ifl->ifl_soname, &stoff);
23027c478bd9Sstevel@tonic-gate 		vnd->vn_file = stoff;
23037c478bd9Sstevel@tonic-gate 
23047c478bd9Sstevel@tonic-gate 		_vnap = vnap = (Vernaux *)(vnd + 1);
23057c478bd9Sstevel@tonic-gate 
23067c478bd9Sstevel@tonic-gate 		if (sdf && (sdf->sdf_flags & FLG_SDF_SPECVER)) {
23077c478bd9Sstevel@tonic-gate 			Sdv_desc *	sdv;
23087c478bd9Sstevel@tonic-gate 			Listnode *	lnp2;
23097c478bd9Sstevel@tonic-gate 
23107c478bd9Sstevel@tonic-gate 			/*
23117c478bd9Sstevel@tonic-gate 			 * If version needed definitions were specified in
23127c478bd9Sstevel@tonic-gate 			 * a mapfile ($VERSION=*) then record those
23137c478bd9Sstevel@tonic-gate 			 * definitions.
23147c478bd9Sstevel@tonic-gate 			 */
23157c478bd9Sstevel@tonic-gate 			for (LIST_TRAVERSE(&sdf->sdf_verneed, lnp2, sdv)) {
23167c478bd9Sstevel@tonic-gate 				(void) st_setstring(dynstr,
23177c478bd9Sstevel@tonic-gate 					sdv->sdv_name, &stoff);
23187c478bd9Sstevel@tonic-gate 				vnap->vna_name = stoff;
23197c478bd9Sstevel@tonic-gate 				/* LINTED */
23207c478bd9Sstevel@tonic-gate 				vnap->vna_hash = (Word)elf_hash(sdv->sdv_name);
23217c478bd9Sstevel@tonic-gate 				vnap->vna_flags = 0;
23227c478bd9Sstevel@tonic-gate 				vnap->vna_other = 0;
23237c478bd9Sstevel@tonic-gate 				_vnap = vnap;
23247c478bd9Sstevel@tonic-gate 				vnap++;
23257c478bd9Sstevel@tonic-gate 				cnt++;
23267c478bd9Sstevel@tonic-gate 				/* LINTED */
23277c478bd9Sstevel@tonic-gate 				_vnap->vna_next = (Word)((uintptr_t)vnap -
23287c478bd9Sstevel@tonic-gate 				    (uintptr_t)_vnap);
23297c478bd9Sstevel@tonic-gate 			}
23307c478bd9Sstevel@tonic-gate 		} else {
23317c478bd9Sstevel@tonic-gate 
23327c478bd9Sstevel@tonic-gate 			/*
23337c478bd9Sstevel@tonic-gate 			 * Traverse the version index list recording
23347c478bd9Sstevel@tonic-gate 			 * each version as a needed dependency.
23357c478bd9Sstevel@tonic-gate 			 */
23367c478bd9Sstevel@tonic-gate 			for (cnt = _cnt = 0; _cnt <= ifl->ifl_vercnt;
23377c478bd9Sstevel@tonic-gate 			    _cnt++) {
23387c478bd9Sstevel@tonic-gate 				Ver_index *	vip = &ifl->ifl_verndx[_cnt];
23397c478bd9Sstevel@tonic-gate 
23407c478bd9Sstevel@tonic-gate 				if (vip->vi_flags & FLG_VER_REFER) {
23417c478bd9Sstevel@tonic-gate 					(void) st_setstring(dynstr,
23427c478bd9Sstevel@tonic-gate 						vip->vi_name, &stoff);
23437c478bd9Sstevel@tonic-gate 					vnap->vna_name = stoff;
23447c478bd9Sstevel@tonic-gate 					if (vip->vi_desc) {
23457c478bd9Sstevel@tonic-gate 					    vnap->vna_hash =
23467c478bd9Sstevel@tonic-gate 						vip->vi_desc->vd_hash;
23477c478bd9Sstevel@tonic-gate 					    vnap->vna_flags =
23487c478bd9Sstevel@tonic-gate 						vip->vi_desc->vd_flags;
23497c478bd9Sstevel@tonic-gate 					} else {
23507c478bd9Sstevel@tonic-gate 					    vnap->vna_hash = 0;
23517c478bd9Sstevel@tonic-gate 					    vnap->vna_flags = 0;
23527c478bd9Sstevel@tonic-gate 					}
23537c478bd9Sstevel@tonic-gate 					vnap->vna_other = 0;
23547c478bd9Sstevel@tonic-gate 
23557c478bd9Sstevel@tonic-gate 					_vnap = vnap;
23567c478bd9Sstevel@tonic-gate 					vnap++, cnt++;
23577c478bd9Sstevel@tonic-gate 					_vnap->vna_next =
23587c478bd9Sstevel@tonic-gate 						/* LINTED */
23597c478bd9Sstevel@tonic-gate 						(Word)((uintptr_t)vnap -
23607c478bd9Sstevel@tonic-gate 						    (uintptr_t)_vnap);
23617c478bd9Sstevel@tonic-gate 				}
23627c478bd9Sstevel@tonic-gate 			}
23637c478bd9Sstevel@tonic-gate 		}
23647c478bd9Sstevel@tonic-gate 		_vnap->vna_next = 0;
23657c478bd9Sstevel@tonic-gate 
23667c478bd9Sstevel@tonic-gate 		/*
23677c478bd9Sstevel@tonic-gate 		 * Record the versions auxiliary array offset and
23687c478bd9Sstevel@tonic-gate 		 * the associated dependency count.
23697c478bd9Sstevel@tonic-gate 		 */
23707c478bd9Sstevel@tonic-gate 		/* LINTED */
23717c478bd9Sstevel@tonic-gate 		vnd->vn_aux = (Word)((uintptr_t)(vnd + 1) - (uintptr_t)vnd);
23727c478bd9Sstevel@tonic-gate 		/* LINTED */
23737c478bd9Sstevel@tonic-gate 		vnd->vn_cnt = (Half)cnt;
23747c478bd9Sstevel@tonic-gate 
23757c478bd9Sstevel@tonic-gate 		/*
23767c478bd9Sstevel@tonic-gate 		 * Record the next versions offset and update the version
23777c478bd9Sstevel@tonic-gate 		 * pointer.  Remember the previous version offset as the very
23787c478bd9Sstevel@tonic-gate 		 * last structures next pointer should be null.
23797c478bd9Sstevel@tonic-gate 		 */
23807c478bd9Sstevel@tonic-gate 		_vnd = vnd;
23817c478bd9Sstevel@tonic-gate 		vnd = (Verneed *)vnap, num++;
23827c478bd9Sstevel@tonic-gate 		/* LINTED */
23837c478bd9Sstevel@tonic-gate 		_vnd->vn_next = (Word)((uintptr_t)vnd - (uintptr_t)_vnd);
23847c478bd9Sstevel@tonic-gate 	}
23857c478bd9Sstevel@tonic-gate 	_vnd->vn_next = 0;
23867c478bd9Sstevel@tonic-gate 
23877c478bd9Sstevel@tonic-gate 	/*
23887c478bd9Sstevel@tonic-gate 	 * Record association on string table section and use the
23897c478bd9Sstevel@tonic-gate 	 * `info' field to indicate the number of entries in this
23907c478bd9Sstevel@tonic-gate 	 * section.
23917c478bd9Sstevel@tonic-gate 	 */
23927c478bd9Sstevel@tonic-gate 	ofl->ofl_osverneed->os_shdr->sh_link =
23937c478bd9Sstevel@tonic-gate 	    /* LINTED */
23947c478bd9Sstevel@tonic-gate 	    (Word)elf_ndxscn(ofl->ofl_osdynstr->os_scn);
23957c478bd9Sstevel@tonic-gate 	ofl->ofl_osverneed->os_shdr->sh_info = num;
23967c478bd9Sstevel@tonic-gate 
23977c478bd9Sstevel@tonic-gate 	return (1);
23987c478bd9Sstevel@tonic-gate }
23997c478bd9Sstevel@tonic-gate 
24007c478bd9Sstevel@tonic-gate 
24017c478bd9Sstevel@tonic-gate /*
24027c478bd9Sstevel@tonic-gate  * Update syminfo section.
24037c478bd9Sstevel@tonic-gate  */
24045aefb655Srie static uintptr_t
24057c478bd9Sstevel@tonic-gate update_osyminfo(Ofl_desc * ofl)
24067c478bd9Sstevel@tonic-gate {
24077c478bd9Sstevel@tonic-gate 	Os_desc *	symosp, * infosp = ofl->ofl_ossyminfo;
24087c478bd9Sstevel@tonic-gate 	Syminfo *	sip = infosp->os_outdata->d_buf;
24097c478bd9Sstevel@tonic-gate 	Shdr *		shdr = infosp->os_shdr;
24107c478bd9Sstevel@tonic-gate 	char		*strtab;
24117c478bd9Sstevel@tonic-gate 	Listnode *	lnp;
24127c478bd9Sstevel@tonic-gate 	Sym_desc *	sdp;
24137c478bd9Sstevel@tonic-gate 	Aliste		off;
24147c478bd9Sstevel@tonic-gate 	Sfltr_desc *	sftp;
24157c478bd9Sstevel@tonic-gate 
24167c478bd9Sstevel@tonic-gate 	if (ofl->ofl_flags & FLG_OF_RELOBJ) {
24177c478bd9Sstevel@tonic-gate 		symosp = ofl->ofl_ossymtab;
24187c478bd9Sstevel@tonic-gate 		strtab = ofl->ofl_osstrtab->os_outdata->d_buf;
24197c478bd9Sstevel@tonic-gate 	} else {
24207c478bd9Sstevel@tonic-gate 		symosp = ofl->ofl_osdynsym;
24217c478bd9Sstevel@tonic-gate 		strtab = ofl->ofl_osdynstr->os_outdata->d_buf;
24227c478bd9Sstevel@tonic-gate 	}
24237c478bd9Sstevel@tonic-gate 
24247c478bd9Sstevel@tonic-gate 	/* LINTED */
24257c478bd9Sstevel@tonic-gate 	infosp->os_shdr->sh_link = (Word)elf_ndxscn(symosp->os_scn);
24267c478bd9Sstevel@tonic-gate 	if (ofl->ofl_osdynamic)
24277c478bd9Sstevel@tonic-gate 		infosp->os_shdr->sh_info =
24287c478bd9Sstevel@tonic-gate 		    /* LINTED */
24297c478bd9Sstevel@tonic-gate 		    (Word)elf_ndxscn(ofl->ofl_osdynamic->os_scn);
24307c478bd9Sstevel@tonic-gate 
24317c478bd9Sstevel@tonic-gate 	/*
24327c478bd9Sstevel@tonic-gate 	 * Update any references with the index into the dynamic table.
24337c478bd9Sstevel@tonic-gate 	 */
24347c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_syminfsyms, lnp, sdp)) {
24357c478bd9Sstevel@tonic-gate 		Ifl_desc *	ifl;
24367c478bd9Sstevel@tonic-gate 		if (sdp->sd_aux && sdp->sd_aux->sa_bindto)
24377c478bd9Sstevel@tonic-gate 			ifl = sdp->sd_aux->sa_bindto;
24387c478bd9Sstevel@tonic-gate 		else
24397c478bd9Sstevel@tonic-gate 			ifl = sdp->sd_file;
24407c478bd9Sstevel@tonic-gate 		sip[sdp->sd_symndx].si_boundto = ifl->ifl_neededndx;
24417c478bd9Sstevel@tonic-gate 	}
24427c478bd9Sstevel@tonic-gate 
24437c478bd9Sstevel@tonic-gate 	/*
24447c478bd9Sstevel@tonic-gate 	 * Update any filtee references with the index into the dynamic table.
24457c478bd9Sstevel@tonic-gate 	 */
24467c478bd9Sstevel@tonic-gate 	for (ALIST_TRAVERSE(ofl->ofl_symfltrs, off, sftp)) {
24477c478bd9Sstevel@tonic-gate 		Dfltr_desc *	dftp;
24487c478bd9Sstevel@tonic-gate 
24497c478bd9Sstevel@tonic-gate 		/* LINTED */
24507c478bd9Sstevel@tonic-gate 		dftp = (Dfltr_desc *)((char *)ofl->ofl_dtsfltrs +
24517c478bd9Sstevel@tonic-gate 		    sftp->sft_off);
24527c478bd9Sstevel@tonic-gate 		sip[sftp->sft_sdp->sd_symndx].si_boundto = dftp->dft_ndx;
24537c478bd9Sstevel@tonic-gate 	}
24547c478bd9Sstevel@tonic-gate 
24557c478bd9Sstevel@tonic-gate 	/*
24567c478bd9Sstevel@tonic-gate 	 * Display debugging information about section.
24577c478bd9Sstevel@tonic-gate 	 */
24585aefb655Srie 	DBG_CALL(Dbg_syminfo_title(ofl->ofl_lml));
24595aefb655Srie 	if (DBG_ENABLED) {
24605aefb655Srie 		Word	_cnt, cnt = shdr->sh_size / shdr->sh_entsize;
24617c478bd9Sstevel@tonic-gate 		Sym *	symtab = symosp->os_outdata->d_buf;
24627c478bd9Sstevel@tonic-gate 		Dyn *	dyn;
24637c478bd9Sstevel@tonic-gate 
24647c478bd9Sstevel@tonic-gate 		if (ofl->ofl_osdynamic)
24657c478bd9Sstevel@tonic-gate 			dyn = ofl->ofl_osdynamic->os_outdata->d_buf;
24667c478bd9Sstevel@tonic-gate 		else
24677c478bd9Sstevel@tonic-gate 			dyn = 0;
24687c478bd9Sstevel@tonic-gate 
24697c478bd9Sstevel@tonic-gate 		for (_cnt = 1; _cnt < cnt; _cnt++) {
24707c478bd9Sstevel@tonic-gate 			if (sip[_cnt].si_flags || sip[_cnt].si_boundto)
24717c478bd9Sstevel@tonic-gate 				/* LINTED */
24725aefb655Srie 				DBG_CALL(Dbg_syminfo_entry(ofl->ofl_lml, _cnt,
24737c478bd9Sstevel@tonic-gate 				    &sip[_cnt], &symtab[_cnt], strtab, dyn));
24747c478bd9Sstevel@tonic-gate 		}
24757c478bd9Sstevel@tonic-gate 	}
24767c478bd9Sstevel@tonic-gate 	return (1);
24777c478bd9Sstevel@tonic-gate }
24787c478bd9Sstevel@tonic-gate 
24797c478bd9Sstevel@tonic-gate /*
24807c478bd9Sstevel@tonic-gate  * Build the output elf header.
24817c478bd9Sstevel@tonic-gate  */
24825aefb655Srie static uintptr_t
24837c478bd9Sstevel@tonic-gate update_oehdr(Ofl_desc * ofl)
24847c478bd9Sstevel@tonic-gate {
24855aefb655Srie 	Ehdr	*ehdr = ofl->ofl_nehdr;
24867c478bd9Sstevel@tonic-gate 
24877c478bd9Sstevel@tonic-gate 	/*
24887c478bd9Sstevel@tonic-gate 	 * If an entry point symbol has already been established (refer
24897c478bd9Sstevel@tonic-gate 	 * sym_validate()) simply update the elf header entry point with the
24907c478bd9Sstevel@tonic-gate 	 * symbols value.  If no entry point is defined it will have been filled
24917c478bd9Sstevel@tonic-gate 	 * with the start address of the first section within the text segment
24927c478bd9Sstevel@tonic-gate 	 * (refer update_outfile()).
24937c478bd9Sstevel@tonic-gate 	 */
24947c478bd9Sstevel@tonic-gate 	if (ofl->ofl_entry)
24957c478bd9Sstevel@tonic-gate 		ehdr->e_entry =
24967c478bd9Sstevel@tonic-gate 			((Sym_desc *)(ofl->ofl_entry))->sd_sym->st_value;
24977c478bd9Sstevel@tonic-gate 
24987c478bd9Sstevel@tonic-gate 	/*
24997c478bd9Sstevel@tonic-gate 	 * Note. it may be necessary to update the `e_flags' field in the
25007c478bd9Sstevel@tonic-gate 	 * machine dependent section.
25017c478bd9Sstevel@tonic-gate 	 */
25027c478bd9Sstevel@tonic-gate 	ehdr->e_ident[EI_DATA] = M_DATA;
25035aefb655Srie 	ehdr->e_machine = ofl->ofl_dehdr->e_machine;
25045aefb655Srie 	ehdr->e_flags = ofl->ofl_dehdr->e_flags;
25055aefb655Srie 	ehdr->e_version = ofl->ofl_dehdr->e_version;
25065aefb655Srie 
25075aefb655Srie 	if (ehdr->e_machine != M_MACH) {
25085aefb655Srie 		if (ehdr->e_machine != M_MACHPLUS)
25097c478bd9Sstevel@tonic-gate 			return (S_ERROR);
25105aefb655Srie 		if ((ehdr->e_flags & M_FLAGSPLUS) == 0)
25117c478bd9Sstevel@tonic-gate 			return (S_ERROR);
25127c478bd9Sstevel@tonic-gate 	}
25137c478bd9Sstevel@tonic-gate 
25147c478bd9Sstevel@tonic-gate 	if (ofl->ofl_flags & FLG_OF_SHAROBJ)
25157c478bd9Sstevel@tonic-gate 		ehdr->e_type = ET_DYN;
25167c478bd9Sstevel@tonic-gate 	else if (ofl->ofl_flags & FLG_OF_RELOBJ)
25177c478bd9Sstevel@tonic-gate 		ehdr->e_type = ET_REL;
25187c478bd9Sstevel@tonic-gate 	else
25197c478bd9Sstevel@tonic-gate 		ehdr->e_type = ET_EXEC;
25207c478bd9Sstevel@tonic-gate 
25217c478bd9Sstevel@tonic-gate 	return (1);
25227c478bd9Sstevel@tonic-gate }
25237c478bd9Sstevel@tonic-gate 
25247c478bd9Sstevel@tonic-gate /*
25257c478bd9Sstevel@tonic-gate  * Perform move table expansion.
25267c478bd9Sstevel@tonic-gate  */
25277c478bd9Sstevel@tonic-gate static uintptr_t
25287c478bd9Sstevel@tonic-gate expand_move(Ofl_desc *ofl, Sym_desc *sdp, Move *u1)
25297c478bd9Sstevel@tonic-gate {
25307c478bd9Sstevel@tonic-gate 	Move		*mv;
25317c478bd9Sstevel@tonic-gate 	Os_desc		*osp;
25327c478bd9Sstevel@tonic-gate 	unsigned char	*taddr, *taddr0;
25337c478bd9Sstevel@tonic-gate 	Sxword		offset;
25347c478bd9Sstevel@tonic-gate 	int		i;
25357c478bd9Sstevel@tonic-gate 	Addr		base1;
25367c478bd9Sstevel@tonic-gate 	unsigned int	stride;
25377c478bd9Sstevel@tonic-gate 
25387c478bd9Sstevel@tonic-gate 	osp = ofl->ofl_issunwdata1->is_osdesc;
25397c478bd9Sstevel@tonic-gate 	base1 = (Addr)(osp->os_shdr->sh_addr +
25407c478bd9Sstevel@tonic-gate 		ofl->ofl_issunwdata1->is_indata->d_off);
25417c478bd9Sstevel@tonic-gate 	taddr0 = taddr = osp->os_outdata->d_buf;
25427c478bd9Sstevel@tonic-gate 	mv = u1;
25437c478bd9Sstevel@tonic-gate 
25447c478bd9Sstevel@tonic-gate 	offset = sdp->sd_sym->st_value - base1;
25457c478bd9Sstevel@tonic-gate 	taddr += offset;
25467c478bd9Sstevel@tonic-gate 	taddr = taddr + mv->m_poffset;
25477c478bd9Sstevel@tonic-gate 	for (i = 0; i < mv->m_repeat; i++) {
25487c478bd9Sstevel@tonic-gate 		/* LINTED */
25495aefb655Srie 		DBG_CALL(Dbg_move_expand(ofl->ofl_lml, mv,
25505aefb655Srie 		    (Addr)(taddr - taddr0)));
25517c478bd9Sstevel@tonic-gate 		stride = (unsigned int)mv->m_stride + 1;
25527c478bd9Sstevel@tonic-gate 		/* LINTED */
25537c478bd9Sstevel@tonic-gate 		switch (ELF_M_SIZE(mv->m_info)) {
25547c478bd9Sstevel@tonic-gate 		case 1:
25557c478bd9Sstevel@tonic-gate 			/* LINTED */
25567c478bd9Sstevel@tonic-gate 			*taddr = (unsigned char)mv->m_value;
25577c478bd9Sstevel@tonic-gate 			taddr += stride;
25587c478bd9Sstevel@tonic-gate 			break;
25597c478bd9Sstevel@tonic-gate 		case 2:
25607c478bd9Sstevel@tonic-gate 			/* LINTED */
25617c478bd9Sstevel@tonic-gate 			*((Half *)taddr) = (Half)mv->m_value;
25627c478bd9Sstevel@tonic-gate 			taddr += 2*stride;
25637c478bd9Sstevel@tonic-gate 			break;
25647c478bd9Sstevel@tonic-gate 		case 4:
25657c478bd9Sstevel@tonic-gate 			/* LINTED */
25667c478bd9Sstevel@tonic-gate 			*((Word *)taddr) = (Word)mv->m_value;
25677c478bd9Sstevel@tonic-gate 			taddr += 4*stride;
25687c478bd9Sstevel@tonic-gate 			break;
25697c478bd9Sstevel@tonic-gate 		case 8:
25707c478bd9Sstevel@tonic-gate 			/* LINTED */
25717c478bd9Sstevel@tonic-gate 			*((unsigned long long *)taddr) =
25727c478bd9Sstevel@tonic-gate 				mv->m_value;
25737c478bd9Sstevel@tonic-gate 			taddr += 8*stride;
25747c478bd9Sstevel@tonic-gate 			break;
25757c478bd9Sstevel@tonic-gate 		default:
25767c478bd9Sstevel@tonic-gate 			/*
25777c478bd9Sstevel@tonic-gate 			 * Should never come here since this is already
25787c478bd9Sstevel@tonic-gate 			 * checked at sunwmove_preprocess().
25797c478bd9Sstevel@tonic-gate 			 */
25807c478bd9Sstevel@tonic-gate 			return (S_ERROR);
25817c478bd9Sstevel@tonic-gate 		}
25827c478bd9Sstevel@tonic-gate 	}
25837c478bd9Sstevel@tonic-gate 	return (1);
25847c478bd9Sstevel@tonic-gate }
25857c478bd9Sstevel@tonic-gate 
25867c478bd9Sstevel@tonic-gate /*
25877c478bd9Sstevel@tonic-gate  * Update Move sections.
25887c478bd9Sstevel@tonic-gate  */
25895aefb655Srie static uintptr_t
25907c478bd9Sstevel@tonic-gate update_move(Ofl_desc *ofl)
25917c478bd9Sstevel@tonic-gate {
25927c478bd9Sstevel@tonic-gate 	Word		ndx = 0;
25937c478bd9Sstevel@tonic-gate 	Is_desc *	isp;
25947c478bd9Sstevel@tonic-gate 	Word		flags = ofl->ofl_flags;
25957c478bd9Sstevel@tonic-gate 	Move *		mv1, * mv2;
25967c478bd9Sstevel@tonic-gate 	Listnode *	lnp1;
25977c478bd9Sstevel@tonic-gate 	Psym_info *	psym;
25987c478bd9Sstevel@tonic-gate 
25997c478bd9Sstevel@tonic-gate 	/*
26007c478bd9Sstevel@tonic-gate 	 * Determine the index of the symbol table that will be referenced by
26017c478bd9Sstevel@tonic-gate 	 * the relocation entries.
26027c478bd9Sstevel@tonic-gate 	 */
2603*9039eeafSab 	if (OFL_ALLOW_DYNSYM(ofl))
26047c478bd9Sstevel@tonic-gate 		/* LINTED */
26057c478bd9Sstevel@tonic-gate 		ndx = (Word) elf_ndxscn(ofl->ofl_osdynsym->os_scn);
26067c478bd9Sstevel@tonic-gate 	else if (!(flags & FLG_OF_STRIP) || (flags & FLG_OF_RELOBJ))
26077c478bd9Sstevel@tonic-gate 		/* LINTED */
26087c478bd9Sstevel@tonic-gate 		ndx = (Word) elf_ndxscn(ofl->ofl_ossymtab->os_scn);
26097c478bd9Sstevel@tonic-gate 
26107c478bd9Sstevel@tonic-gate 	/*
26117c478bd9Sstevel@tonic-gate 	 * update sh_link and mv pointer for updating move table.
26127c478bd9Sstevel@tonic-gate 	 */
26137c478bd9Sstevel@tonic-gate 	if (ofl->ofl_osmove) {
26147c478bd9Sstevel@tonic-gate 		ofl->ofl_osmove->os_shdr->sh_link = ndx;
26157c478bd9Sstevel@tonic-gate 		mv1 = (Move *) ofl->ofl_osmove->os_outdata->d_buf;
26167c478bd9Sstevel@tonic-gate 	}
26177c478bd9Sstevel@tonic-gate 
26187c478bd9Sstevel@tonic-gate 	/*
26197c478bd9Sstevel@tonic-gate 	 * Update symbol entry index
26207c478bd9Sstevel@tonic-gate 	 */
26217c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_parsym, lnp1, psym)) {
26227c478bd9Sstevel@tonic-gate 		Listnode *	lnp2;
26237c478bd9Sstevel@tonic-gate 		Mv_itm *	mvp;
26247c478bd9Sstevel@tonic-gate 		Sym_desc 	*sdp;
26257c478bd9Sstevel@tonic-gate 
26267c478bd9Sstevel@tonic-gate 		/*
26277c478bd9Sstevel@tonic-gate 		 * Expand move table
26287c478bd9Sstevel@tonic-gate 		 */
26297c478bd9Sstevel@tonic-gate 		if (psym->psym_symd->sd_flags & FLG_SY_PAREXPN) {
26307c478bd9Sstevel@tonic-gate 			const char	*s;
26317c478bd9Sstevel@tonic-gate 
26327c478bd9Sstevel@tonic-gate 			if (ofl->ofl_flags & FLG_OF_STATIC)
26337c478bd9Sstevel@tonic-gate 				s = MSG_INTL(MSG_PSYM_EXPREASON1);
26347c478bd9Sstevel@tonic-gate 			else if (ofl->ofl_flags1 & FLG_OF1_NOPARTI)
26357c478bd9Sstevel@tonic-gate 				s = MSG_INTL(MSG_PSYM_EXPREASON2);
26367c478bd9Sstevel@tonic-gate 			else
26377c478bd9Sstevel@tonic-gate 				s = MSG_INTL(MSG_PSYM_EXPREASON3);
26385aefb655Srie 			DBG_CALL(Dbg_move_parexpn(ofl->ofl_lml,
26395aefb655Srie 			    psym->psym_symd->sd_name, s));
26407c478bd9Sstevel@tonic-gate 			for (LIST_TRAVERSE(&(psym->psym_mvs), lnp2, mvp)) {
26417c478bd9Sstevel@tonic-gate 				if ((mvp->mv_flag & FLG_MV_OUTSECT) == 0)
26427c478bd9Sstevel@tonic-gate 					continue;
26437c478bd9Sstevel@tonic-gate 				mv2 = mvp->mv_ientry;
26447c478bd9Sstevel@tonic-gate 				sdp = psym->psym_symd;
26455aefb655Srie 				DBG_CALL(Dbg_move_entry1(ofl->ofl_lml, 0,
26465aefb655Srie 				    mv2, sdp));
26477c478bd9Sstevel@tonic-gate 				(void) expand_move(ofl, sdp, mv2);
26487c478bd9Sstevel@tonic-gate 			}
26497c478bd9Sstevel@tonic-gate 			continue;
26507c478bd9Sstevel@tonic-gate 		}
26517c478bd9Sstevel@tonic-gate 
26527c478bd9Sstevel@tonic-gate 		/*
26537c478bd9Sstevel@tonic-gate 		 * Process move table
26547c478bd9Sstevel@tonic-gate 		 */
26555aefb655Srie 		DBG_CALL(Dbg_move_outmove(ofl->ofl_lml,
26565aefb655Srie 		    psym->psym_symd->sd_name));
26577c478bd9Sstevel@tonic-gate 		for (LIST_TRAVERSE(&(psym->psym_mvs), lnp2, mvp)) {
26587c478bd9Sstevel@tonic-gate 			int	idx = 1;
26597c478bd9Sstevel@tonic-gate 			if ((mvp->mv_flag & FLG_MV_OUTSECT) == 0)
26607c478bd9Sstevel@tonic-gate 				continue;
26617c478bd9Sstevel@tonic-gate 			isp = mvp->mv_isp;
26627c478bd9Sstevel@tonic-gate 			mv2 = mvp->mv_ientry;
26637c478bd9Sstevel@tonic-gate 			sdp = isp->is_file->ifl_oldndx[
26647c478bd9Sstevel@tonic-gate 				ELF_M_SYM(mv2->m_info)];
26657c478bd9Sstevel@tonic-gate 
26665aefb655Srie 			DBG_CALL(Dbg_move_entry1(ofl->ofl_lml, 0, mv2, sdp));
26677c478bd9Sstevel@tonic-gate 			*mv1 = *mv2;
26687c478bd9Sstevel@tonic-gate 			if ((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) {
26697c478bd9Sstevel@tonic-gate 				if (ELF_ST_BIND(sdp->sd_sym->st_info) ==
26707c478bd9Sstevel@tonic-gate 				    STB_LOCAL) {
26717c478bd9Sstevel@tonic-gate 				    Half	symbssndx =
26727c478bd9Sstevel@tonic-gate 					ofl->ofl_isbss->is_osdesc->os_scnsymndx;
26737c478bd9Sstevel@tonic-gate 				    mv1->m_info =
26747c478bd9Sstevel@tonic-gate 					/* LINTED */
26757c478bd9Sstevel@tonic-gate 					ELF_M_INFO(symbssndx, mv2->m_info);
26767c478bd9Sstevel@tonic-gate 				    if (ELF_ST_TYPE(sdp->sd_sym->st_info) !=
26777c478bd9Sstevel@tonic-gate 				    STT_SECTION) {
26787c478bd9Sstevel@tonic-gate 					mv1->m_poffset = sdp->sd_sym->st_value -
26797c478bd9Sstevel@tonic-gate 					ofl->ofl_isbss->
26807c478bd9Sstevel@tonic-gate 						is_osdesc->os_shdr->sh_addr +
26817c478bd9Sstevel@tonic-gate 					mv2->m_poffset;
26827c478bd9Sstevel@tonic-gate 				    }
26837c478bd9Sstevel@tonic-gate 				} else {
26847c478bd9Sstevel@tonic-gate 				    mv1->m_info =
26857c478bd9Sstevel@tonic-gate 					/* LINTED */
26867c478bd9Sstevel@tonic-gate 					ELF_M_INFO(sdp->sd_symndx, mv2->m_info);
26877c478bd9Sstevel@tonic-gate 				}
26887c478bd9Sstevel@tonic-gate 			} else {
26897c478bd9Sstevel@tonic-gate 				Boolean 	isredloc = FALSE;
26907c478bd9Sstevel@tonic-gate 
26917c478bd9Sstevel@tonic-gate 				if ((ELF_ST_BIND(sdp->sd_sym->st_info) ==
26927c478bd9Sstevel@tonic-gate 				    STB_LOCAL) &&
26937c478bd9Sstevel@tonic-gate 				    (ofl->ofl_flags1 & FLG_OF1_REDLSYM))
26947c478bd9Sstevel@tonic-gate 					isredloc = TRUE;
26957c478bd9Sstevel@tonic-gate 
26967c478bd9Sstevel@tonic-gate 				if (isredloc && !(sdp->sd_psyminfo)) {
26977c478bd9Sstevel@tonic-gate 					Word symndx =
26987c478bd9Sstevel@tonic-gate 					sdp->sd_isc->is_osdesc->os_scnsymndx;
26997c478bd9Sstevel@tonic-gate 					mv1->m_info =
27007c478bd9Sstevel@tonic-gate 					/* LINTED */
27017c478bd9Sstevel@tonic-gate 					ELF_M_INFO(symndx, mv2->m_info);
27027c478bd9Sstevel@tonic-gate 					mv1->m_poffset += sdp->sd_sym->st_value;
27037c478bd9Sstevel@tonic-gate 				} else {
27047c478bd9Sstevel@tonic-gate 					if (isredloc)
27055aefb655Srie 					    DBG_CALL(Dbg_syms_reduce(ofl,
27065aefb655Srie 						DBG_SYM_REDUCE_RETAIN, sdp,
27077c478bd9Sstevel@tonic-gate 						idx, ofl->ofl_osmove->os_name));
27087c478bd9Sstevel@tonic-gate 
27097c478bd9Sstevel@tonic-gate 					mv1->m_info =
27107c478bd9Sstevel@tonic-gate 					/* LINTED */
27117c478bd9Sstevel@tonic-gate 					ELF_M_INFO(sdp->sd_symndx, mv2->m_info);
27127c478bd9Sstevel@tonic-gate 				}
27137c478bd9Sstevel@tonic-gate 			}
27145aefb655Srie 			DBG_CALL(Dbg_move_entry1(ofl->ofl_lml, 1, mv1, sdp));
27157c478bd9Sstevel@tonic-gate 			mv1++;
27167c478bd9Sstevel@tonic-gate 			idx++;
27177c478bd9Sstevel@tonic-gate 		}
27187c478bd9Sstevel@tonic-gate 	}
27197c478bd9Sstevel@tonic-gate 	return (1);
27207c478bd9Sstevel@tonic-gate }
27217c478bd9Sstevel@tonic-gate 
27227c478bd9Sstevel@tonic-gate 
27237c478bd9Sstevel@tonic-gate /*
27247c478bd9Sstevel@tonic-gate  * Scan through the SHT_GROUP output sections.  Update their
27257c478bd9Sstevel@tonic-gate  * sh_link/sh_info fields as well as the section contents.
27267c478bd9Sstevel@tonic-gate  */
27275aefb655Srie static uintptr_t
27287c478bd9Sstevel@tonic-gate update_ogroup(Ofl_desc * ofl)
27297c478bd9Sstevel@tonic-gate {
27307c478bd9Sstevel@tonic-gate 	Listnode	*lnp;
27317c478bd9Sstevel@tonic-gate 	Os_desc		*osp;
27327c478bd9Sstevel@tonic-gate 	uintptr_t	error = 0;
27337c478bd9Sstevel@tonic-gate 
27347c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_osgroups, lnp, osp)) {
27357c478bd9Sstevel@tonic-gate 		Is_desc		*isp;
27367c478bd9Sstevel@tonic-gate 		Ifl_desc	*ifl;
27377c478bd9Sstevel@tonic-gate 		Shdr		*shdr = osp->os_shdr;
27387c478bd9Sstevel@tonic-gate 		Sym_desc	*sdp;
27397c478bd9Sstevel@tonic-gate 		Xword		i, grpcnt;
27407c478bd9Sstevel@tonic-gate 		Word		*gdata;
27417c478bd9Sstevel@tonic-gate 
27427c478bd9Sstevel@tonic-gate 		/*
27437c478bd9Sstevel@tonic-gate 		 * Since input GROUP sections always create unique
27447c478bd9Sstevel@tonic-gate 		 * output GROUP sections - we know there is only one
27457c478bd9Sstevel@tonic-gate 		 * item on the list.
27467c478bd9Sstevel@tonic-gate 		 */
27477c478bd9Sstevel@tonic-gate 		isp = (Is_desc *)osp->os_isdescs.head->data;
27487c478bd9Sstevel@tonic-gate 
27497c478bd9Sstevel@tonic-gate 		ifl = isp->is_file;
27507c478bd9Sstevel@tonic-gate 		sdp = ifl->ifl_oldndx[isp->is_shdr->sh_info];
27517c478bd9Sstevel@tonic-gate 		shdr->sh_link = (Word)elf_ndxscn(ofl->ofl_ossymtab->os_scn);
27527c478bd9Sstevel@tonic-gate 		shdr->sh_info = sdp->sd_symndx;
27537c478bd9Sstevel@tonic-gate 
27547c478bd9Sstevel@tonic-gate 		/*
27557c478bd9Sstevel@tonic-gate 		 * Scan through the group data section and update
27567c478bd9Sstevel@tonic-gate 		 * all of the links to new values.
27577c478bd9Sstevel@tonic-gate 		 */
27587c478bd9Sstevel@tonic-gate 		grpcnt = shdr->sh_size / shdr->sh_entsize;
27597c478bd9Sstevel@tonic-gate 		gdata = (Word *)osp->os_outdata->d_buf;
27607c478bd9Sstevel@tonic-gate 		for (i = 1; i < grpcnt; i++) {
27617c478bd9Sstevel@tonic-gate 			Is_desc	*	_isp;
27627c478bd9Sstevel@tonic-gate 			Os_desc	*	_osp;
27637c478bd9Sstevel@tonic-gate 
27647c478bd9Sstevel@tonic-gate 			/*
27657c478bd9Sstevel@tonic-gate 			 * Perform a sanity check that the section index
27667c478bd9Sstevel@tonic-gate 			 * stored in the SHT_GROUP section is valid
27677c478bd9Sstevel@tonic-gate 			 * for the file it came from.
27687c478bd9Sstevel@tonic-gate 			 */
27697c478bd9Sstevel@tonic-gate 			if (gdata[i] >= ifl->ifl_shnum) {
27705aefb655Srie 				eprintf(ofl->ofl_lml, ERR_FATAL,
27715aefb655Srie 				    MSG_INTL(MSG_GRP_INVALNDX), isp->is_name,
27725aefb655Srie 				    ifl->ifl_name, i, gdata[i]);
27737c478bd9Sstevel@tonic-gate 				error = S_ERROR;
27747c478bd9Sstevel@tonic-gate 				gdata[i] = 0;
27757c478bd9Sstevel@tonic-gate 				continue;
27767c478bd9Sstevel@tonic-gate 			}
27777c478bd9Sstevel@tonic-gate 
27787c478bd9Sstevel@tonic-gate 			_isp = ifl->ifl_isdesc[gdata[i]];
27797c478bd9Sstevel@tonic-gate 
27807c478bd9Sstevel@tonic-gate 			/*
27817c478bd9Sstevel@tonic-gate 			 * If the referenced section didn't make it to the
27827c478bd9Sstevel@tonic-gate 			 * output file - just zero out the entry.
27837c478bd9Sstevel@tonic-gate 			 */
27847c478bd9Sstevel@tonic-gate 			if ((_osp = _isp->is_osdesc) == 0)
27857c478bd9Sstevel@tonic-gate 				gdata[i] = 0;
27867c478bd9Sstevel@tonic-gate 			else
27877c478bd9Sstevel@tonic-gate 				gdata[i] = (Word)elf_ndxscn(_osp->os_scn);
27887c478bd9Sstevel@tonic-gate 		}
27897c478bd9Sstevel@tonic-gate 	}
27907c478bd9Sstevel@tonic-gate 	return (error);
27917c478bd9Sstevel@tonic-gate }
27927c478bd9Sstevel@tonic-gate 
27935aefb655Srie static void
27947c478bd9Sstevel@tonic-gate update_ostrtab(Os_desc *osp, Str_tbl *stp)
27957c478bd9Sstevel@tonic-gate {
27967c478bd9Sstevel@tonic-gate 	Elf_Data	*data;
27977c478bd9Sstevel@tonic-gate 	if (osp == 0)
27987c478bd9Sstevel@tonic-gate 		return;
27997c478bd9Sstevel@tonic-gate 
28007c478bd9Sstevel@tonic-gate 	data = osp->os_outdata;
28017c478bd9Sstevel@tonic-gate 	assert(data->d_size == st_getstrtab_sz(stp));
28027c478bd9Sstevel@tonic-gate 	(void) st_setstrbuf(stp, data->d_buf, (uint_t)data->d_size);
28037c478bd9Sstevel@tonic-gate }
28047c478bd9Sstevel@tonic-gate 
28057c478bd9Sstevel@tonic-gate /*
28067c478bd9Sstevel@tonic-gate  * Translate the shdr->sh_{link, info} from its input section value to that
28077c478bd9Sstevel@tonic-gate  * of the corresponding shdr->sh_{link, info} output section value.
28087c478bd9Sstevel@tonic-gate  */
28095aefb655Srie static Word
28105aefb655Srie translate_link(Ofl_desc *ofl, Os_desc *osp, Word link, const char *msg)
28117c478bd9Sstevel@tonic-gate {
28127c478bd9Sstevel@tonic-gate 	Is_desc *	isp;
28137c478bd9Sstevel@tonic-gate 	Ifl_desc *	ifl;
28147c478bd9Sstevel@tonic-gate 
28157c478bd9Sstevel@tonic-gate 	/*
28167c478bd9Sstevel@tonic-gate 	 * Don't translate the special section numbers.
28177c478bd9Sstevel@tonic-gate 	 */
28187c478bd9Sstevel@tonic-gate 	if (link >= SHN_LORESERVE)
28197c478bd9Sstevel@tonic-gate 		return (link);
28207c478bd9Sstevel@tonic-gate 
28217c478bd9Sstevel@tonic-gate 	/*
28227c478bd9Sstevel@tonic-gate 	 * Does this output section translate back to an input file.  If not
28237c478bd9Sstevel@tonic-gate 	 * then there is no translation to do.  In this case we will assume that
28247c478bd9Sstevel@tonic-gate 	 * if sh_link has a value, it's the right value.
28257c478bd9Sstevel@tonic-gate 	 */
28267c478bd9Sstevel@tonic-gate 	isp = (Is_desc *)osp->os_isdescs.head->data;
28277c478bd9Sstevel@tonic-gate 	if ((ifl = isp->is_file) == NULL)
28287c478bd9Sstevel@tonic-gate 		return (link);
28297c478bd9Sstevel@tonic-gate 
28307c478bd9Sstevel@tonic-gate 	/*
28317c478bd9Sstevel@tonic-gate 	 * Sanity check to make sure that the sh_{link, info} value
28327c478bd9Sstevel@tonic-gate 	 * is within range for the input file.
28337c478bd9Sstevel@tonic-gate 	 */
28347c478bd9Sstevel@tonic-gate 	if (link >= ifl->ifl_shnum) {
28355aefb655Srie 		eprintf(ofl->ofl_lml, ERR_WARNING, msg, ifl->ifl_name,
28367c478bd9Sstevel@tonic-gate 		    isp->is_name, EC_XWORD(link));
28377c478bd9Sstevel@tonic-gate 		return (link);
28387c478bd9Sstevel@tonic-gate 	}
28397c478bd9Sstevel@tonic-gate 
28407c478bd9Sstevel@tonic-gate 	/*
28417c478bd9Sstevel@tonic-gate 	 * Follow the link to the input section.
28427c478bd9Sstevel@tonic-gate 	 */
28437c478bd9Sstevel@tonic-gate 	if ((isp = ifl->ifl_isdesc[link]) == 0)
28447c478bd9Sstevel@tonic-gate 		return (0);
28457c478bd9Sstevel@tonic-gate 	if ((osp = isp->is_osdesc) == 0)
28467c478bd9Sstevel@tonic-gate 		return (0);
28477c478bd9Sstevel@tonic-gate 
28487c478bd9Sstevel@tonic-gate 	/* LINTED */
28497c478bd9Sstevel@tonic-gate 	return ((Word)elf_ndxscn(osp->os_scn));
28507c478bd9Sstevel@tonic-gate }
28517c478bd9Sstevel@tonic-gate 
28527c478bd9Sstevel@tonic-gate /*
28537c478bd9Sstevel@tonic-gate  * Having created all of the necessary sections, segments, and associated
28547c478bd9Sstevel@tonic-gate  * headers, fill in the program headers and update any other data in the
28557c478bd9Sstevel@tonic-gate  * output image.  Some general rules:
28567c478bd9Sstevel@tonic-gate  *
285770d3e49eSrie  *  o	If an interpreter is required always generate a PT_PHDR entry as
28587c478bd9Sstevel@tonic-gate  *	well.  It is this entry that triggers the kernel into passing the
285970d3e49eSrie  *	interpreter an aux vector instead of just a file descriptor.
28607c478bd9Sstevel@tonic-gate  *
28617c478bd9Sstevel@tonic-gate  *  o	When generating an image that will be interpreted (ie. a dynamic
28627c478bd9Sstevel@tonic-gate  *	executable, a shared object, or a static executable that has been
286370d3e49eSrie  *	provided with an interpreter - weird, but possible), make the initial
28647c478bd9Sstevel@tonic-gate  *	loadable segment include both the ehdr and phdr[].  Both of these
286570d3e49eSrie  *	tables are used by the interpreter therefore it seems more intuitive
28667c478bd9Sstevel@tonic-gate  *	to explicitly defined them as part of the mapped image rather than
286770d3e49eSrie  *	relying on page rounding by the interpreter to allow their access.
28687c478bd9Sstevel@tonic-gate  *
286970d3e49eSrie  *  o	When generating a static image that does not require an interpreter
28707c478bd9Sstevel@tonic-gate  *	have the first loadable segment indicate the address of the first
28717c478bd9Sstevel@tonic-gate  *	.section as the start address (things like /kernel/unix and ufsboot
28727c478bd9Sstevel@tonic-gate  *	expect this behavior).
28737c478bd9Sstevel@tonic-gate  */
28747c478bd9Sstevel@tonic-gate uintptr_t
28755aefb655Srie ld_update_outfile(Ofl_desc *ofl)
28767c478bd9Sstevel@tonic-gate {
28777c478bd9Sstevel@tonic-gate 	Addr		size, etext, vaddr = ofl->ofl_segorigin;
28787c478bd9Sstevel@tonic-gate 	Listnode	*lnp1, *lnp2;
28797c478bd9Sstevel@tonic-gate 	Sg_desc		*sgp;
28800bc07c75Srie 	Os_desc		**ospp, *osp;
28817c478bd9Sstevel@tonic-gate 	int		phdrndx = 0, capndx = 0, segndx = -1, secndx;
28825aefb655Srie 	Ehdr		*ehdr = ofl->ofl_nehdr;
28837c478bd9Sstevel@tonic-gate 	Shdr		*hshdr;
28847c478bd9Sstevel@tonic-gate 	Phdr		*_phdr = 0, *dtracephdr = 0;
28857c478bd9Sstevel@tonic-gate 	Word		phdrsz = ehdr->e_phnum *ehdr->e_phentsize, shscnndx;
28867c478bd9Sstevel@tonic-gate 	Word		flags = ofl->ofl_flags, ehdrsz = ehdr->e_ehsize;
28877c478bd9Sstevel@tonic-gate 	Boolean		nobits;
28887c478bd9Sstevel@tonic-gate 	Off		offset;
28890bc07c75Srie 	Aliste		off;
28907c478bd9Sstevel@tonic-gate 
28917c478bd9Sstevel@tonic-gate 	/*
28927c478bd9Sstevel@tonic-gate 	 * Loop through the segment descriptors and pick out what we need.
28937c478bd9Sstevel@tonic-gate 	 */
28945aefb655Srie 	DBG_CALL(Dbg_seg_title(ofl->ofl_lml));
28957c478bd9Sstevel@tonic-gate 	for (LIST_TRAVERSE(&ofl->ofl_segs, lnp1, sgp)) {
28967c478bd9Sstevel@tonic-gate 		Phdr *	phdr = &(sgp->sg_phdr);
28977c478bd9Sstevel@tonic-gate 		Xword 	p_align;
28987c478bd9Sstevel@tonic-gate 
28997c478bd9Sstevel@tonic-gate 		segndx++;
29007c478bd9Sstevel@tonic-gate 
29017c478bd9Sstevel@tonic-gate 		/*
29027c478bd9Sstevel@tonic-gate 		 * If an interpreter is required generate a PT_INTERP and
29037c478bd9Sstevel@tonic-gate 		 * PT_PHDR program header entry.  The PT_PHDR entry describes
29047c478bd9Sstevel@tonic-gate 		 * the program header table itself.  This information will be
29057c478bd9Sstevel@tonic-gate 		 * passed via the aux vector to the interpreter (ld.so.1).
29067c478bd9Sstevel@tonic-gate 		 * The program header array is actually part of the first
29077c478bd9Sstevel@tonic-gate 		 * loadable segment (and the PT_PHDR entry is the first entry),
29087c478bd9Sstevel@tonic-gate 		 * therefore its virtual address isn't known until the first
29097c478bd9Sstevel@tonic-gate 		 * loadable segment is processed.
29107c478bd9Sstevel@tonic-gate 		 */
29117c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_PHDR) {
29127c478bd9Sstevel@tonic-gate 			if (ofl->ofl_osinterp) {
29137c478bd9Sstevel@tonic-gate 				phdr->p_offset = ehdr->e_phoff;
29147c478bd9Sstevel@tonic-gate 				phdr->p_filesz = phdr->p_memsz = phdrsz;
29155aefb655Srie 				DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp));
29167c478bd9Sstevel@tonic-gate 				ofl->ofl_phdr[phdrndx++] = *phdr;
29177c478bd9Sstevel@tonic-gate 			}
29187c478bd9Sstevel@tonic-gate 			continue;
29197c478bd9Sstevel@tonic-gate 		}
29207c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_INTERP) {
29217c478bd9Sstevel@tonic-gate 			if (ofl->ofl_osinterp) {
29227c478bd9Sstevel@tonic-gate 				Shdr *	shdr = ofl->ofl_osinterp->os_shdr;
29237c478bd9Sstevel@tonic-gate 
29247c478bd9Sstevel@tonic-gate 				phdr->p_vaddr = phdr->p_memsz = 0;
29257c478bd9Sstevel@tonic-gate 				phdr->p_offset = shdr->sh_offset;
29267c478bd9Sstevel@tonic-gate 				phdr->p_filesz = shdr->sh_size;
29275aefb655Srie 				DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp));
29287c478bd9Sstevel@tonic-gate 				ofl->ofl_phdr[phdrndx++] = *phdr;
29297c478bd9Sstevel@tonic-gate 			}
29307c478bd9Sstevel@tonic-gate 			continue;
29317c478bd9Sstevel@tonic-gate 		}
29327c478bd9Sstevel@tonic-gate 
29337c478bd9Sstevel@tonic-gate 		/*
29347c478bd9Sstevel@tonic-gate 		 * If we are creating a PT_SUNWDTRACE segment,
29357c478bd9Sstevel@tonic-gate 		 * just remember where the program header is.
29367c478bd9Sstevel@tonic-gate 		 *
29377c478bd9Sstevel@tonic-gate 		 * It's actual values will be assigned after
29387c478bd9Sstevel@tonic-gate 		 * update_osym() has completed and the symbol
29397c478bd9Sstevel@tonic-gate 		 * table addresses have been udpated.
29407c478bd9Sstevel@tonic-gate 		 */
29417c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_SUNWDTRACE) {
29427c478bd9Sstevel@tonic-gate 			if ((ofl->ofl_dtracesym) &&
29437c478bd9Sstevel@tonic-gate 			    ((flags & FLG_OF_RELOBJ) == 0)) {
29447c478bd9Sstevel@tonic-gate 				dtracephdr = &ofl->ofl_phdr[phdrndx];
29457c478bd9Sstevel@tonic-gate 				ofl->ofl_phdr[phdrndx++] = *phdr;
29467c478bd9Sstevel@tonic-gate 			}
29477c478bd9Sstevel@tonic-gate 			continue;
29487c478bd9Sstevel@tonic-gate 		}
29497c478bd9Sstevel@tonic-gate 
29507c478bd9Sstevel@tonic-gate 		/*
29517c478bd9Sstevel@tonic-gate 		 * If a hardware/software capabilities section is required,
29527c478bd9Sstevel@tonic-gate 		 * generate the PT_SUNWCAP header.  Note, as this comes before
29537c478bd9Sstevel@tonic-gate 		 * the first loadable segment, we don't yet know its real
29547c478bd9Sstevel@tonic-gate 		 * virtual address.  This is updated later.
29557c478bd9Sstevel@tonic-gate 		 */
29567c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_SUNWCAP) {
29577c478bd9Sstevel@tonic-gate 			if (ofl->ofl_oscap) {
29587c478bd9Sstevel@tonic-gate 				Shdr *	shdr = ofl->ofl_oscap->os_shdr;
29597c478bd9Sstevel@tonic-gate 
29607c478bd9Sstevel@tonic-gate 				phdr->p_vaddr = shdr->sh_addr;
29617c478bd9Sstevel@tonic-gate 				phdr->p_offset = shdr->sh_offset;
29627c478bd9Sstevel@tonic-gate 				phdr->p_filesz = shdr->sh_size;
29637c478bd9Sstevel@tonic-gate 				phdr->p_flags = PF_R;
29645aefb655Srie 				DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp));
29657c478bd9Sstevel@tonic-gate 				capndx = phdrndx;
29667c478bd9Sstevel@tonic-gate 				ofl->ofl_phdr[phdrndx++] = *phdr;
29677c478bd9Sstevel@tonic-gate 			}
29687c478bd9Sstevel@tonic-gate 			continue;
29697c478bd9Sstevel@tonic-gate 		}
29707c478bd9Sstevel@tonic-gate 
29717c478bd9Sstevel@tonic-gate 		/*
29727c478bd9Sstevel@tonic-gate 		 * As the dynamic program header occurs after the loadable
29737c478bd9Sstevel@tonic-gate 		 * headers in the segment descriptor table, all the address
29747c478bd9Sstevel@tonic-gate 		 * information for the .dynamic output section will have been
29757c478bd9Sstevel@tonic-gate 		 * figured out by now.
29767c478bd9Sstevel@tonic-gate 		 */
29777c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_DYNAMIC) {
2978*9039eeafSab 			if (OFL_ALLOW_DYNSYM(ofl)) {
29797c478bd9Sstevel@tonic-gate 				Shdr *	shdr = ofl->ofl_osdynamic->os_shdr;
29807c478bd9Sstevel@tonic-gate 
29817c478bd9Sstevel@tonic-gate 				phdr->p_vaddr = shdr->sh_addr;
29827c478bd9Sstevel@tonic-gate 				phdr->p_offset = shdr->sh_offset;
29837c478bd9Sstevel@tonic-gate 				phdr->p_filesz = shdr->sh_size;
29847c478bd9Sstevel@tonic-gate 				phdr->p_flags = M_DATASEG_PERM;
29855aefb655Srie 				DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp));
29867c478bd9Sstevel@tonic-gate 				ofl->ofl_phdr[phdrndx++] = *phdr;
29877c478bd9Sstevel@tonic-gate 			}
29887c478bd9Sstevel@tonic-gate 			continue;
29897c478bd9Sstevel@tonic-gate 		}
29905aefb655Srie #if	defined(__x86) && defined(_ELF64)
29917c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_SUNW_UNWIND) {
29927c478bd9Sstevel@tonic-gate 			Shdr	    *shdr;
29937c478bd9Sstevel@tonic-gate 			if (ofl->ofl_unwindhdr == 0)
29947c478bd9Sstevel@tonic-gate 				continue;
29957c478bd9Sstevel@tonic-gate 			shdr = ofl->ofl_unwindhdr->os_shdr;
29967c478bd9Sstevel@tonic-gate 
29977c478bd9Sstevel@tonic-gate 			phdr->p_flags = PF_R;
29987c478bd9Sstevel@tonic-gate 			phdr->p_vaddr = shdr->sh_addr;
29997c478bd9Sstevel@tonic-gate 			phdr->p_memsz = shdr->sh_size;
30007c478bd9Sstevel@tonic-gate 			phdr->p_filesz = shdr->sh_size;
30017c478bd9Sstevel@tonic-gate 			phdr->p_offset = shdr->sh_offset;
30027c478bd9Sstevel@tonic-gate 			phdr->p_align = shdr->sh_addralign;
30037c478bd9Sstevel@tonic-gate 			phdr->p_paddr = 0;
30047c478bd9Sstevel@tonic-gate 			ofl->ofl_phdr[phdrndx++] = *phdr;
30057c478bd9Sstevel@tonic-gate 			continue;
30067c478bd9Sstevel@tonic-gate 		}
30077c478bd9Sstevel@tonic-gate #endif
30087c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_TLS) {
3009dd94ecefSrie 			Os_desc	*tlsosp;
3010dd94ecefSrie 			Shdr	*firstshdr = 0, *lastfilshdr, *lastmemshdr;
30117c478bd9Sstevel@tonic-gate 
3012dd94ecefSrie 			if (ofl->ofl_ostlsseg.head == NULL)
30137c478bd9Sstevel@tonic-gate 				continue;
3014dd94ecefSrie 
3015dd94ecefSrie 			for (LIST_TRAVERSE(&ofl->ofl_ostlsseg, lnp2, tlsosp)) {
3016dd94ecefSrie 				Shdr	*tlsshdr = tlsosp->os_shdr;
3017dd94ecefSrie 
3018dd94ecefSrie 				if (firstshdr == 0) {
3019dd94ecefSrie 					firstshdr = lastfilshdr = lastmemshdr =
3020dd94ecefSrie 					    tlsosp->os_shdr;
3021dd94ecefSrie 					continue;
30227c478bd9Sstevel@tonic-gate 				}
3023dd94ecefSrie 
3024dd94ecefSrie 				if (tlsshdr->sh_type == SHT_NOBITS)
3025dd94ecefSrie 					lastmemshdr = tlsshdr;
3026dd94ecefSrie 				else
3027dd94ecefSrie 					lastfilshdr = tlsshdr;
30287c478bd9Sstevel@tonic-gate 			}
3029dd94ecefSrie 
3030dd94ecefSrie 			phdr->p_flags = PF_R | PF_W;
30317c478bd9Sstevel@tonic-gate 			phdr->p_vaddr = firstshdr->sh_addr;
30327c478bd9Sstevel@tonic-gate 			phdr->p_offset = firstshdr->sh_offset;
3033dd94ecefSrie 			phdr->p_align = firstshdr->sh_addralign;
3034dd94ecefSrie 			phdr->p_filesz = lastfilshdr->sh_offset +
3035dd94ecefSrie 			    lastfilshdr->sh_size - phdr->p_offset;
3036dd94ecefSrie 			phdr->p_memsz = lastmemshdr->sh_offset +
3037dd94ecefSrie 			    lastmemshdr->sh_size - phdr->p_offset;
3038dd94ecefSrie 
30395aefb655Srie 			DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp));
3040dd94ecefSrie 
30417c478bd9Sstevel@tonic-gate 			ofl->ofl_tlsphdr = phdr;
30427c478bd9Sstevel@tonic-gate 			ofl->ofl_phdr[phdrndx++] = *phdr;
30437c478bd9Sstevel@tonic-gate 			continue;
30447c478bd9Sstevel@tonic-gate 		}
30457c478bd9Sstevel@tonic-gate 
30467c478bd9Sstevel@tonic-gate 		/*
30477c478bd9Sstevel@tonic-gate 		 * If this is an empty segment declaration, it will occur after
30487c478bd9Sstevel@tonic-gate 		 * all other loadable segments, make sure the previous segment
30497c478bd9Sstevel@tonic-gate 		 * doesn't overlap. We do not do the check if we are generating
30507c478bd9Sstevel@tonic-gate 		 * a relocatable file.
30517c478bd9Sstevel@tonic-gate 		 */
30527c478bd9Sstevel@tonic-gate 		if (!(ofl->ofl_flags & FLG_OF_RELOBJ) &&
30537c478bd9Sstevel@tonic-gate 		    (sgp->sg_flags & FLG_SG_EMPTY)) {
30547c478bd9Sstevel@tonic-gate 			int i;
30557c478bd9Sstevel@tonic-gate 			Addr	v_e;
30567c478bd9Sstevel@tonic-gate 
30577c478bd9Sstevel@tonic-gate 			vaddr = phdr->p_vaddr;
30587c478bd9Sstevel@tonic-gate 			phdr->p_memsz = sgp->sg_length;
30595aefb655Srie 			DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp));
30607c478bd9Sstevel@tonic-gate 			ofl->ofl_phdr[phdrndx++] = *phdr;
30617c478bd9Sstevel@tonic-gate 
30627c478bd9Sstevel@tonic-gate 			if (phdr->p_type != PT_LOAD)
30637c478bd9Sstevel@tonic-gate 				continue;
30647c478bd9Sstevel@tonic-gate 
30657c478bd9Sstevel@tonic-gate 			v_e = vaddr + phdr->p_memsz;
30667c478bd9Sstevel@tonic-gate 			/*
30677c478bd9Sstevel@tonic-gate 			 * Check overlaps
30687c478bd9Sstevel@tonic-gate 			 */
30697c478bd9Sstevel@tonic-gate 			for (i = 0; i < phdrndx - 1; i++) {
30707c478bd9Sstevel@tonic-gate 				Addr 	p_s = (ofl->ofl_phdr[i]).p_vaddr;
30717c478bd9Sstevel@tonic-gate 				Addr 	p_e;
30727c478bd9Sstevel@tonic-gate 
30737c478bd9Sstevel@tonic-gate 				if ((ofl->ofl_phdr[i]).p_type != PT_LOAD)
30747c478bd9Sstevel@tonic-gate 					continue;
30757c478bd9Sstevel@tonic-gate 
30767c478bd9Sstevel@tonic-gate 				p_e = p_s + (ofl->ofl_phdr[i]).p_memsz;
30777c478bd9Sstevel@tonic-gate 				if (((p_s <= vaddr) && (p_e > vaddr)) ||
30787c478bd9Sstevel@tonic-gate 				    ((vaddr <= p_s) && (v_e > p_s)))
30795aefb655Srie 					eprintf(ofl->ofl_lml, ERR_WARNING,
30807c478bd9Sstevel@tonic-gate 					    MSG_INTL(MSG_UPD_SEGOVERLAP),
30815aefb655Srie 					    ofl->ofl_name, EC_ADDR(p_e),
30825aefb655Srie 					    sgp->sg_name, EC_ADDR(vaddr));
30837c478bd9Sstevel@tonic-gate 			}
30847c478bd9Sstevel@tonic-gate 			continue;
30857c478bd9Sstevel@tonic-gate 		}
30867c478bd9Sstevel@tonic-gate 
30877c478bd9Sstevel@tonic-gate 		/*
30887c478bd9Sstevel@tonic-gate 		 * Having processed any of the special program headers any
30897c478bd9Sstevel@tonic-gate 		 * remaining headers will be built to express individual
30907c478bd9Sstevel@tonic-gate 		 * segments.  Segments are only built if they have output
30917c478bd9Sstevel@tonic-gate 		 * section descriptors associated with them (ie. some form of
30927c478bd9Sstevel@tonic-gate 		 * input section has been matched to this segment).
30937c478bd9Sstevel@tonic-gate 		 */
30940bc07c75Srie 		if (sgp->sg_osdescs == NULL)
30957c478bd9Sstevel@tonic-gate 			continue;
30967c478bd9Sstevel@tonic-gate 
30977c478bd9Sstevel@tonic-gate 		/*
30987c478bd9Sstevel@tonic-gate 		 * Determine the segments offset and size from the section
30997c478bd9Sstevel@tonic-gate 		 * information provided from elf_update().
31007c478bd9Sstevel@tonic-gate 		 * Allow for multiple NOBITS sections.
31017c478bd9Sstevel@tonic-gate 		 */
31020bc07c75Srie 		osp = (Os_desc *)sgp->sg_osdescs->al_data[0];
310354d82594Sseizo 		hshdr = osp->os_shdr;
31047c478bd9Sstevel@tonic-gate 
31057c478bd9Sstevel@tonic-gate 		phdr->p_filesz = 0;
31067c478bd9Sstevel@tonic-gate 		phdr->p_memsz = 0;
31077c478bd9Sstevel@tonic-gate 		phdr->p_offset = offset = hshdr->sh_offset;
31080bc07c75Srie 
310954d82594Sseizo 		nobits = ((hshdr->sh_type == SHT_NOBITS) &&
31100bc07c75Srie 		    ((sgp->sg_flags & FLG_SG_PHREQ) == 0));
31110bc07c75Srie 
31120bc07c75Srie 		for (ALIST_TRAVERSE(sgp->sg_osdescs, off, ospp)) {
31130bc07c75Srie 			Shdr	*shdr;
31140bc07c75Srie 
31150bc07c75Srie 			osp = *ospp;
31160bc07c75Srie 			shdr = osp->os_shdr;
31177c478bd9Sstevel@tonic-gate 
31187c478bd9Sstevel@tonic-gate 			p_align = 0;
31197c478bd9Sstevel@tonic-gate 			if (shdr->sh_addralign > p_align)
31207c478bd9Sstevel@tonic-gate 				p_align = shdr->sh_addralign;
31210bc07c75Srie 
31227c478bd9Sstevel@tonic-gate 			offset = (Off)S_ROUND(offset, shdr->sh_addralign);
31237c478bd9Sstevel@tonic-gate 			offset += shdr->sh_size;
31240bc07c75Srie 
31257c478bd9Sstevel@tonic-gate 			if (shdr->sh_type != SHT_NOBITS) {
31267c478bd9Sstevel@tonic-gate 				if (nobits) {
31275aefb655Srie 					eprintf(ofl->ofl_lml, ERR_FATAL,
31287c478bd9Sstevel@tonic-gate 					    MSG_INTL(MSG_UPD_NOBITS));
31297c478bd9Sstevel@tonic-gate 					return (S_ERROR);
31307c478bd9Sstevel@tonic-gate 				}
31317c478bd9Sstevel@tonic-gate 				phdr->p_filesz = offset - phdr->p_offset;
313254d82594Sseizo 			} else if ((sgp->sg_flags & FLG_SG_PHREQ) == 0)
31337c478bd9Sstevel@tonic-gate 				nobits = TRUE;
31347c478bd9Sstevel@tonic-gate 		}
31357c478bd9Sstevel@tonic-gate 		phdr->p_memsz = offset - hshdr->sh_offset;
31367c478bd9Sstevel@tonic-gate 
31377c478bd9Sstevel@tonic-gate 		/*
31387c478bd9Sstevel@tonic-gate 		 * If this is PT_SUNWBSS, set alignment
31397c478bd9Sstevel@tonic-gate 		 */
31407c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_SUNWBSS)
31417c478bd9Sstevel@tonic-gate 			phdr->p_align = p_align;
31427c478bd9Sstevel@tonic-gate 
31437c478bd9Sstevel@tonic-gate 		/*
31447c478bd9Sstevel@tonic-gate 		 * If this is the first loadable segment of a dynamic object,
314570d3e49eSrie 		 * or an interpreter has been specified (a static object built
314670d3e49eSrie 		 * with an interpreter will still be given a PT_HDR entry), then
31477c478bd9Sstevel@tonic-gate 		 * compensate for the elf header and program header array.  Both
31487c478bd9Sstevel@tonic-gate 		 * of these are actually part of the loadable segment as they
314970d3e49eSrie 		 * may be inspected by the interpreter.  Adjust the segments
31507c478bd9Sstevel@tonic-gate 		 * size and offset accordingly.
31517c478bd9Sstevel@tonic-gate 		 */
31527c478bd9Sstevel@tonic-gate 		if ((_phdr == 0) && (phdr->p_type == PT_LOAD) &&
31537c478bd9Sstevel@tonic-gate 		    ((ofl->ofl_osinterp) || (flags & FLG_OF_DYNAMIC)) &&
31544899432aSab 		    (!(ofl->ofl_dtflags_1 & DF_1_NOHDR))) {
31557c478bd9Sstevel@tonic-gate 			size = (Addr)S_ROUND((phdrsz + ehdrsz),
31567c478bd9Sstevel@tonic-gate 			    hshdr->sh_addralign);
31577c478bd9Sstevel@tonic-gate 			phdr->p_offset -= size;
31587c478bd9Sstevel@tonic-gate 			phdr->p_filesz += size;
31597c478bd9Sstevel@tonic-gate 			phdr->p_memsz += size;
31607c478bd9Sstevel@tonic-gate 		}
31617c478bd9Sstevel@tonic-gate 
31627c478bd9Sstevel@tonic-gate 		/*
31637c478bd9Sstevel@tonic-gate 		 * If a segment size symbol is required (specified via a
31647c478bd9Sstevel@tonic-gate 		 * mapfile) update its value.
31657c478bd9Sstevel@tonic-gate 		 */
31667c478bd9Sstevel@tonic-gate 		if (sgp->sg_sizesym != NULL)
31677c478bd9Sstevel@tonic-gate 			sgp->sg_sizesym->sd_sym->st_value = phdr->p_memsz;
31687c478bd9Sstevel@tonic-gate 
31697c478bd9Sstevel@tonic-gate 		/*
31707c478bd9Sstevel@tonic-gate 		 * If no file content has been assigned to this segment (it
31717c478bd9Sstevel@tonic-gate 		 * only contains no-bits sections), then reset the offset for
31727c478bd9Sstevel@tonic-gate 		 * consistency.
31737c478bd9Sstevel@tonic-gate 		 */
31747c478bd9Sstevel@tonic-gate 		if (phdr->p_filesz == 0)
31757c478bd9Sstevel@tonic-gate 			phdr->p_offset = 0;
31767c478bd9Sstevel@tonic-gate 
31777c478bd9Sstevel@tonic-gate 		/*
31787c478bd9Sstevel@tonic-gate 		 * If a virtual address has been specified for this segment
31797c478bd9Sstevel@tonic-gate 		 * (presumably from a map file) use it and make sure the
31807c478bd9Sstevel@tonic-gate 		 * previous segment does not run into this segment.
31817c478bd9Sstevel@tonic-gate 		 */
31827c478bd9Sstevel@tonic-gate 		if ((phdr->p_type == PT_LOAD) ||
31837c478bd9Sstevel@tonic-gate 		    (phdr->p_type == PT_SUNWBSS)) {
31847c478bd9Sstevel@tonic-gate 			if ((sgp->sg_flags & FLG_SG_VADDR)) {
31857c478bd9Sstevel@tonic-gate 				if (_phdr && (vaddr > phdr->p_vaddr) &&
31867c478bd9Sstevel@tonic-gate 				    (phdr->p_type == PT_LOAD))
31875aefb655Srie 					eprintf(ofl->ofl_lml, ERR_WARNING,
31887c478bd9Sstevel@tonic-gate 					    MSG_INTL(MSG_UPD_SEGOVERLAP),
31897c478bd9Sstevel@tonic-gate 					    ofl->ofl_name, EC_ADDR(vaddr),
31907c478bd9Sstevel@tonic-gate 					    sgp->sg_name,
31917c478bd9Sstevel@tonic-gate 					    EC_ADDR(phdr->p_vaddr));
31927c478bd9Sstevel@tonic-gate 				vaddr = phdr->p_vaddr;
31937c478bd9Sstevel@tonic-gate 				phdr->p_align = 0;
31947c478bd9Sstevel@tonic-gate 			} else {
31957c478bd9Sstevel@tonic-gate 				vaddr = phdr->p_vaddr =
31967c478bd9Sstevel@tonic-gate 				    (Addr)S_ROUND(vaddr, phdr->p_align);
31977c478bd9Sstevel@tonic-gate 			}
31987c478bd9Sstevel@tonic-gate 		}
31997c478bd9Sstevel@tonic-gate 
32007c478bd9Sstevel@tonic-gate 		/*
32017c478bd9Sstevel@tonic-gate 		 * Adjust the address offset and p_align if needed.
32027c478bd9Sstevel@tonic-gate 		 */
32034899432aSab 		if (!((ofl->ofl_flags1 & FLG_OF1_VADDR) ||
32044899432aSab 			(ofl->ofl_dtflags_1 & DF_1_NOHDR))) {
32057c478bd9Sstevel@tonic-gate 			if (phdr->p_align != 0)
32067c478bd9Sstevel@tonic-gate 				vaddr += phdr->p_offset % phdr->p_align;
32077c478bd9Sstevel@tonic-gate 			else
32087c478bd9Sstevel@tonic-gate 				vaddr += phdr->p_offset;
32097c478bd9Sstevel@tonic-gate 			phdr->p_vaddr = vaddr;
32107c478bd9Sstevel@tonic-gate 		}
32117c478bd9Sstevel@tonic-gate 
32127c478bd9Sstevel@tonic-gate 		/*
32137c478bd9Sstevel@tonic-gate 		 * If an interpreter is required set the virtual address of the
32147c478bd9Sstevel@tonic-gate 		 * PT_PHDR program header now that we know the virtual address
32157c478bd9Sstevel@tonic-gate 		 * of the loadable segment that contains it.  Update the
32167c478bd9Sstevel@tonic-gate 		 * PT_SUNWCAP header similarly.
32177c478bd9Sstevel@tonic-gate 		 */
32187c478bd9Sstevel@tonic-gate 		if ((_phdr == 0) && (phdr->p_type == PT_LOAD)) {
32197c478bd9Sstevel@tonic-gate 			_phdr = phdr;
32207c478bd9Sstevel@tonic-gate 
32214899432aSab 			if (!(ofl->ofl_dtflags_1 & DF_1_NOHDR)) {
32227c478bd9Sstevel@tonic-gate 				if (ofl->ofl_osinterp)
32237c478bd9Sstevel@tonic-gate 					ofl->ofl_phdr[0].p_vaddr =
32247c478bd9Sstevel@tonic-gate 					    vaddr + ehdrsz;
32257c478bd9Sstevel@tonic-gate 
32267c478bd9Sstevel@tonic-gate 				if (ofl->ofl_oscap)
32277c478bd9Sstevel@tonic-gate 				    ofl->ofl_phdr[capndx].p_vaddr = vaddr +
32287c478bd9Sstevel@tonic-gate 					ofl->ofl_phdr[capndx].p_offset;
32297c478bd9Sstevel@tonic-gate 
32307c478bd9Sstevel@tonic-gate 				/*
32317c478bd9Sstevel@tonic-gate 				 * Finally, if we're creating a dynamic object
323270d3e49eSrie 				 * (or a static object in which an interpreter
32337c478bd9Sstevel@tonic-gate 				 * is specified) update the vaddr to reflect
32347c478bd9Sstevel@tonic-gate 				 * the address of the first section within this
32357c478bd9Sstevel@tonic-gate 				 * segment.
32367c478bd9Sstevel@tonic-gate 				 */
32377c478bd9Sstevel@tonic-gate 				if ((ofl->ofl_osinterp) ||
32387c478bd9Sstevel@tonic-gate 				    (flags & FLG_OF_DYNAMIC))
32397c478bd9Sstevel@tonic-gate 					vaddr += size;
32407c478bd9Sstevel@tonic-gate 			} else {
32417c478bd9Sstevel@tonic-gate 				/*
32424899432aSab 				 * If the DF_1_NOHDR flag was set, PT_PHDR
32437c478bd9Sstevel@tonic-gate 				 * will not be part of any loadable segment.
32447c478bd9Sstevel@tonic-gate 				 */
32457c478bd9Sstevel@tonic-gate 				ofl->ofl_phdr[0].p_vaddr = 0;
32467c478bd9Sstevel@tonic-gate 				ofl->ofl_phdr[0].p_memsz = 0;
32477c478bd9Sstevel@tonic-gate 				ofl->ofl_phdr[0].p_flags = 0;
32487c478bd9Sstevel@tonic-gate 			}
32497c478bd9Sstevel@tonic-gate 		}
32507c478bd9Sstevel@tonic-gate 
32517c478bd9Sstevel@tonic-gate 		/*
3252c1c6f601Srie 		 * Ensure the ELF entry point defaults to zero.  Typically, this
3253c1c6f601Srie 		 * value is overridden in update_oehdr() to one of the standard
3254c1c6f601Srie 		 * entry points.  Historically, this default was set to the
3255c1c6f601Srie 		 * address of first executable section, but this has since been
3256c1c6f601Srie 		 * found to be more confusing than it is helpful.
32577c478bd9Sstevel@tonic-gate 		 */
3258c1c6f601Srie 		ehdr->e_entry = 0;
32597c478bd9Sstevel@tonic-gate 
32605aefb655Srie 		DBG_CALL(Dbg_seg_entry(ofl, segndx, sgp));
32617c478bd9Sstevel@tonic-gate 
32627c478bd9Sstevel@tonic-gate 		/*
32637c478bd9Sstevel@tonic-gate 		 * Traverse the output section descriptors for this segment so
32647c478bd9Sstevel@tonic-gate 		 * that we can update the section headers addresses.  We've
32657c478bd9Sstevel@tonic-gate 		 * calculated the virtual address of the initial section within
32667c478bd9Sstevel@tonic-gate 		 * this segment, so each successive section can be calculated
32677c478bd9Sstevel@tonic-gate 		 * based on their offsets from each other.
32687c478bd9Sstevel@tonic-gate 		 */
32697c478bd9Sstevel@tonic-gate 		secndx = 0;
32707c478bd9Sstevel@tonic-gate 		hshdr = 0;
32710bc07c75Srie 		for (ALIST_TRAVERSE(sgp->sg_osdescs, off, ospp)) {
32720bc07c75Srie 			Shdr	*shdr;
32730bc07c75Srie 
32740bc07c75Srie 			osp = *ospp;
32750bc07c75Srie 			shdr = osp->os_shdr;
32767c478bd9Sstevel@tonic-gate 
32777c478bd9Sstevel@tonic-gate 			if (shdr->sh_link)
32787c478bd9Sstevel@tonic-gate 			    shdr->sh_link =
32795aefb655Srie 				translate_link(ofl, osp, shdr->sh_link,
32807c478bd9Sstevel@tonic-gate 				MSG_INTL(MSG_FIL_INVSHLINK));
32817c478bd9Sstevel@tonic-gate 
32827c478bd9Sstevel@tonic-gate 			if (shdr->sh_info && (shdr->sh_flags & SHF_INFO_LINK))
32837c478bd9Sstevel@tonic-gate 			    shdr->sh_info =
32845aefb655Srie 				translate_link(ofl, osp, shdr->sh_info,
32857c478bd9Sstevel@tonic-gate 				MSG_INTL(MSG_FIL_INVSHINFO));
32867c478bd9Sstevel@tonic-gate 
32877c478bd9Sstevel@tonic-gate 			if (!(flags & FLG_OF_RELOBJ) &&
32887c478bd9Sstevel@tonic-gate 			    (phdr->p_type == PT_LOAD) ||
32897c478bd9Sstevel@tonic-gate 			    (phdr->p_type == PT_SUNWBSS)) {
32907c478bd9Sstevel@tonic-gate 				if (hshdr)
32917c478bd9Sstevel@tonic-gate 					vaddr += (shdr->sh_offset -
32927c478bd9Sstevel@tonic-gate 					    hshdr->sh_offset);
32937c478bd9Sstevel@tonic-gate 
32947c478bd9Sstevel@tonic-gate 				shdr->sh_addr = vaddr;
32957c478bd9Sstevel@tonic-gate 				hshdr = shdr;
32967c478bd9Sstevel@tonic-gate 			}
32977c478bd9Sstevel@tonic-gate 
32987c478bd9Sstevel@tonic-gate 			DBG_CALL(Dbg_seg_os(ofl, osp, secndx));
32997c478bd9Sstevel@tonic-gate 			secndx++;
33007c478bd9Sstevel@tonic-gate 		}
33017c478bd9Sstevel@tonic-gate 
33027c478bd9Sstevel@tonic-gate 		/*
33037c478bd9Sstevel@tonic-gate 		 * Establish the virtual address of the end of the last section
33047c478bd9Sstevel@tonic-gate 		 * in this segment so that the next segments offset can be
33057c478bd9Sstevel@tonic-gate 		 * calculated from this.
33067c478bd9Sstevel@tonic-gate 		 */
33077c478bd9Sstevel@tonic-gate 		if (hshdr)
33087c478bd9Sstevel@tonic-gate 			vaddr += hshdr->sh_size;
33097c478bd9Sstevel@tonic-gate 
33107c478bd9Sstevel@tonic-gate 		/*
33117c478bd9Sstevel@tonic-gate 		 * Output sections for this segment complete.  Adjust the
33127c478bd9Sstevel@tonic-gate 		 * virtual offset for the last sections size, and make sure we
33137c478bd9Sstevel@tonic-gate 		 * haven't exceeded any maximum segment length specification.
33147c478bd9Sstevel@tonic-gate 		 */
33157c478bd9Sstevel@tonic-gate 		if ((sgp->sg_length != 0) && (sgp->sg_length < phdr->p_memsz)) {
33165aefb655Srie 			eprintf(ofl->ofl_lml, ERR_FATAL,
33175aefb655Srie 			    MSG_INTL(MSG_UPD_LARGSIZE), ofl->ofl_name,
33185aefb655Srie 			    sgp->sg_name, EC_XWORD(phdr->p_memsz),
33197c478bd9Sstevel@tonic-gate 			    EC_XWORD(sgp->sg_length));
33207c478bd9Sstevel@tonic-gate 			return (S_ERROR);
33217c478bd9Sstevel@tonic-gate 		}
33227c478bd9Sstevel@tonic-gate 
33237c478bd9Sstevel@tonic-gate 		if (phdr->p_type == PT_NOTE) {
33247c478bd9Sstevel@tonic-gate 			phdr->p_vaddr = 0;
33257c478bd9Sstevel@tonic-gate 			phdr->p_paddr = 0;
33267c478bd9Sstevel@tonic-gate 			phdr->p_align = 0;
33277c478bd9Sstevel@tonic-gate 			phdr->p_memsz = 0;
33287c478bd9Sstevel@tonic-gate 		}
33297c478bd9Sstevel@tonic-gate 		if ((phdr->p_type != PT_NULL) && !(flags & FLG_OF_RELOBJ))
33307c478bd9Sstevel@tonic-gate 			ofl->ofl_phdr[phdrndx++] = *phdr;
33317c478bd9Sstevel@tonic-gate 	}
33327c478bd9Sstevel@tonic-gate 
33337c478bd9Sstevel@tonic-gate 	/*
33347c478bd9Sstevel@tonic-gate 	 * Update any new output sections.  When building the initial output
33357c478bd9Sstevel@tonic-gate 	 * image, a number of sections were created but left uninitialized (eg.
33367c478bd9Sstevel@tonic-gate 	 * .dynsym, .dynstr, .symtab, .symtab, etc.).  Here we update these
33377c478bd9Sstevel@tonic-gate 	 * sections with the appropriate data.  Other sections may still be
33387c478bd9Sstevel@tonic-gate 	 * modified via reloc_process().
33397c478bd9Sstevel@tonic-gate 	 *
334070d3e49eSrie 	 * Copy the interpreter name into the .interp section.
33417c478bd9Sstevel@tonic-gate 	 */
33427c478bd9Sstevel@tonic-gate 	if (ofl->ofl_interp)
33437c478bd9Sstevel@tonic-gate 		(void) strcpy((char *)ofl->ofl_osinterp->os_outdata->d_buf,
33447c478bd9Sstevel@tonic-gate 		    ofl->ofl_interp);
33457c478bd9Sstevel@tonic-gate 
33467c478bd9Sstevel@tonic-gate 	/*
33477c478bd9Sstevel@tonic-gate 	 * Update the .shstrtab, .strtab and .dynstr sections.
33487c478bd9Sstevel@tonic-gate 	 */
33497c478bd9Sstevel@tonic-gate 	update_ostrtab(ofl->ofl_osshstrtab, ofl->ofl_shdrsttab);
33507c478bd9Sstevel@tonic-gate 	update_ostrtab(ofl->ofl_osstrtab, ofl->ofl_strtab);
33517c478bd9Sstevel@tonic-gate 	update_ostrtab(ofl->ofl_osdynstr, ofl->ofl_dynstrtab);
33527c478bd9Sstevel@tonic-gate 
33537c478bd9Sstevel@tonic-gate 	/*
33547c478bd9Sstevel@tonic-gate 	 * Build any output symbol tables, the symbols information is copied
33557c478bd9Sstevel@tonic-gate 	 * and updated into the new output image.
33567c478bd9Sstevel@tonic-gate 	 */
33577c478bd9Sstevel@tonic-gate 	if ((etext = update_osym(ofl)) == (Addr)S_ERROR)
33587c478bd9Sstevel@tonic-gate 		return (S_ERROR);
33597c478bd9Sstevel@tonic-gate 
33607c478bd9Sstevel@tonic-gate 	/*
33617c478bd9Sstevel@tonic-gate 	 * If we have a PT_SUNWDTRACE phdr, update it now with the address of
33627c478bd9Sstevel@tonic-gate 	 * the symbol.  It's only now been updated via update_sym().
33637c478bd9Sstevel@tonic-gate 	 */
33647c478bd9Sstevel@tonic-gate 	if (dtracephdr && ofl->ofl_dtracesym) {
33657c478bd9Sstevel@tonic-gate 		Phdr		*pphdr;
33667c478bd9Sstevel@tonic-gate 		Sym_desc	*sdp = ofl->ofl_dtracesym;
33677c478bd9Sstevel@tonic-gate 
33687c478bd9Sstevel@tonic-gate 		dtracephdr->p_vaddr = sdp->sd_sym->st_value;
33697c478bd9Sstevel@tonic-gate 		dtracephdr->p_memsz = sdp->sd_sym->st_size;
33707c478bd9Sstevel@tonic-gate 
33717c478bd9Sstevel@tonic-gate 		/*
33727c478bd9Sstevel@tonic-gate 		 * Take permisions of the segment the symbol is associated with.
33737c478bd9Sstevel@tonic-gate 		 */
33747c478bd9Sstevel@tonic-gate 		pphdr = &sdp->sd_isc->is_osdesc->os_sgdesc->sg_phdr;
33757c478bd9Sstevel@tonic-gate 		assert(pphdr);
33767c478bd9Sstevel@tonic-gate 		dtracephdr->p_flags = pphdr->p_flags;
33777c478bd9Sstevel@tonic-gate 	}
33787c478bd9Sstevel@tonic-gate 
33797c478bd9Sstevel@tonic-gate 	/*
33807c478bd9Sstevel@tonic-gate 	 * Update the GROUP sections.
33817c478bd9Sstevel@tonic-gate 	 */
33827c478bd9Sstevel@tonic-gate 	if (update_ogroup(ofl) == S_ERROR)
33837c478bd9Sstevel@tonic-gate 		return (S_ERROR);
33847c478bd9Sstevel@tonic-gate 
33857c478bd9Sstevel@tonic-gate 	/*
33867c478bd9Sstevel@tonic-gate 	 * Update Move Table.
33877c478bd9Sstevel@tonic-gate 	 */
33887c478bd9Sstevel@tonic-gate 	if (ofl->ofl_osmove || ofl->ofl_issunwdata1) {
33897c478bd9Sstevel@tonic-gate 		if (update_move(ofl) == S_ERROR)
33907c478bd9Sstevel@tonic-gate 			return (S_ERROR);
33917c478bd9Sstevel@tonic-gate 	}
33927c478bd9Sstevel@tonic-gate 
33937c478bd9Sstevel@tonic-gate 	/*
33947c478bd9Sstevel@tonic-gate 	 * Build any output headers, version information, dynamic structure and
33957c478bd9Sstevel@tonic-gate 	 * syminfo structure.
33967c478bd9Sstevel@tonic-gate 	 */
33977c478bd9Sstevel@tonic-gate 	if (update_oehdr(ofl) == S_ERROR)
33987c478bd9Sstevel@tonic-gate 		return (S_ERROR);
33997c478bd9Sstevel@tonic-gate 	if ((flags & (FLG_OF_VERDEF | FLG_OF_NOVERSEC)) == FLG_OF_VERDEF)
34007c478bd9Sstevel@tonic-gate 		if (update_overdef(ofl) == S_ERROR)
34017c478bd9Sstevel@tonic-gate 			return (S_ERROR);
34027c478bd9Sstevel@tonic-gate 	if ((flags & (FLG_OF_VERNEED | FLG_OF_NOVERSEC)) == FLG_OF_VERNEED)
34037c478bd9Sstevel@tonic-gate 		if (update_overneed(ofl) == S_ERROR)
34047c478bd9Sstevel@tonic-gate 			return (S_ERROR);
34057c478bd9Sstevel@tonic-gate 	if (flags & FLG_OF_DYNAMIC) {
34067c478bd9Sstevel@tonic-gate 		if (update_odynamic(ofl) == S_ERROR)
34077c478bd9Sstevel@tonic-gate 			return (S_ERROR);
34087c478bd9Sstevel@tonic-gate 		if (ofl->ofl_ossyminfo)
34097c478bd9Sstevel@tonic-gate 			if (update_osyminfo(ofl) == S_ERROR)
34107c478bd9Sstevel@tonic-gate 				return (S_ERROR);
34117c478bd9Sstevel@tonic-gate 	}
34127c478bd9Sstevel@tonic-gate 
34137c478bd9Sstevel@tonic-gate 	/*
34147c478bd9Sstevel@tonic-gate 	 * Emit Strtab diagnostics.
34157c478bd9Sstevel@tonic-gate 	 */
34165aefb655Srie 	DBG_CALL(Dbg_sec_strtab(ofl->ofl_lml, ofl->ofl_osshstrtab,
34175aefb655Srie 	    ofl->ofl_shdrsttab));
34185aefb655Srie 	DBG_CALL(Dbg_sec_strtab(ofl->ofl_lml, ofl->ofl_osstrtab,
34195aefb655Srie 	    ofl->ofl_strtab));
34205aefb655Srie 	DBG_CALL(Dbg_sec_strtab(ofl->ofl_lml, ofl->ofl_osdynstr,
34215aefb655Srie 	    ofl->ofl_dynstrtab));
34227c478bd9Sstevel@tonic-gate 
34237c478bd9Sstevel@tonic-gate 	/*
34247c478bd9Sstevel@tonic-gate 	 * Initialize the section headers string table index within the elf
34257c478bd9Sstevel@tonic-gate 	 * header.
34267c478bd9Sstevel@tonic-gate 	 */
34277c478bd9Sstevel@tonic-gate 	/* LINTED */
34287c478bd9Sstevel@tonic-gate 	if ((shscnndx = elf_ndxscn(ofl->ofl_osshstrtab->os_scn)) <
34297c478bd9Sstevel@tonic-gate 	    SHN_LORESERVE) {
34305aefb655Srie 		ofl->ofl_nehdr->e_shstrndx =
34317c478bd9Sstevel@tonic-gate 		    /* LINTED */
34327c478bd9Sstevel@tonic-gate 		    (Half)shscnndx;
34337c478bd9Sstevel@tonic-gate 	} else {
34347c478bd9Sstevel@tonic-gate 		/*
34357c478bd9Sstevel@tonic-gate 		 * If the STRTAB section index doesn't fit into
34367c478bd9Sstevel@tonic-gate 		 * e_shstrndx, then we store it in 'shdr[0].st_link'.
34377c478bd9Sstevel@tonic-gate 		 */
34387c478bd9Sstevel@tonic-gate 		Elf_Scn	*scn;
34397c478bd9Sstevel@tonic-gate 		Shdr	*shdr0;
34405aefb655Srie 
34417c478bd9Sstevel@tonic-gate 		if ((scn = elf_getscn(ofl->ofl_elf, 0)) == NULL) {
34425aefb655Srie 			eprintf(ofl->ofl_lml, ERR_ELF,
34435aefb655Srie 			    MSG_INTL(MSG_ELF_GETSCN), ofl->ofl_name);
34447c478bd9Sstevel@tonic-gate 			return (S_ERROR);
34457c478bd9Sstevel@tonic-gate 		}
34467c478bd9Sstevel@tonic-gate 		if ((shdr0 = elf_getshdr(scn)) == NULL) {
34475aefb655Srie 			eprintf(ofl->ofl_lml, ERR_ELF,
34485aefb655Srie 			    MSG_INTL(MSG_ELF_GETSHDR), ofl->ofl_name);
34497c478bd9Sstevel@tonic-gate 			return (S_ERROR);
34507c478bd9Sstevel@tonic-gate 		}
34515aefb655Srie 		ofl->ofl_nehdr->e_shstrndx = SHN_XINDEX;
34527c478bd9Sstevel@tonic-gate 		shdr0->sh_link = shscnndx;
34537c478bd9Sstevel@tonic-gate 	}
34547c478bd9Sstevel@tonic-gate 
34557c478bd9Sstevel@tonic-gate 	return ((uintptr_t)etext);
34567c478bd9Sstevel@tonic-gate }
3457