xref: /onnv-gate/usr/src/cmd/sgs/elfdump/common/elfdump.c (revision 2352:9cdfed81bb1c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211324Srie 
220Sstevel@tonic-gate /*
231324Srie  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * Dump an elf file.
300Sstevel@tonic-gate  */
311618Srie #include	<machdep.h>
321618Srie #include	<sys/elf_386.h>
331618Srie #include	<sys/elf_amd64.h>
341618Srie #include	<sys/elf_SPARC.h>
351618Srie #include	<dwarf.h>
360Sstevel@tonic-gate #include	<unistd.h>
370Sstevel@tonic-gate #include	<errno.h>
380Sstevel@tonic-gate #include	<strings.h>
390Sstevel@tonic-gate #include	<debug.h>
400Sstevel@tonic-gate #include	<conv.h>
410Sstevel@tonic-gate #include	<msg.h>
421618Srie #include	<_elfdump.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate /*
450Sstevel@tonic-gate  * Focal point for verifying symbol names.
460Sstevel@tonic-gate  */
470Sstevel@tonic-gate static const char *
481618Srie string(Cache *refsec, Word ndx, Cache *strsec, const char *file, Word name)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate 	static Cache	*osec = 0;
510Sstevel@tonic-gate 	static int	nostr;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate 	const char	*strs = (char *)strsec->c_data->d_buf;
541618Srie 	Word		strn = strsec->c_data->d_size;
550Sstevel@tonic-gate 
560Sstevel@tonic-gate 	/*
571618Srie 	 * Only print a diagnostic regarding an empty string table once per
580Sstevel@tonic-gate 	 * input section being processed.
590Sstevel@tonic-gate 	 */
600Sstevel@tonic-gate 	if (osec != refsec) {
610Sstevel@tonic-gate 		osec = refsec;
620Sstevel@tonic-gate 		nostr = 0;
630Sstevel@tonic-gate 	}
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	/*
660Sstevel@tonic-gate 	 * Is the string table offset within range of the available strings?
670Sstevel@tonic-gate 	 */
680Sstevel@tonic-gate 	if (name >= strn) {
690Sstevel@tonic-gate 		/*
700Sstevel@tonic-gate 		 * Do we have a empty string table?
710Sstevel@tonic-gate 		 */
720Sstevel@tonic-gate 		if (strs == 0) {
730Sstevel@tonic-gate 			if (nostr == 0) {
740Sstevel@tonic-gate 				(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
750Sstevel@tonic-gate 				    file, strsec->c_name);
760Sstevel@tonic-gate 				nostr++;
770Sstevel@tonic-gate 			}
780Sstevel@tonic-gate 		} else {
790Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSTOFF),
801618Srie 			    file, refsec->c_name, EC_WORD(ndx), strsec->c_name,
811618Srie 			    EC_WORD(name), EC_WORD(strn - 1));
820Sstevel@tonic-gate 		}
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 		/*
850Sstevel@tonic-gate 		 * Return the empty string so that the calling function can
860Sstevel@tonic-gate 		 * continue it's output diagnostics.
870Sstevel@tonic-gate 		 */
880Sstevel@tonic-gate 		return (MSG_INTL(MSG_STR_UNKNOWN));
890Sstevel@tonic-gate 	}
900Sstevel@tonic-gate 	return (strs + name);
910Sstevel@tonic-gate }
920Sstevel@tonic-gate 
930Sstevel@tonic-gate /*
941618Srie  * Relocations can reference section symbols and standard symbols.  If the
951618Srie  * former, establish the section name.
961618Srie  */
971618Srie static const char *
981618Srie relsymname(Cache *cache, Cache *csec, Cache *strsec, Word symndx, Word symnum,
991618Srie     Word relndx, Sym *syms, char *secstr, size_t secsz, const char *file,
1001618Srie     uint_t flags)
1011618Srie {
1021618Srie 	Sym	*sym;
1031618Srie 
1041618Srie 	if (symndx >= symnum) {
1051618Srie 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_RELBADSYMNDX),
1061618Srie 		    file, EC_WORD(symndx), EC_WORD(relndx));
1071618Srie 		return (MSG_INTL(MSG_STR_UNKNOWN));
1081618Srie 	}
1091618Srie 
1101618Srie 	sym = (Sym *)(syms + symndx);
1111618Srie 
1121618Srie 	/*
1131618Srie 	 * If the symbol represents a section offset construct an appropriate
1141618Srie 	 * string.
1151618Srie 	 */
1161618Srie 	if ((ELF_ST_TYPE(sym->st_info) == STT_SECTION) && (sym->st_name == 0)) {
1171618Srie 		if (flags & FLG_LONGNAME)
1181618Srie 			(void) snprintf(secstr, secsz,
1191618Srie 			    MSG_INTL(MSG_STR_L_SECTION),
1201618Srie 			    cache[sym->st_shndx].c_name);
1211618Srie 		else
1221618Srie 			(void) snprintf(secstr, secsz,
1231618Srie 			    MSG_INTL(MSG_STR_SECTION),
1241618Srie 			    cache[sym->st_shndx].c_name);
1251618Srie 		return ((const char *)secstr);
1261618Srie 	}
1271618Srie 
1281618Srie 	return (string(csec, symndx, strsec, file, sym->st_name));
1291618Srie }
1301618Srie 
1311618Srie /*
1321618Srie  * Focal point for establishing a string table section.  Data such as the
1331618Srie  * dynamic information simply points to a string table.  Data such as
1341618Srie  * relocations, reference a symbol table, which in turn is associated with a
1351618Srie  * string table.
1360Sstevel@tonic-gate  */
1370Sstevel@tonic-gate static int
1381618Srie stringtbl(Cache *cache, int symtab, Word ndx, Word shnum, const char *file,
1391618Srie     Word *symnum, Cache **symsec, Cache **strsec)
1401618Srie {
1411618Srie 	Shdr	*shdr = cache[ndx].c_shdr;
1421618Srie 
1431618Srie 	if (symtab) {
1441618Srie 		/*
1451618Srie 		 * Validate the symbol table section.
1461618Srie 		 */
1471618Srie 		if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
1481618Srie 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
1491618Srie 			    file, cache[ndx].c_name, EC_WORD(shdr->sh_link));
1501618Srie 			return (0);
1511618Srie 		}
1521618Srie 
1531618Srie 		/*
1541618Srie 		 * Obtain, and verify the symbol table data.
1551618Srie 		 */
1561618Srie 		if (cache[ndx].c_data->d_buf == 0) {
1571618Srie 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
1581618Srie 			    file, cache[ndx].c_name);
1591618Srie 			return (0);
1601618Srie 		}
1611618Srie 
1621618Srie 		/*
1631618Srie 		 * Establish the string table index.
1641618Srie 		 */
1651618Srie 		ndx = shdr->sh_link;
1661618Srie 		shdr = cache[ndx].c_shdr;
1671618Srie 
1681618Srie 		/*
1691618Srie 		 * Return symbol table information.
1701618Srie 		 */
1711618Srie 		if (symnum)
1721618Srie 			*symnum = (shdr->sh_size / shdr->sh_entsize);
1731618Srie 		if (symsec)
1741618Srie 			*symsec = &cache[ndx];
1751618Srie 	}
1761618Srie 
1771618Srie 	/*
1781618Srie 	 * Validate the associated string table section.
1791618Srie 	 */
1801618Srie 	if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
1811618Srie 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
1821618Srie 		    file, cache[ndx].c_name, EC_WORD(shdr->sh_link));
1831618Srie 		return (0);
1841618Srie 	}
1851618Srie 
1861618Srie 	if (strsec)
1871618Srie 		*strsec = &cache[shdr->sh_link];
1881618Srie 
1891618Srie 	return (1);
1901618Srie }
1911618Srie 
1921618Srie /*
1931618Srie  * Lookup a symbol and set Sym accordingly.
1941618Srie  */
1951618Srie static int
1961618Srie symlookup(const char *name, Cache *cache, Word shnum, Sym **sym,
1970Sstevel@tonic-gate     Cache *symtab, const char *file)
1980Sstevel@tonic-gate {
1991618Srie 	Shdr	*shdr;
2001618Srie 	Word	symn, cnt;
2011618Srie 	Sym	*syms;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	if (symtab == 0)
2040Sstevel@tonic-gate 		return (0);
2050Sstevel@tonic-gate 
2061618Srie 	shdr = symtab->c_shdr;
2071618Srie 
2080Sstevel@tonic-gate 	/*
2090Sstevel@tonic-gate 	 * Determine the symbol data and number.
2100Sstevel@tonic-gate 	 */
2110Sstevel@tonic-gate 	if ((shdr->sh_entsize == 0) || (shdr->sh_size == 0)) {
2120Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
2130Sstevel@tonic-gate 		    file, symtab->c_name);
2140Sstevel@tonic-gate 		return (0);
2150Sstevel@tonic-gate 	}
2160Sstevel@tonic-gate 	/* LINTED */
2171618Srie 	symn = (Word)(shdr->sh_size / shdr->sh_entsize);
2181618Srie 	syms = (Sym *)symtab->c_data->d_buf;
2190Sstevel@tonic-gate 
2200Sstevel@tonic-gate 	/*
2210Sstevel@tonic-gate 	 * Get the associated string table section.
2220Sstevel@tonic-gate 	 */
2230Sstevel@tonic-gate 	if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
2240Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
2251618Srie 		    file, symtab->c_name, EC_WORD(shdr->sh_link));
2260Sstevel@tonic-gate 		return (0);
2270Sstevel@tonic-gate 	}
2280Sstevel@tonic-gate 
2290Sstevel@tonic-gate 	/*
2300Sstevel@tonic-gate 	 * Loop through the symbol table to find a match.
2310Sstevel@tonic-gate 	 */
2321618Srie 	for (cnt = 0; cnt < symn; syms++, cnt++) {
2331618Srie 		const char	*symname;
2340Sstevel@tonic-gate 
2351618Srie 		symname = string(symtab, cnt, &cache[shdr->sh_link], file,
2361618Srie 		    syms->st_name);
2370Sstevel@tonic-gate 
2381618Srie 		if (symname && (strcmp(name, symname) == 0)) {
2391618Srie 			*sym = syms;
2400Sstevel@tonic-gate 			return (1);
2410Sstevel@tonic-gate 		}
2420Sstevel@tonic-gate 	}
2430Sstevel@tonic-gate 	return (0);
2440Sstevel@tonic-gate }
2450Sstevel@tonic-gate 
2460Sstevel@tonic-gate /*
2470Sstevel@tonic-gate  * Print section headers.
2480Sstevel@tonic-gate  */
2490Sstevel@tonic-gate static void
2501618Srie sections(const char *file, Cache *cache, Word shnum, Ehdr *ehdr,
2511618Srie     const char *name)
2520Sstevel@tonic-gate {
2531618Srie 	size_t	seccnt;
2540Sstevel@tonic-gate 
2551618Srie 	for (seccnt = 1; seccnt < shnum; seccnt++) {
2561618Srie 		Cache		*_cache = &cache[seccnt];
2571618Srie 		Shdr		*shdr = _cache->c_shdr;
2581618Srie 		const char	*secname = _cache->c_name;
2590Sstevel@tonic-gate 
2601618Srie 		if (name && strcmp(name, secname))
2610Sstevel@tonic-gate 			continue;
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 		/*
2640Sstevel@tonic-gate 		 * Although numerous section header entries can be zero, it's
2650Sstevel@tonic-gate 		 * usually a sign of trouble if the name or type are zero.
2660Sstevel@tonic-gate 		 */
2670Sstevel@tonic-gate 		if (shdr->sh_type == 0) {
2680Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHTYPE),
2691618Srie 			    file, secname, EC_WORD(shdr->sh_type));
2700Sstevel@tonic-gate 		}
2710Sstevel@tonic-gate 		if (shdr->sh_name == 0) {
2720Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHNAME),
2731618Srie 			    file, secname, EC_XWORD(shdr->sh_name));
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate 			/*
2760Sstevel@tonic-gate 			 * Use the empty string, rather than the fabricated
2770Sstevel@tonic-gate 			 * name for the section output.
2780Sstevel@tonic-gate 			 */
2791618Srie 			secname = MSG_ORIG(MSG_STR_EMPTY);
2800Sstevel@tonic-gate 		}
2810Sstevel@tonic-gate 
2821324Srie 		/*
2831324Srie 		 * Identify any sections that are suspicious.  A .got section
2841324Srie 		 * shouldn't exist in a relocatable object.
2851324Srie 		 */
2861324Srie 		if (ehdr->e_type == ET_REL) {
2871618Srie 			if (strncmp(secname, MSG_ORIG(MSG_ELF_GOT),
2881324Srie 			    MSG_ELF_GOT_SIZE) == 0) {
2891324Srie 				(void) fprintf(stderr,
2901618Srie 				    MSG_INTL(MSG_GOT_UNEXPECTED), file,
2911618Srie 				    secname);
2921324Srie 			}
2931324Srie 		}
2941324Srie 
2951618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
2961618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SHDR), EC_WORD(seccnt), secname);
2971618Srie 		Elf_shdr(0, ehdr->e_machine, shdr);
2980Sstevel@tonic-gate 	}
2990Sstevel@tonic-gate }
3000Sstevel@tonic-gate 
3011618Srie /*
3021618Srie  * A couple of instances of unwind data are printed as tables of 8 data items
3031618Srie  * expressed as 0x?? integers.
3041618Srie  */
3051618Srie #define	UNWINDTBLSZ	10 + (8 * 5) + 1
3061618Srie 
3071618Srie static void
3081618Srie unwindtbl(uint64_t *ndx, uint_t len, uchar_t *data, uint64_t doff,
3091618Srie     const char *msg, const char *pre, size_t plen)
3101618Srie {
3111618Srie 	char	buffer[UNWINDTBLSZ];
3121618Srie 	uint_t	boff = plen, cnt = 0;
3131618Srie 
3141618Srie 	dbg_print(0, msg);
3151618Srie 	(void) strncpy(buffer, pre, UNWINDTBLSZ);
3161618Srie 
3171618Srie 	while (*ndx < (len + 4)) {
3181618Srie 		if (cnt == 8) {
3191618Srie 			dbg_print(0, buffer);
3201618Srie 			boff = plen;
3211618Srie 			cnt = 0;
3221618Srie 		}
3231618Srie 		(void) snprintf(&buffer[boff], UNWINDTBLSZ - boff,
3241618Srie 		    MSG_ORIG(MSG_UNW_TBLENTRY), data[doff + (*ndx)++]);
3251618Srie 		boff += 5;
3261618Srie 		cnt++;
3271618Srie 	}
3281618Srie 	if (cnt)
3291618Srie 		dbg_print(0, buffer);
3301618Srie }
3311618Srie 
3321618Srie /*
3331618Srie  * Obtain a specified Phdr entry.
3341618Srie  */
3351618Srie static Phdr *
3361618Srie getphdr(Word phnum, Word type, const char *file, Elf *elf)
3371618Srie {
3381618Srie 	Word	cnt;
3391618Srie 	Phdr	*phdr;
3401618Srie 
3411618Srie 	if ((phdr = elf_getphdr(elf)) == NULL) {
3421618Srie 		failure(file, MSG_ORIG(MSG_ELF_GETPHDR));
3431618Srie 		return (0);
3441618Srie 	}
3451618Srie 
3461618Srie 	for (cnt = 0; cnt < phnum; phdr++, cnt++) {
3471618Srie 		if (phdr->p_type == type)
3481618Srie 			return (phdr);
3491618Srie 	}
3501618Srie 	return (0);
3511618Srie }
3521618Srie 
3530Sstevel@tonic-gate static void
3541618Srie unwind(Cache *cache, Word shnum, Word phnum, Ehdr *ehdr, const char *name,
3551618Srie     const char *file, Elf *elf)
3560Sstevel@tonic-gate {
3571618Srie 	Word	cnt;
3581618Srie 	Phdr	*uphdr = 0;
3591618Srie 
3600Sstevel@tonic-gate 	/*
3611618Srie 	 * For the moment - UNWIND is only relevant for a AMD64 object.
3620Sstevel@tonic-gate 	 */
3630Sstevel@tonic-gate 	if (ehdr->e_machine != EM_AMD64)
3641618Srie 		return;
3650Sstevel@tonic-gate 
3661618Srie 	if (phnum)
3671618Srie 		uphdr = getphdr(phnum, PT_SUNW_UNWIND, file, elf);
3680Sstevel@tonic-gate 
3690Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
3701618Srie 		Cache		*_cache = &cache[cnt];
3711618Srie 		Shdr		*shdr = _cache->c_shdr;
3721618Srie 		uchar_t		*data;
3730Sstevel@tonic-gate 		size_t		datasize;
3741618Srie 		uint64_t	off, ndx, frame_ptr, fde_cnt, tabndx;
3751618Srie 		uint_t		vers, frame_ptr_enc, fde_cnt_enc, table_enc;
3760Sstevel@tonic-gate 
3770Sstevel@tonic-gate 		/*
3781618Srie 		 * AMD64 - this is a strmcp() just to find the gcc produced
3791618Srie 		 * sections.  Soon gcc should be setting the section type - and
3801618Srie 		 * we'll not need this strcmp().
3810Sstevel@tonic-gate 		 */
3820Sstevel@tonic-gate 		if ((shdr->sh_type != SHT_AMD64_UNWIND) &&
3830Sstevel@tonic-gate 		    (strncmp(_cache->c_name, MSG_ORIG(MSG_SCN_FRM),
3840Sstevel@tonic-gate 		    MSG_SCN_FRM_SIZE) != 0) &&
3850Sstevel@tonic-gate 		    (strncmp(_cache->c_name, MSG_ORIG(MSG_SCN_FRMHDR),
3860Sstevel@tonic-gate 		    MSG_SCN_FRMHDR_SIZE) != 0))
3870Sstevel@tonic-gate 			continue;
3880Sstevel@tonic-gate 		if (name && strcmp(name, _cache->c_name))
3890Sstevel@tonic-gate 			continue;
3900Sstevel@tonic-gate 
3911618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
3921618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_UNWIND), _cache->c_name);
3930Sstevel@tonic-gate 
3941618Srie 		data = (uchar_t *)(_cache->c_data->d_buf);
3950Sstevel@tonic-gate 		datasize = _cache->c_data->d_size;
3960Sstevel@tonic-gate 		off = 0;
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 		/*
3990Sstevel@tonic-gate 		 * Is this a .eh_frame_hdr
4000Sstevel@tonic-gate 		 */
4011618Srie 		if ((uphdr && (shdr->sh_addr == uphdr->p_vaddr)) ||
4020Sstevel@tonic-gate 		    (strncmp(_cache->c_name, MSG_ORIG(MSG_SCN_FRMHDR),
4031618Srie 		    MSG_SCN_FRMHDR_SIZE) == 0)) {
4041618Srie 
4051618Srie 			dbg_print(0, MSG_ORIG(MSG_UNW_FRMHDR));
4061618Srie 			ndx = 0;
4070Sstevel@tonic-gate 
4081618Srie 			vers = data[ndx++];
4091618Srie 			frame_ptr_enc = data[ndx++];
4101618Srie 			fde_cnt_enc = data[ndx++];
4111618Srie 			table_enc = data[ndx++];
4120Sstevel@tonic-gate 
4131618Srie 			dbg_print(0, MSG_ORIG(MSG_UNW_FRMVERS), vers);
4140Sstevel@tonic-gate 
4151618Srie 			frame_ptr = dwarf_ehe_extract(data, &ndx, frame_ptr_enc,
4161618Srie 			    ehdr->e_ident, shdr->sh_addr + ndx);
4170Sstevel@tonic-gate 
4181618Srie 			dbg_print(0, MSG_ORIG(MSG_UNW_FRPTRENC),
4191618Srie 			    conv_dwarf_ehe(frame_ptr_enc), EC_XWORD(frame_ptr));
4201618Srie 
4211618Srie 			fde_cnt = dwarf_ehe_extract(data, &ndx, fde_cnt_enc,
4221618Srie 			    ehdr->e_ident, shdr->sh_addr + ndx);
4230Sstevel@tonic-gate 
4241618Srie 			dbg_print(0, MSG_ORIG(MSG_UNW_FDCNENC),
4251618Srie 			    conv_dwarf_ehe(fde_cnt_enc), EC_XWORD(fde_cnt));
4261618Srie 			dbg_print(0, MSG_ORIG(MSG_UNW_TABENC),
4271618Srie 			    conv_dwarf_ehe(table_enc));
4281618Srie 			dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTAB1));
4291618Srie 			dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTAB2));
4300Sstevel@tonic-gate 
4311618Srie 			for (tabndx = 0; tabndx < fde_cnt; tabndx++) {
4321618Srie 				dbg_print(0, MSG_ORIG(MSG_UNW_BINSRTABENT),
4331618Srie 				    EC_XWORD(dwarf_ehe_extract(data, &ndx,
4341618Srie 				    table_enc, ehdr->e_ident, shdr->sh_addr)),
4351618Srie 				    EC_XWORD(dwarf_ehe_extract(data, &ndx,
4361618Srie 				    table_enc, ehdr->e_ident, shdr->sh_addr)));
4371618Srie 			}
4381618Srie 			continue;
4390Sstevel@tonic-gate 		}
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 		/*
4420Sstevel@tonic-gate 		 * Walk the Eh_frame's
4430Sstevel@tonic-gate 		 */
4440Sstevel@tonic-gate 		while (off < datasize) {
4450Sstevel@tonic-gate 			uint_t		cieid, cielength, cieversion,
4460Sstevel@tonic-gate 					cieretaddr;
4471618Srie 			int		cieRflag, cieLflag, ciePflag, cieZflag;
4481618Srie 			uint_t		cieaugndx, length, id;
4490Sstevel@tonic-gate 			uint64_t	ciecalign, ciedalign;
4500Sstevel@tonic-gate 			char		*cieaugstr;
4510Sstevel@tonic-gate 
4520Sstevel@tonic-gate 			ndx = 0;
4530Sstevel@tonic-gate 			/*
4540Sstevel@tonic-gate 			 * extract length in lsb format
4550Sstevel@tonic-gate 			 */
4560Sstevel@tonic-gate 			length = LSB32EXTRACT(data + off + ndx);
4570Sstevel@tonic-gate 			ndx += 4;
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate 			/*
4600Sstevel@tonic-gate 			 * extract CIE id in lsb format
4610Sstevel@tonic-gate 			 */
4620Sstevel@tonic-gate 			id = LSB32EXTRACT(data + off + ndx);
4630Sstevel@tonic-gate 			ndx += 4;
4640Sstevel@tonic-gate 
4650Sstevel@tonic-gate 			/*
4661618Srie 			 * A CIE record has a id of '0', otherwise this is a
4671618Srie 			 * FDE entry and the 'id' is the CIE pointer.
4680Sstevel@tonic-gate 			 */
4690Sstevel@tonic-gate 			if (id == 0) {
4700Sstevel@tonic-gate 				uint64_t    persVal;
4711618Srie 
4720Sstevel@tonic-gate 				cielength = length;
4730Sstevel@tonic-gate 				cieid = id;
4741618Srie 				cieLflag = ciePflag = cieRflag = cieZflag = 0;
4750Sstevel@tonic-gate 
4761618Srie 				dbg_print(0, MSG_ORIG(MSG_UNW_CIE),
4771618Srie 				    EC_XWORD(shdr->sh_addr + off));
4781618Srie 				dbg_print(0, MSG_ORIG(MSG_UNW_CIELNGTH),
4791618Srie 				    cielength, cieid);
4800Sstevel@tonic-gate 
4810Sstevel@tonic-gate 				cieversion = data[off + ndx];
4820Sstevel@tonic-gate 				ndx += 1;
4830Sstevel@tonic-gate 				cieaugstr = (char *)(&data[off + ndx]);
4840Sstevel@tonic-gate 				ndx += strlen(cieaugstr) + 1;
4851618Srie 
4861618Srie 				dbg_print(0, MSG_ORIG(MSG_UNW_CIEVERS),
4871618Srie 				    cieversion, cieaugstr);
4881618Srie 
4890Sstevel@tonic-gate 				ciecalign = uleb_extract(&data[off], &ndx);
4900Sstevel@tonic-gate 				ciedalign = sleb_extract(&data[off], &ndx);
4910Sstevel@tonic-gate 				cieretaddr = data[off + ndx];
4920Sstevel@tonic-gate 				ndx += 1;
4931618Srie 
4941618Srie 				dbg_print(0, MSG_ORIG(MSG_UNW_CIECALGN),
4951618Srie 				    EC_XWORD(ciecalign), EC_XWORD(ciedalign),
4961618Srie 				    cieretaddr);
4970Sstevel@tonic-gate 
4980Sstevel@tonic-gate 				if (cieaugstr[0])
4991618Srie 				    dbg_print(0, MSG_ORIG(MSG_UNW_CIEAUXVAL));
5001618Srie 
5010Sstevel@tonic-gate 				for (cieaugndx = 0; cieaugstr[cieaugndx];
5020Sstevel@tonic-gate 				    cieaugndx++) {
5030Sstevel@tonic-gate 					uint_t	val;
5041618Srie 
5050Sstevel@tonic-gate 					switch (cieaugstr[cieaugndx]) {
5060Sstevel@tonic-gate 					case 'z':
5070Sstevel@tonic-gate 					    val = uleb_extract(&data[off],
5080Sstevel@tonic-gate 						&ndx);
5091618Srie 					    dbg_print(0,
5100Sstevel@tonic-gate 						MSG_ORIG(MSG_UNW_CIEAUXSIZE),
5110Sstevel@tonic-gate 						val);
5120Sstevel@tonic-gate 					    cieZflag = 1;
5130Sstevel@tonic-gate 					    break;
5140Sstevel@tonic-gate 					case 'P':
5150Sstevel@tonic-gate 					    ciePflag = data[off + ndx];
5160Sstevel@tonic-gate 					    ndx += 1;
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate 					    persVal = dwarf_ehe_extract(
5190Sstevel@tonic-gate 						&data[off],
5200Sstevel@tonic-gate 						&ndx, ciePflag, ehdr->e_ident,
5210Sstevel@tonic-gate 						shdr->sh_addr + off + ndx);
5221618Srie 					    dbg_print(0,
5230Sstevel@tonic-gate 						MSG_ORIG(MSG_UNW_CIEAUXPERS),
5240Sstevel@tonic-gate 						ciePflag,
5251618Srie 						conv_dwarf_ehe(ciePflag),
5260Sstevel@tonic-gate 						EC_XWORD(persVal));
5270Sstevel@tonic-gate 					    break;
5280Sstevel@tonic-gate 					case 'R':
5290Sstevel@tonic-gate 					    val = data[off + ndx];
5300Sstevel@tonic-gate 					    ndx += 1;
5311618Srie 					    dbg_print(0,
5320Sstevel@tonic-gate 						MSG_ORIG(MSG_UNW_CIEAUXCENC),
5331618Srie 						val, conv_dwarf_ehe(val));
5340Sstevel@tonic-gate 					    cieRflag = val;
5350Sstevel@tonic-gate 					    break;
5360Sstevel@tonic-gate 					case 'L':
5370Sstevel@tonic-gate 					    val = data[off + ndx];
5380Sstevel@tonic-gate 					    ndx += 1;
5391618Srie 					    dbg_print(0,
5400Sstevel@tonic-gate 						MSG_ORIG(MSG_UNW_CIEAUXLSDA),
5411618Srie 						val, conv_dwarf_ehe(val));
5420Sstevel@tonic-gate 					    cieLflag = val;
5430Sstevel@tonic-gate 					    break;
5440Sstevel@tonic-gate 					default:
5451618Srie 					    dbg_print(0,
5460Sstevel@tonic-gate 						MSG_ORIG(MSG_UNW_CIEAUXUNEC),
5470Sstevel@tonic-gate 						cieaugstr[cieaugndx]);
5480Sstevel@tonic-gate 					    break;
5490Sstevel@tonic-gate 					}
5500Sstevel@tonic-gate 				}
5511618Srie 				if ((cielength + 4) > ndx)
5521618Srie 					unwindtbl(&ndx, cielength, data, off,
5531618Srie 					    MSG_ORIG(MSG_UNW_CIECFI),
5541618Srie 					    MSG_ORIG(MSG_UNW_CIEPRE),
5551618Srie 					    MSG_UNW_CIEPRE_SIZE);
5560Sstevel@tonic-gate 				off += cielength + 4;
5571618Srie 
5580Sstevel@tonic-gate 			} else {
5590Sstevel@tonic-gate 				uint_t	    fdelength = length;
5600Sstevel@tonic-gate 				int	    fdecieptr = id;
5610Sstevel@tonic-gate 				uint64_t    fdeinitloc, fdeaddrrange;
5620Sstevel@tonic-gate 
5631618Srie 				dbg_print(0, MSG_ORIG(MSG_UNW_FDE),
5641618Srie 				    EC_XWORD(shdr->sh_addr + off));
5651618Srie 				dbg_print(0, MSG_ORIG(MSG_UNW_FDELNGTH),
5660Sstevel@tonic-gate 				    fdelength, fdecieptr);
5671618Srie 
5680Sstevel@tonic-gate 				fdeinitloc = dwarf_ehe_extract(&data[off],
5690Sstevel@tonic-gate 				    &ndx, cieRflag, ehdr->e_ident,
5700Sstevel@tonic-gate 				    shdr->sh_addr + off + ndx);
5710Sstevel@tonic-gate 				fdeaddrrange = dwarf_ehe_extract(&data[off],
5720Sstevel@tonic-gate 				    &ndx, (cieRflag & ~DW_EH_PE_pcrel),
5730Sstevel@tonic-gate 				    ehdr->e_ident,
5740Sstevel@tonic-gate 				    shdr->sh_addr + off + ndx);
5751618Srie 
5761618Srie 				dbg_print(0, MSG_ORIG(MSG_UNW_FDEINITLOC),
5771618Srie 				    EC_XWORD(fdeinitloc),
5781618Srie 				    EC_XWORD(fdeaddrrange));
5791618Srie 
5800Sstevel@tonic-gate 				if (cieaugstr[0])
5811618Srie 					dbg_print(0,
5821618Srie 					    MSG_ORIG(MSG_UNW_FDEAUXVAL));
5830Sstevel@tonic-gate 				if (cieZflag) {
5840Sstevel@tonic-gate 					uint64_t    val;
5850Sstevel@tonic-gate 					val = uleb_extract(&data[off], &ndx);
5861618Srie 					dbg_print(0,
5871618Srie 					    MSG_ORIG(MSG_UNW_FDEAUXSIZE),
5881618Srie 					    EC_XWORD(val));
5890Sstevel@tonic-gate 					if (val & cieLflag) {
5900Sstevel@tonic-gate 					    fdeinitloc = dwarf_ehe_extract(
5910Sstevel@tonic-gate 						&data[off], &ndx, cieLflag,
5920Sstevel@tonic-gate 						ehdr->e_ident,
5930Sstevel@tonic-gate 						shdr->sh_addr + off + ndx);
5941618Srie 					    dbg_print(0,
5950Sstevel@tonic-gate 						MSG_ORIG(MSG_UNW_FDEAUXLSDA),
5961618Srie 						EC_XWORD(val));
5970Sstevel@tonic-gate 					}
5980Sstevel@tonic-gate 				}
5991618Srie 				if ((fdelength + 4) > ndx)
6001618Srie 					unwindtbl(&ndx, fdelength, data, off,
6011618Srie 					    MSG_ORIG(MSG_UNW_FDECFI),
6021618Srie 					    MSG_ORIG(MSG_UNW_FDEPRE),
6031618Srie 					    MSG_UNW_FDEPRE_SIZE);
6040Sstevel@tonic-gate 				off += fdelength + 4;
6050Sstevel@tonic-gate 			}
6060Sstevel@tonic-gate 		}
6070Sstevel@tonic-gate 	}
6080Sstevel@tonic-gate }
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate /*
6110Sstevel@tonic-gate  * Print the hardware/software capabilities.  For executables and shared objects
6120Sstevel@tonic-gate  * this should be accompanied with a program header.
6130Sstevel@tonic-gate  */
6140Sstevel@tonic-gate static void
6151618Srie cap(const char *file, Cache *cache, Word shnum, Word phnum, Ehdr *ehdr,
6161618Srie     Elf *elf)
6170Sstevel@tonic-gate {
6181618Srie 	Word		cnt;
6191618Srie 	Shdr *		cshdr = 0;
6200Sstevel@tonic-gate 	Cache *		ccache;
6211618Srie 	Off		cphdr_off = 0;
6221618Srie 	Xword		cphdr_sz;
6230Sstevel@tonic-gate 
6240Sstevel@tonic-gate 	/*
6250Sstevel@tonic-gate 	 * Determine if a hardware/software capabilities header exists.
6260Sstevel@tonic-gate 	 */
6271618Srie 	if (phnum) {
6281618Srie 		Phdr	*phdr;
6290Sstevel@tonic-gate 
6301618Srie 		if ((phdr = elf_getphdr(elf)) == NULL) {
6310Sstevel@tonic-gate 			failure(file, MSG_ORIG(MSG_ELF_GETPHDR));
6320Sstevel@tonic-gate 			return;
6330Sstevel@tonic-gate 		}
6340Sstevel@tonic-gate 
6351618Srie 		for (cnt = 0; cnt < phnum; phdr++, cnt++) {
6361618Srie 			if (phdr->p_type == PT_SUNWCAP) {
6371618Srie 				cphdr_off = phdr->p_offset;
6381618Srie 				cphdr_sz = phdr->p_filesz;
6391618Srie 				break;
6401618Srie 			}
6410Sstevel@tonic-gate 		}
6420Sstevel@tonic-gate 	}
6430Sstevel@tonic-gate 
6440Sstevel@tonic-gate 	/*
6450Sstevel@tonic-gate 	 * Determine if a hardware/software capabilities section exists.
6460Sstevel@tonic-gate 	 */
6470Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
6481618Srie 		Cache	*_cache = &cache[cnt];
6491618Srie 		Shdr	*shdr = _cache->c_shdr;
6500Sstevel@tonic-gate 
6510Sstevel@tonic-gate 		if (shdr->sh_type != SHT_SUNW_cap)
6520Sstevel@tonic-gate 			continue;
6530Sstevel@tonic-gate 
6540Sstevel@tonic-gate 		if (cphdr_off && ((cphdr_off < shdr->sh_offset) ||
6550Sstevel@tonic-gate 		    (cphdr_off + cphdr_sz) > (shdr->sh_offset + shdr->sh_size)))
6560Sstevel@tonic-gate 			continue;
6570Sstevel@tonic-gate 
6580Sstevel@tonic-gate 		ccache = _cache;
6590Sstevel@tonic-gate 		cshdr = shdr;
6600Sstevel@tonic-gate 		break;
6610Sstevel@tonic-gate 	}
6620Sstevel@tonic-gate 
6630Sstevel@tonic-gate 	if ((cshdr == 0) && (cphdr_off == 0))
6640Sstevel@tonic-gate 		return;
6650Sstevel@tonic-gate 
6660Sstevel@tonic-gate 	/*
6670Sstevel@tonic-gate 	 * Print the hardware/software capabilities section.
6680Sstevel@tonic-gate 	 */
6690Sstevel@tonic-gate 	if (cshdr) {
6701618Srie 		Word	ndx, capn;
6711618Srie 		Cap	*cap = (Cap *)ccache->c_data->d_buf;
6720Sstevel@tonic-gate 
6731618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
6741618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_CAP), ccache->c_name);
6750Sstevel@tonic-gate 
6761618Srie 		Elf_cap_title(0);
6771618Srie 
6781618Srie 		capn = (Word)(cshdr->sh_size / cshdr->sh_entsize);
6790Sstevel@tonic-gate 
6801618Srie 		for (ndx = 0; ndx < capn; cap++, ndx++) {
6811618Srie 			if (cap->c_tag != CA_SUNW_NULL)
6821618Srie 				Elf_cap_entry(0, cap, ndx, ehdr->e_machine);
6830Sstevel@tonic-gate 		}
6840Sstevel@tonic-gate 	} else
6850Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_WARN_INVCAP1), file);
6860Sstevel@tonic-gate 
6870Sstevel@tonic-gate 	/*
6880Sstevel@tonic-gate 	 * If this object is an executable or shared object, then the
6890Sstevel@tonic-gate 	 * hardware/software capabilities section should have an accompanying
6900Sstevel@tonic-gate 	 * program header.
6910Sstevel@tonic-gate 	 */
6920Sstevel@tonic-gate 	if (cshdr && ((ehdr->e_type == ET_EXEC) || (ehdr->e_type == ET_DYN))) {
6930Sstevel@tonic-gate 		if (cphdr_off == 0)
6940Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_WARN_INVCAP2),
6950Sstevel@tonic-gate 			    file, ccache->c_name);
6960Sstevel@tonic-gate 		else if ((cphdr_off != cshdr->sh_offset) ||
6970Sstevel@tonic-gate 		    (cphdr_sz != cshdr->sh_size))
6980Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_WARN_INVCAP3),
6990Sstevel@tonic-gate 			    file, ccache->c_name);
7000Sstevel@tonic-gate 	}
7010Sstevel@tonic-gate }
7020Sstevel@tonic-gate 
7030Sstevel@tonic-gate /*
7040Sstevel@tonic-gate  * Print the interpretor.
7050Sstevel@tonic-gate  */
7060Sstevel@tonic-gate static void
7071618Srie interp(const char *file, Cache *cache, Word shnum, Word phnum, Elf *elf)
7080Sstevel@tonic-gate {
7091618Srie 	Word	cnt;
7101618Srie 	Shdr	*ishdr = 0;
7111618Srie 	Cache	*icache;
7121618Srie 	Off	iphdr_off = 0;
7131618Srie 	Xword	iphdr_fsz;
7140Sstevel@tonic-gate 
7150Sstevel@tonic-gate 	/*
7160Sstevel@tonic-gate 	 * Determine if an interp header exists.
7170Sstevel@tonic-gate 	 */
7181618Srie 	if (phnum) {
7191618Srie 		Phdr	*phdr;
7200Sstevel@tonic-gate 
7211618Srie 		if ((phdr = getphdr(phnum, PT_INTERP, file, elf)) != 0) {
7221618Srie 			iphdr_off = phdr->p_offset;
7231618Srie 			iphdr_fsz = phdr->p_filesz;
7240Sstevel@tonic-gate 		}
7250Sstevel@tonic-gate 	}
7260Sstevel@tonic-gate 
7270Sstevel@tonic-gate 	if (iphdr_off == 0)
7280Sstevel@tonic-gate 		return;
7290Sstevel@tonic-gate 
7300Sstevel@tonic-gate 	/*
7310Sstevel@tonic-gate 	 * Determine if an interp section exists.
7320Sstevel@tonic-gate 	 */
7330Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
7341618Srie 		Cache	*_cache = &cache[cnt];
7351618Srie 		Shdr	*shdr = _cache->c_shdr;
7360Sstevel@tonic-gate 
7370Sstevel@tonic-gate 		/*
7380Sstevel@tonic-gate 		 * Scan sections to find a section which contains the PT_INTERP
7390Sstevel@tonic-gate 		 * string.  The target section can't be in a NOBITS section.
7400Sstevel@tonic-gate 		 */
7410Sstevel@tonic-gate 		if ((shdr->sh_type == SHT_NOBITS) ||
7420Sstevel@tonic-gate 		    (iphdr_off < shdr->sh_offset) ||
7431618Srie 		    (iphdr_off + iphdr_fsz) > (shdr->sh_offset + shdr->sh_size))
7440Sstevel@tonic-gate 			continue;
7450Sstevel@tonic-gate 
7460Sstevel@tonic-gate 		icache = _cache;
7470Sstevel@tonic-gate 		ishdr = shdr;
7480Sstevel@tonic-gate 		break;
7490Sstevel@tonic-gate 	}
7500Sstevel@tonic-gate 
7510Sstevel@tonic-gate 	/*
7520Sstevel@tonic-gate 	 * Print the interpreter string based on the offset defined in the
7530Sstevel@tonic-gate 	 * program header, as this is the offset used by the kernel.
7540Sstevel@tonic-gate 	 */
7550Sstevel@tonic-gate 	if (ishdr) {
7561618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
7571618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_INTERP), icache->c_name);
7581618Srie 		dbg_print(0, MSG_ORIG(MSG_FMT_INDENT),
7590Sstevel@tonic-gate 		    (char *)icache->c_data->d_buf +
7600Sstevel@tonic-gate 		    (iphdr_off - ishdr->sh_offset));
7610Sstevel@tonic-gate 	} else
7620Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_WARN_INVINTERP1), file);
7630Sstevel@tonic-gate 
7640Sstevel@tonic-gate 	/*
7650Sstevel@tonic-gate 	 * If there are any inconsistences between the program header and
7660Sstevel@tonic-gate 	 * section information, flag them.
7670Sstevel@tonic-gate 	 */
7680Sstevel@tonic-gate 	if (ishdr && ((iphdr_off != ishdr->sh_offset) ||
7691618Srie 	    (iphdr_fsz != ishdr->sh_size))) {
7700Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_WARN_INVINTERP2), file,
7710Sstevel@tonic-gate 		    icache->c_name);
7720Sstevel@tonic-gate 	}
7730Sstevel@tonic-gate }
7740Sstevel@tonic-gate 
7750Sstevel@tonic-gate /*
7760Sstevel@tonic-gate  * Print the syminfo section.
7770Sstevel@tonic-gate  */
7780Sstevel@tonic-gate static void
7791618Srie syminfo(Cache *cache, Word shnum, const char *file)
7800Sstevel@tonic-gate {
7811618Srie 	Shdr		*infoshdr;
7821618Srie 	Syminfo		*info;
7831618Srie 	Sym		*syms;
7841618Srie 	Dyn		*dyns;
7851618Srie 	Word		infonum, cnt, ndx, symnum;
7861618Srie 	Cache		*infocache = 0, *symsec, *strsec;
7870Sstevel@tonic-gate 
7880Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
7891618Srie 		if (cache[cnt].c_shdr->sh_type == SHT_SUNW_syminfo) {
7901618Srie 			infocache = &cache[cnt];
7910Sstevel@tonic-gate 			break;
7920Sstevel@tonic-gate 		}
7930Sstevel@tonic-gate 	}
7941618Srie 	if (infocache == 0)
7950Sstevel@tonic-gate 		return;
7960Sstevel@tonic-gate 
7971618Srie 	infoshdr = infocache->c_shdr;
7981618Srie 	if ((infoshdr->sh_entsize == 0) || (infoshdr->sh_size == 0)) {
7990Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
8001618Srie 		    file, infocache->c_name);
8010Sstevel@tonic-gate 		return;
8020Sstevel@tonic-gate 	}
8031618Srie 	infonum = (Word)(infoshdr->sh_size / infoshdr->sh_entsize);
8041618Srie 	info = (Syminfo *)infocache->c_data->d_buf;
8050Sstevel@tonic-gate 
8060Sstevel@tonic-gate 	/*
8070Sstevel@tonic-gate 	 * Get the data buffer of the associated dynamic section.
8080Sstevel@tonic-gate 	 */
8091618Srie 	if ((infoshdr->sh_info == 0) || (infoshdr->sh_info >= shnum)) {
8100Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHINFO),
8111618Srie 		    file, infocache->c_name, EC_WORD(infoshdr->sh_info));
8120Sstevel@tonic-gate 		return;
8130Sstevel@tonic-gate 	}
8141618Srie 	dyns = cache[infoshdr->sh_info].c_data->d_buf;
8151618Srie 	if (dyns == 0) {
8160Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
8171618Srie 		    file, cache[infoshdr->sh_info].c_name);
8180Sstevel@tonic-gate 		return;
8190Sstevel@tonic-gate 	}
8200Sstevel@tonic-gate 
8210Sstevel@tonic-gate 	/*
8221618Srie 	 * Get the data buffer for the associated symbol table and string table.
8230Sstevel@tonic-gate 	 */
8241618Srie 	if (stringtbl(cache, 1, cnt, shnum, file,
8251618Srie 	    &symnum, &symsec, &strsec) == 0)
8260Sstevel@tonic-gate 		return;
8270Sstevel@tonic-gate 
8281618Srie 	syms = symsec->c_data->d_buf;
8290Sstevel@tonic-gate 
8301618Srie 	/*
8311618Srie 	 * Loop through the syminfo entries.
8321618Srie 	 */
8331618Srie 	dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
8341618Srie 	dbg_print(0, MSG_INTL(MSG_ELF_SCN_SYMINFO), infocache->c_name);
8351618Srie 	Elf_syminfo_title(0);
8360Sstevel@tonic-gate 
8371618Srie 	for (ndx = 1, info++; ndx < infonum; ndx++, info++) {
8381618Srie 		Sym 		*sym;
8391618Srie 		const char	*needed = 0, *name;
8401618Srie 
8411618Srie 		if ((info->si_flags == 0) && (info->si_boundto == 0))
8420Sstevel@tonic-gate 			continue;
8430Sstevel@tonic-gate 
8441618Srie 		sym = &syms[ndx];
8451618Srie 		name = string(infocache, ndx, strsec, file, sym->st_name);
8460Sstevel@tonic-gate 
8471618Srie 		if (info->si_boundto < SYMINFO_BT_LOWRESERVE) {
8481618Srie 			Dyn	*dyn = &dyns[info->si_boundto];
8491618Srie 
8501618Srie 			needed = string(infocache, info->si_boundto,
8511618Srie 			    strsec, file, dyn->d_un.d_val);
8520Sstevel@tonic-gate 		}
8531618Srie 		Elf_syminfo_entry(0, ndx, info, name, needed);
8540Sstevel@tonic-gate 	}
8550Sstevel@tonic-gate }
8560Sstevel@tonic-gate 
8570Sstevel@tonic-gate /*
8580Sstevel@tonic-gate  * Print version definition section entries.
8590Sstevel@tonic-gate  */
8600Sstevel@tonic-gate static void
8611618Srie version_def(Verdef *vdf, Word shnum, Cache *vcache, Cache *scache,
8620Sstevel@tonic-gate     const char *file)
8630Sstevel@tonic-gate {
8641618Srie 	Word	cnt;
8651618Srie 	char	index[MAXNDXSIZE];
8660Sstevel@tonic-gate 
8671618Srie 	Elf_ver_def_title(0);
8680Sstevel@tonic-gate 
8690Sstevel@tonic-gate 	for (cnt = 1; cnt <= shnum; cnt++,
8701618Srie 	    vdf = (Verdef *)((uintptr_t)vdf + vdf->vd_next)) {
8710Sstevel@tonic-gate 		const char	*name, *dep;
8721618Srie 		Half		vcnt = vdf->vd_cnt - 1;
8731618Srie 		Half		ndx = vdf->vd_ndx;
8741618Srie 		Verdaux		*vdap = (Verdaux *)((uintptr_t)vdf +
8751618Srie 				    vdf->vd_aux);
8760Sstevel@tonic-gate 
8770Sstevel@tonic-gate 		/*
8780Sstevel@tonic-gate 		 * Obtain the name and first dependency (if any).
8790Sstevel@tonic-gate 		 */
8800Sstevel@tonic-gate 		name = string(vcache, cnt, scache, file, vdap->vda_name);
8811618Srie 		vdap = (Verdaux *)((uintptr_t)vdap + vdap->vda_next);
8820Sstevel@tonic-gate 		if (vcnt)
8830Sstevel@tonic-gate 			dep = string(vcache, cnt, scache, file, vdap->vda_name);
8840Sstevel@tonic-gate 		else
8850Sstevel@tonic-gate 			dep = MSG_ORIG(MSG_STR_EMPTY);
8860Sstevel@tonic-gate 
8870Sstevel@tonic-gate 		(void) snprintf(index, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INDEX),
8880Sstevel@tonic-gate 		    EC_XWORD(ndx));
8891618Srie 		Elf_ver_line_1(0, index, name, dep,
8901618Srie 		    conv_ver_flags(vdf->vd_flags));
8910Sstevel@tonic-gate 
8920Sstevel@tonic-gate 		/*
8930Sstevel@tonic-gate 		 * Print any additional dependencies.
8940Sstevel@tonic-gate 		 */
8950Sstevel@tonic-gate 		if (vcnt) {
8961618Srie 			vdap = (Verdaux *)((uintptr_t)vdap + vdap->vda_next);
8970Sstevel@tonic-gate 			for (vcnt--; vcnt; vcnt--,
8981618Srie 			    vdap = (Verdaux *)((uintptr_t)vdap +
8990Sstevel@tonic-gate 			    vdap->vda_next)) {
9000Sstevel@tonic-gate 				dep = string(vcache, cnt, scache, file,
9010Sstevel@tonic-gate 				    vdap->vda_name);
9021618Srie 				Elf_ver_line_2(0, MSG_ORIG(MSG_STR_EMPTY), dep);
9030Sstevel@tonic-gate 			}
9040Sstevel@tonic-gate 		}
9050Sstevel@tonic-gate 	}
9060Sstevel@tonic-gate }
9070Sstevel@tonic-gate 
9080Sstevel@tonic-gate /*
9090Sstevel@tonic-gate  * Print a version needed section entries.
9100Sstevel@tonic-gate  */
9110Sstevel@tonic-gate static void
9121618Srie version_need(Verneed *vnd, Word shnum, Cache *vcache, Cache *scache,
9130Sstevel@tonic-gate     const char *file)
9140Sstevel@tonic-gate {
9151618Srie 	Word	cnt;
9160Sstevel@tonic-gate 
9171618Srie 	Elf_ver_need_title(0);
9180Sstevel@tonic-gate 
9190Sstevel@tonic-gate 	for (cnt = 1; cnt <= shnum; cnt++,
9201618Srie 	    vnd = (Verneed *)((uintptr_t)vnd + vnd->vn_next)) {
9210Sstevel@tonic-gate 		const char	*name, *dep;
9221618Srie 		Half		vcnt = vnd->vn_cnt;
9231618Srie 		Vernaux		*vnap = (Vernaux *)((uintptr_t)vnd +
9241618Srie 					vnd->vn_aux);
9250Sstevel@tonic-gate 
9260Sstevel@tonic-gate 		/*
9270Sstevel@tonic-gate 		 * Obtain the name of the needed file and the version name
9280Sstevel@tonic-gate 		 * within it that we're dependent on.  Note that the count
9290Sstevel@tonic-gate 		 * should be at least one, otherwise this is a pretty bogus
9300Sstevel@tonic-gate 		 * entry.
9310Sstevel@tonic-gate 		 */
9320Sstevel@tonic-gate 		name = string(vcache, cnt, scache, file, vnd->vn_file);
9330Sstevel@tonic-gate 		if (vcnt)
9340Sstevel@tonic-gate 			dep = string(vcache, cnt, scache, file, vnap->vna_name);
9350Sstevel@tonic-gate 		else
9360Sstevel@tonic-gate 			dep = MSG_INTL(MSG_STR_NULL);
9370Sstevel@tonic-gate 
9381618Srie 		Elf_ver_line_1(0, MSG_ORIG(MSG_STR_EMPTY), name, dep,
9391618Srie 		    conv_ver_flags(vnap->vna_flags));
9400Sstevel@tonic-gate 
9410Sstevel@tonic-gate 		/*
9420Sstevel@tonic-gate 		 * Print any additional version dependencies.
9430Sstevel@tonic-gate 		 */
9440Sstevel@tonic-gate 		if (vcnt) {
9451618Srie 			vnap = (Vernaux *)((uintptr_t)vnap + vnap->vna_next);
9460Sstevel@tonic-gate 			for (vcnt--; vcnt; vcnt--,
9471618Srie 			    vnap = (Vernaux *)((uintptr_t)vnap +
9480Sstevel@tonic-gate 			    vnap->vna_next)) {
9490Sstevel@tonic-gate 				dep = string(vcache, cnt, scache, file,
9500Sstevel@tonic-gate 				    vnap->vna_name);
9511618Srie 				Elf_ver_line_3(0, MSG_ORIG(MSG_STR_EMPTY), dep,
9521618Srie 				    conv_ver_flags(vnap->vna_flags));
9530Sstevel@tonic-gate 			}
9540Sstevel@tonic-gate 		}
9550Sstevel@tonic-gate 	}
9560Sstevel@tonic-gate }
9570Sstevel@tonic-gate 
9580Sstevel@tonic-gate /*
9591618Srie  * Search for any version sections - the Versym output is possibly used by the
9601618Srie  * symbols() printing.  If VERSYM is specified - then display the version
9611618Srie  * information.
9620Sstevel@tonic-gate  */
9630Sstevel@tonic-gate static Cache *
9641618Srie versions(Cache *cache, Word shnum, const char *file, uint_t flags)
9650Sstevel@tonic-gate {
9660Sstevel@tonic-gate 	GElf_Word	cnt;
9670Sstevel@tonic-gate 	Cache		*versymcache = 0;
9680Sstevel@tonic-gate 
9690Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
9701618Srie 		void		*ver;
9710Sstevel@tonic-gate 		uint_t		num;
9721618Srie 		Cache		*_cache = &cache[cnt];
9731618Srie 		Shdr		*shdr = _cache->c_shdr;
9741618Srie 		const char	*secname = _cache->c_name;
9750Sstevel@tonic-gate 
9760Sstevel@tonic-gate 		/*
9770Sstevel@tonic-gate 		 * If this is the version symbol table simply record its
9780Sstevel@tonic-gate 		 * data address for possible use in later symbol processing.
9790Sstevel@tonic-gate 		 */
9800Sstevel@tonic-gate 		if (shdr->sh_type == SHT_SUNW_versym) {
9810Sstevel@tonic-gate 			versymcache = _cache;
9820Sstevel@tonic-gate 			continue;
9830Sstevel@tonic-gate 		}
9840Sstevel@tonic-gate 
9850Sstevel@tonic-gate 		if ((flags & FLG_VERSIONS) == 0)
9860Sstevel@tonic-gate 			continue;
9870Sstevel@tonic-gate 
9880Sstevel@tonic-gate 		if ((shdr->sh_type != SHT_SUNW_verdef) &&
9890Sstevel@tonic-gate 		    (shdr->sh_type != SHT_SUNW_verneed))
9900Sstevel@tonic-gate 			continue;
9910Sstevel@tonic-gate 
9920Sstevel@tonic-gate 		/*
9930Sstevel@tonic-gate 		 * Determine the version section data and number.
9940Sstevel@tonic-gate 		 */
9950Sstevel@tonic-gate 		if ((ver = (void *)_cache->c_data->d_buf) == 0) {
9960Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
9971618Srie 			    file, secname);
9980Sstevel@tonic-gate 			continue;
9990Sstevel@tonic-gate 		}
10000Sstevel@tonic-gate 		if ((num = shdr->sh_info) == 0) {
10010Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHINFO),
10021618Srie 			    file, secname, EC_WORD(shdr->sh_info));
10030Sstevel@tonic-gate 			continue;
10040Sstevel@tonic-gate 		}
10050Sstevel@tonic-gate 
10060Sstevel@tonic-gate 		/*
10070Sstevel@tonic-gate 		 * Get the data buffer for the associated string table.
10080Sstevel@tonic-gate 		 */
10090Sstevel@tonic-gate 		if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
10100Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
10111618Srie 			    file, secname, EC_WORD(shdr->sh_link));
10120Sstevel@tonic-gate 			continue;
10130Sstevel@tonic-gate 		}
10140Sstevel@tonic-gate 
10151618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
10160Sstevel@tonic-gate 		if (shdr->sh_type == SHT_SUNW_verdef) {
10171618Srie 			dbg_print(0, MSG_INTL(MSG_ELF_SCN_VERDEF), secname);
10181618Srie 			version_def((Verdef *)ver, num, _cache,
10190Sstevel@tonic-gate 			    &cache[shdr->sh_link], file);
10200Sstevel@tonic-gate 		} else if (shdr->sh_type == SHT_SUNW_verneed) {
10211618Srie 			dbg_print(0, MSG_INTL(MSG_ELF_SCN_VERNEED), secname);
10221618Srie 			version_need((Verneed *)ver, num, _cache,
10230Sstevel@tonic-gate 			    &cache[shdr->sh_link], file);
10240Sstevel@tonic-gate 		}
10250Sstevel@tonic-gate 	}
10260Sstevel@tonic-gate 	return (versymcache);
10270Sstevel@tonic-gate }
10280Sstevel@tonic-gate 
10290Sstevel@tonic-gate /*
10301618Srie  * Determine the extended section index used for symbol tables entries.
10311618Srie  */
10321618Srie static int
10331618Srie symbols_getxindex(Cache *cache, Word shnum, Word seccnt, Word **shxndx,
10341618Srie     uint_t *symnshxndx)
10351618Srie {
10361618Srie 	uint_t	symn;
10371618Srie 	Word	symcnt;
10381618Srie 
10391618Srie 	for (symcnt = 1; symcnt < shnum; symcnt++) {
10401618Srie 		Cache	*_cache = &cache[symcnt];
10411618Srie 		Shdr	*shdr = _cache->c_shdr;
10421618Srie 
10431618Srie 		if ((shdr->sh_type != SHT_SYMTAB_SHNDX) ||
10441618Srie 		    (shdr->sh_link != seccnt))
10451618Srie 			continue;
10461618Srie 
10471618Srie 		if ((shdr->sh_entsize) &&
10481618Srie 		    /* LINTED */
10491618Srie 		    ((symn = (uint_t)(shdr->sh_size / shdr->sh_entsize)) == 0))
10501618Srie 			continue;
10511618Srie 
10521618Srie 		*shxndx = _cache->c_data->d_buf;
10531618Srie 		*symnshxndx = symn;
10541618Srie 		return (0);
10551618Srie 	}
10561618Srie 	return (1);
10571618Srie }
10581618Srie 
10591618Srie /*
10600Sstevel@tonic-gate  * Search for and process any symbol tables.
10610Sstevel@tonic-gate  */
10621618Srie void
10631618Srie symbols(Cache *cache, Word shnum, Ehdr *ehdr, const char *name,
10641618Srie     Cache *versymcache, const char *file, uint_t flags)
10650Sstevel@tonic-gate {
10661618Srie 	Word	seccnt;
10671618Srie 	char	is_core = (ehdr->e_type == ET_CORE);
10680Sstevel@tonic-gate 
10691618Srie 	for (seccnt = 1; seccnt < shnum; seccnt++) {
10701618Srie 		Word		symn, symcnt, *shxndx;
10711618Srie 		Versym		*versym;
10721618Srie 		Cache		*_cache = &cache[seccnt];
10731618Srie 		Shdr		*shdr = _cache->c_shdr;
10741618Srie 		const char	*secname = _cache->c_name;
10751618Srie 		Sym 		*sym;
10761618Srie 		int		noshxndx;
10771618Srie 		uint_t		symnshxndx;
10780Sstevel@tonic-gate 
10790Sstevel@tonic-gate 		if ((shdr->sh_type != SHT_SYMTAB) &&
10800Sstevel@tonic-gate 		    (shdr->sh_type != SHT_DYNSYM))
10810Sstevel@tonic-gate 			continue;
10821618Srie 		if (name && strcmp(name, secname))
10830Sstevel@tonic-gate 			continue;
10840Sstevel@tonic-gate 
10850Sstevel@tonic-gate 		/*
10860Sstevel@tonic-gate 		 * Determine the symbol data and number.
10870Sstevel@tonic-gate 		 */
10880Sstevel@tonic-gate 		if ((shdr->sh_entsize == 0) || (shdr->sh_size == 0)) {
10890Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
10901618Srie 			    file, secname);
10910Sstevel@tonic-gate 			continue;
10920Sstevel@tonic-gate 		}
10930Sstevel@tonic-gate 		/* LINTED */
10941618Srie 		symn = (Word)(shdr->sh_size / shdr->sh_entsize);
10951618Srie 		sym = (Sym *)_cache->c_data->d_buf;
10960Sstevel@tonic-gate 
10970Sstevel@tonic-gate 		/*
10980Sstevel@tonic-gate 		 * Get the associated string table section.
10990Sstevel@tonic-gate 		 */
11000Sstevel@tonic-gate 		if ((shdr->sh_link == 0) || (shdr->sh_link >= shnum)) {
11010Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
11021618Srie 			    file, secname, EC_WORD(shdr->sh_link));
11030Sstevel@tonic-gate 			continue;
11040Sstevel@tonic-gate 		}
11050Sstevel@tonic-gate 
11060Sstevel@tonic-gate 		/*
11070Sstevel@tonic-gate 		 * Determine if there is a associated Versym section
11080Sstevel@tonic-gate 		 * with this Symbol Table.
11090Sstevel@tonic-gate 		 */
11101618Srie 		if (versymcache && (versymcache->c_shdr->sh_link == seccnt))
11110Sstevel@tonic-gate 			versym = versymcache->c_data->d_buf;
11120Sstevel@tonic-gate 		else
11130Sstevel@tonic-gate 			versym = 0;
11140Sstevel@tonic-gate 
11150Sstevel@tonic-gate 		/*
11160Sstevel@tonic-gate 		 * Loop through the symbol tables entries.
11170Sstevel@tonic-gate 		 */
11181618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
11191618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_SYMTAB), secname);
11201618Srie 		Elf_syms_table_title(0, ELF_DBG_ELFDUMP);
11210Sstevel@tonic-gate 
11221618Srie 		shxndx = 0;
11231618Srie 		noshxndx = 0;
11241618Srie 		symnshxndx = 0;
11251618Srie 		for (symcnt = 0; symcnt < symn; sym++, symcnt++) {
11261618Srie 			char		index[MAXNDXSIZE], *sec;
11271618Srie 			const char	*symname;
11280Sstevel@tonic-gate 			int		verndx;
11290Sstevel@tonic-gate 			uchar_t		type;
11301618Srie 			Shdr		*tshdr;
11310Sstevel@tonic-gate 			Word		shndx;
11320Sstevel@tonic-gate 
11330Sstevel@tonic-gate 			/*
11340Sstevel@tonic-gate 			 * If we are using extended symbol indexes, find the
11350Sstevel@tonic-gate 			 * corresponding SHN_SYMTAB_SHNDX table.
11360Sstevel@tonic-gate 			 */
11371618Srie 			if ((sym->st_shndx == SHN_XINDEX) &&
11381618Srie 			    (shxndx == 0) && (noshxndx == 0))
11391618Srie 				noshxndx = symbols_getxindex(cache, shnum,
11401618Srie 				    seccnt, &shxndx, &symnshxndx);
11410Sstevel@tonic-gate 
11420Sstevel@tonic-gate 			/* LINTED */
11431618Srie 			symname = string(_cache, symcnt, &cache[shdr->sh_link],
11441618Srie 			    file, sym->st_name);
11450Sstevel@tonic-gate 
11460Sstevel@tonic-gate 			tshdr = 0;
11470Sstevel@tonic-gate 			sec = NULL;
11480Sstevel@tonic-gate 
11490Sstevel@tonic-gate 			if (is_core)
11500Sstevel@tonic-gate 				sec = (char *)MSG_INTL(MSG_STR_UNKNOWN);
11511618Srie 			else if ((sym->st_shndx < SHN_LORESERVE) &&
11521618Srie 			    (sym->st_shndx < shnum)) {
11531618Srie 				shndx = sym->st_shndx;
11541618Srie 				tshdr = cache[shndx].c_shdr;
11550Sstevel@tonic-gate 				sec = cache[shndx].c_name;
11561618Srie 			} else if (sym->st_shndx == SHN_XINDEX) {
11571618Srie 				if (shxndx) {
11581618Srie 					Word	_shxndx;
11590Sstevel@tonic-gate 
11601618Srie 					if (symcnt > symnshxndx) {
11610Sstevel@tonic-gate 					    (void) fprintf(stderr,
11620Sstevel@tonic-gate 						MSG_INTL(MSG_ERR_BADSYMXINDEX1),
11631618Srie 						file, secname, EC_WORD(symcnt));
11641618Srie 					} else if ((_shxndx =
11651618Srie 					    shxndx[symcnt]) > shnum) {
11660Sstevel@tonic-gate 					    (void) fprintf(stderr,
11670Sstevel@tonic-gate 						MSG_INTL(MSG_ERR_BADSYMXINDEX2),
11681618Srie 						file, secname, EC_WORD(symcnt),
11691618Srie 						EC_WORD(_shxndx));
11700Sstevel@tonic-gate 					} else {
11711618Srie 					    shndx = _shxndx;
11721618Srie 					    tshdr = cache[shndx].c_shdr;
11730Sstevel@tonic-gate 					    sec = cache[shndx].c_name;
11740Sstevel@tonic-gate 					}
11750Sstevel@tonic-gate 				} else {
11760Sstevel@tonic-gate 					(void) fprintf(stderr,
11771618Srie 					    MSG_INTL(MSG_ERR_BADSYMXINDEX3),
11781618Srie 					    file, secname, EC_WORD(symcnt));
11790Sstevel@tonic-gate 				}
11801618Srie 			} else if ((sym->st_shndx < SHN_LORESERVE) &&
11811618Srie 			    (sym->st_shndx >= shnum)) {
11820Sstevel@tonic-gate 				(void) fprintf(stderr,
11831618Srie 				    MSG_INTL(MSG_ERR_BADSYM5), file,
11841618Srie 				    secname, demangle(symname, flags),
11851618Srie 				    sym->st_shndx);
11860Sstevel@tonic-gate 			}
11870Sstevel@tonic-gate 
11880Sstevel@tonic-gate 			/*
11890Sstevel@tonic-gate 			 * If versioning is available display the
11900Sstevel@tonic-gate 			 * version index.
11910Sstevel@tonic-gate 			 */
11920Sstevel@tonic-gate 			if (versym)
11931618Srie 				verndx = (int)versym[symcnt];
11940Sstevel@tonic-gate 			else
11950Sstevel@tonic-gate 				verndx = 0;
11960Sstevel@tonic-gate 
11970Sstevel@tonic-gate 			/*
11980Sstevel@tonic-gate 			 * Error checking for TLS.
11990Sstevel@tonic-gate 			 */
12001618Srie 			type = ELF_ST_TYPE(sym->st_info);
12010Sstevel@tonic-gate 			if (type == STT_TLS) {
12020Sstevel@tonic-gate 				if (tshdr &&
12031618Srie 				    (sym->st_shndx != SHN_UNDEF) &&
12040Sstevel@tonic-gate 				    ((tshdr->sh_flags & SHF_TLS) == 0)) {
12050Sstevel@tonic-gate 					(void) fprintf(stderr,
12060Sstevel@tonic-gate 					    MSG_INTL(MSG_ERR_BADSYM3), file,
12071618Srie 					    secname, demangle(symname, flags));
12080Sstevel@tonic-gate 				}
12091618Srie 			} else if ((type != STT_SECTION) && sym->st_size &&
12100Sstevel@tonic-gate 			    tshdr && (tshdr->sh_flags & SHF_TLS)) {
12110Sstevel@tonic-gate 				(void) fprintf(stderr,
12120Sstevel@tonic-gate 				    MSG_INTL(MSG_ERR_BADSYM4), file,
12131618Srie 				    secname, demangle(symname, flags));
12140Sstevel@tonic-gate 			}
12150Sstevel@tonic-gate 
12160Sstevel@tonic-gate 			/*
12170Sstevel@tonic-gate 			 * If a symbol has size, then make sure the section it
12180Sstevel@tonic-gate 			 * references is appropriate.  Note, UNDEF symbols that
12190Sstevel@tonic-gate 			 * have a size, have been known to exist - ignore them.
12200Sstevel@tonic-gate 			 */
12211618Srie 			if (sym->st_size && shndx && tshdr &&
12221618Srie 			    (tshdr->sh_size < sym->st_size)) {
12230Sstevel@tonic-gate 				(void) fprintf(stderr,
12240Sstevel@tonic-gate 				    MSG_INTL(MSG_ERR_BADSYM6), file,
12251618Srie 				    secname, demangle(symname, flags),
12261618Srie 				    EC_WORD(shndx), EC_XWORD(tshdr->sh_size),
12271618Srie 				    EC_XWORD(sym->st_size));
12280Sstevel@tonic-gate 			}
12290Sstevel@tonic-gate 
12300Sstevel@tonic-gate 			(void) snprintf(index, MAXNDXSIZE,
12311618Srie 			    MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(symcnt));
12321618Srie 			Elf_syms_table_entry(0, ELF_DBG_ELFDUMP, index,
12331618Srie 			    ehdr->e_machine, sym, verndx, sec, symname);
12340Sstevel@tonic-gate 		}
12350Sstevel@tonic-gate 	}
12360Sstevel@tonic-gate }
12370Sstevel@tonic-gate 
12380Sstevel@tonic-gate /*
12390Sstevel@tonic-gate  * Search for and process any relocation sections.
12400Sstevel@tonic-gate  */
12410Sstevel@tonic-gate static void
12421618Srie reloc(Cache *cache, Word shnum, Ehdr *ehdr, const char *name, const char *file,
12431618Srie     uint_t flags)
12440Sstevel@tonic-gate {
12451618Srie 	Word	cnt;
12460Sstevel@tonic-gate 
12470Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
12481618Srie 		Word		type, symnum;
12491618Srie 		Xword		relndx, relnum, relsize;
12501618Srie 		void		*rels;
12511618Srie 		Sym		*syms;
12521618Srie 		Cache		*symsec, *strsec;
12530Sstevel@tonic-gate 		Cache		*_cache = &cache[cnt];
12541618Srie 		Shdr		*shdr = _cache->c_shdr;
12551618Srie 		char		*relname = _cache->c_name;
12560Sstevel@tonic-gate 
12570Sstevel@tonic-gate 		if (((type = shdr->sh_type) != SHT_RELA) &&
12580Sstevel@tonic-gate 		    (type != SHT_REL))
12590Sstevel@tonic-gate 			continue;
12601618Srie 		if (name && strcmp(name, relname))
12610Sstevel@tonic-gate 			continue;
12620Sstevel@tonic-gate 
12630Sstevel@tonic-gate 		/*
12641618Srie 		 * Decide entry size.
12650Sstevel@tonic-gate 		 */
12661618Srie 		if (((relsize = shdr->sh_entsize) == 0) ||
12671618Srie 		    (relsize > shdr->sh_size)) {
12680Sstevel@tonic-gate 			if (type == SHT_RELA)
12691618Srie 				relsize = sizeof (Rela);
12700Sstevel@tonic-gate 			else
12711618Srie 				relsize = sizeof (Rel);
12720Sstevel@tonic-gate 		}
12730Sstevel@tonic-gate 
12740Sstevel@tonic-gate 		/*
12750Sstevel@tonic-gate 		 * Determine the number of relocations available.
12760Sstevel@tonic-gate 		 */
12770Sstevel@tonic-gate 		if (shdr->sh_size == 0) {
12780Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
12791618Srie 			    file, relname);
12800Sstevel@tonic-gate 			continue;
12810Sstevel@tonic-gate 		}
12821618Srie 		rels = _cache->c_data->d_buf;
12831618Srie 		relnum = shdr->sh_size / relsize;
12840Sstevel@tonic-gate 
12850Sstevel@tonic-gate 		/*
12861618Srie 		 * Get the data buffer for the associated symbol table and
12871618Srie 		 * string table.
12880Sstevel@tonic-gate 		 */
12891618Srie 		if (stringtbl(cache, 1, cnt, shnum, file,
12901618Srie 		    &symnum, &symsec, &strsec) == 0)
12910Sstevel@tonic-gate 			continue;
12921618Srie 
12931618Srie 		syms = symsec->c_data->d_buf;
12940Sstevel@tonic-gate 
12950Sstevel@tonic-gate 		/*
12960Sstevel@tonic-gate 		 * Loop through the relocation entries.
12970Sstevel@tonic-gate 		 */
12981618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
12991618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_RELOC), _cache->c_name);
13001618Srie 		Elf_reloc_title(0, ELF_DBG_ELFDUMP, type);
13010Sstevel@tonic-gate 
13021618Srie 		for (relndx = 0; relndx < relnum; relndx++,
13031618Srie 		    rels = (void *)((char *)rels + relsize)) {
13040Sstevel@tonic-gate 			char		section[BUFSIZ];
13051618Srie 			const char	*symname;
13061618Srie 			Word		symndx, reltype;
13071618Srie 			Rela		*rela;
13081618Srie 			Rel		*rel;
13090Sstevel@tonic-gate 
13100Sstevel@tonic-gate 			/*
13111618Srie 			 * Unravel the relocation and determine the symbol with
13121618Srie 			 * which this relocation is associated.
13130Sstevel@tonic-gate 			 */
13140Sstevel@tonic-gate 			if (type == SHT_RELA) {
13151618Srie 				rela = (Rela *)rels;
13161618Srie 				symndx = ELF_R_SYM(rela->r_info);
13171618Srie 				reltype = ELF_R_TYPE(rela->r_info);
13180Sstevel@tonic-gate 			} else {
13191618Srie 				rel = (Rel *)rels;
13201618Srie 				symndx = ELF_R_SYM(rel->r_info);
13211618Srie 				reltype = ELF_R_TYPE(rel->r_info);
13220Sstevel@tonic-gate 			}
13231618Srie 
13241618Srie 			symname = relsymname(cache, _cache, strsec, symndx,
13251618Srie 			    symnum, relndx, syms, section, BUFSIZ, file,
13261618Srie 			    flags);
13271618Srie 
13281618Srie 			/*
13291618Srie 			 * A zero symbol index is only valid for a few
13301618Srie 			 * relocations.
13311618Srie 			 */
13321618Srie 			if (symndx == 0) {
13331618Srie 				Half	mach = ehdr->e_machine;
13341618Srie 				int	badrel = 0;
13350Sstevel@tonic-gate 
13361618Srie 				if ((mach == EM_SPARC) ||
13371618Srie 				    (mach == EM_SPARC32PLUS) ||
13381618Srie 				    (mach == EM_SPARCV9)) {
13391618Srie 					if ((reltype != R_SPARC_NONE) &&
13401618Srie 					    (reltype != R_SPARC_REGISTER) &&
13411618Srie 					    (reltype != R_SPARC_RELATIVE))
13421618Srie 						badrel++;
13431618Srie 				} else if (mach == EM_386) {
13441618Srie 					if ((reltype != R_386_NONE) &&
13451618Srie 					    (reltype != R_386_RELATIVE))
13461618Srie 						badrel++;
13471618Srie 				} else if (mach == EM_AMD64) {
13481618Srie 					if ((reltype != R_AMD64_NONE) &&
13491618Srie 					    (reltype != R_AMD64_RELATIVE))
13501618Srie 						badrel++;
13511618Srie 				}
13521618Srie 
13531618Srie 				if (badrel) {
13541618Srie 					(void) fprintf(stderr,
13551618Srie 					    MSG_INTL(MSG_ERR_BADREL1), file,
13561976Sab196087 					    conv_reloc_type(mach, reltype, 0));
13570Sstevel@tonic-gate 				}
13580Sstevel@tonic-gate 			}
13590Sstevel@tonic-gate 
13601618Srie 			Elf_reloc_entry_1(0, ELF_DBG_ELFDUMP,
13611618Srie 			    MSG_ORIG(MSG_STR_EMPTY), ehdr->e_machine, type,
13621618Srie 			    rels, relname, symname, 0);
13630Sstevel@tonic-gate 		}
13640Sstevel@tonic-gate 	}
13650Sstevel@tonic-gate }
13660Sstevel@tonic-gate 
13670Sstevel@tonic-gate /*
13680Sstevel@tonic-gate  * Search for and process a .dynamic section.
13690Sstevel@tonic-gate  */
13700Sstevel@tonic-gate static void
13711618Srie dynamic(Cache *cache, Word shnum, Ehdr *ehdr, const char *file)
13720Sstevel@tonic-gate {
13731618Srie 	Word	cnt;
13740Sstevel@tonic-gate 
13750Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
13761618Srie 		Dyn	*dyn;
13771618Srie 		ulong_t	numdyn;
13781618Srie 		int	ndx;
13791618Srie 		Cache	*_cache = &cache[cnt], *strsec;
13801618Srie 		Shdr	*shdr = _cache->c_shdr;
13810Sstevel@tonic-gate 
13820Sstevel@tonic-gate 		if (shdr->sh_type != SHT_DYNAMIC)
13830Sstevel@tonic-gate 			continue;
13840Sstevel@tonic-gate 
13850Sstevel@tonic-gate 		/*
13861618Srie 		 * Verify the associated string table section.
13870Sstevel@tonic-gate 		 */
13881618Srie 		if (stringtbl(cache, 0, cnt, shnum, file, 0, 0, &strsec) == 0)
13890Sstevel@tonic-gate 			continue;
13901618Srie 
13910Sstevel@tonic-gate 		numdyn = shdr->sh_size / shdr->sh_entsize;
13921618Srie 		dyn = (Dyn *)_cache->c_data->d_buf;
13930Sstevel@tonic-gate 
13941618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
13951618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_DYNAMIC), _cache->c_name);
13960Sstevel@tonic-gate 
13971618Srie 		Elf_dyn_title(0);
13980Sstevel@tonic-gate 
13991618Srie 		for (ndx = 0; ndx < numdyn; dyn++, ndx++) {
14001618Srie 			const char	*name;
14010Sstevel@tonic-gate 
14020Sstevel@tonic-gate 			/*
14030Sstevel@tonic-gate 			 * Print the information numerically, and if possible
14040Sstevel@tonic-gate 			 * as a string.
14050Sstevel@tonic-gate 			 */
14061618Srie 			if ((dyn->d_tag == DT_NEEDED) ||
14071618Srie 			    (dyn->d_tag == DT_SONAME) ||
14081618Srie 			    (dyn->d_tag == DT_FILTER) ||
14091618Srie 			    (dyn->d_tag == DT_AUXILIARY) ||
14101618Srie 			    (dyn->d_tag == DT_CONFIG) ||
14111618Srie 			    (dyn->d_tag == DT_RPATH) ||
14121618Srie 			    (dyn->d_tag == DT_RUNPATH) ||
14131618Srie 			    (dyn->d_tag == DT_USED) ||
14141618Srie 			    (dyn->d_tag == DT_DEPAUDIT) ||
14151618Srie 			    (dyn->d_tag == DT_AUDIT) ||
14161618Srie 			    (dyn->d_tag == DT_SUNW_AUXILIARY) ||
14171618Srie 			    (dyn->d_tag == DT_SUNW_FILTER))
14181618Srie 				name = string(_cache, ndx, strsec,
14191618Srie 				    file, dyn->d_un.d_ptr);
14201618Srie 			else if (dyn->d_tag == DT_FLAGS)
1421*2352Sab196087 				name = conv_dyn_flag(dyn->d_un.d_val, 0);
14221618Srie 			else if (dyn->d_tag == DT_FLAGS_1)
14231618Srie 				name = conv_dyn_flag1(dyn->d_un.d_val);
14241618Srie 			else if (dyn->d_tag == DT_POSFLAG_1)
1425*2352Sab196087 				name = conv_dyn_posflag1(dyn->d_un.d_val, 0);
14261618Srie 			else if (dyn->d_tag == DT_FEATURE_1)
1427*2352Sab196087 				name = conv_dyn_feature1(dyn->d_un.d_val, 0);
14281618Srie 			else if (dyn->d_tag == DT_DEPRECATED_SPARC_REGISTER)
14291618Srie 				name = MSG_INTL(MSG_STR_DEPRECATED);
14300Sstevel@tonic-gate 			else
14311618Srie 				name = MSG_ORIG(MSG_STR_EMPTY);
14320Sstevel@tonic-gate 
14331618Srie 			Elf_dyn_entry(0, dyn, ndx, name, ehdr->e_machine);
14340Sstevel@tonic-gate 		}
14350Sstevel@tonic-gate 	}
14360Sstevel@tonic-gate }
14370Sstevel@tonic-gate 
14380Sstevel@tonic-gate /*
14390Sstevel@tonic-gate  * Search for and process a MOVE section.
14400Sstevel@tonic-gate  */
14410Sstevel@tonic-gate static void
14421618Srie move(Cache *cache, Word shnum, const char *name, const char *file, uint_t flags)
14430Sstevel@tonic-gate {
14441618Srie 	Word		cnt;
14451618Srie 	const char	*fmt = 0;
14460Sstevel@tonic-gate 
14470Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
14481618Srie 		Word	movenum, symnum, ndx;
14491618Srie 		Sym	*syms;
14501618Srie 		Cache	*_cache = &cache[cnt];
14511618Srie 		Shdr	*shdr = _cache->c_shdr;
14521618Srie 		Cache	*symsec, *strsec;
14531618Srie 		Move	*move;
14540Sstevel@tonic-gate 
14550Sstevel@tonic-gate 		if (shdr->sh_type != SHT_SUNW_move)
14560Sstevel@tonic-gate 			continue;
14570Sstevel@tonic-gate 		if (name && strcmp(name, _cache->c_name))
14580Sstevel@tonic-gate 			continue;
14590Sstevel@tonic-gate 
14600Sstevel@tonic-gate 		/*
14610Sstevel@tonic-gate 		 * Determine the move data and number.
14620Sstevel@tonic-gate 		 */
14630Sstevel@tonic-gate 		if ((shdr->sh_entsize == 0) || (shdr->sh_size == 0)) {
14640Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
14650Sstevel@tonic-gate 			    file, _cache->c_name);
14660Sstevel@tonic-gate 			continue;
14670Sstevel@tonic-gate 		}
14681618Srie 		move = (Move *)_cache->c_data->d_buf;
14691618Srie 		movenum = shdr->sh_size / shdr->sh_entsize;
14700Sstevel@tonic-gate 
14710Sstevel@tonic-gate 		/*
14721618Srie 		 * Get the data buffer for the associated symbol table and
14731618Srie 		 * string table.
14740Sstevel@tonic-gate 		 */
14751618Srie 		if (stringtbl(cache, 1, cnt, shnum, file,
14761618Srie 		    &symnum, &symsec, &strsec) == 0)
14771618Srie 			return;
14781618Srie 
14791618Srie 		syms = (Sym *)symsec->c_data->d_buf;
14800Sstevel@tonic-gate 
14811618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
14821618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_MOVE), _cache->c_name);
14831618Srie 		dbg_print(0, MSG_INTL(MSG_MOVE_TITLE));
14840Sstevel@tonic-gate 
14851618Srie 		if (fmt == 0)
14861618Srie 			fmt = MSG_INTL(MSG_MOVE_ENTRY);
14870Sstevel@tonic-gate 
14881618Srie 		for (ndx = 0; ndx < movenum; move++, ndx++) {
14891618Srie 			const char	*symname;
14901618Srie 			char		index[MAXNDXSIZE], section[BUFSIZ];
14911618Srie 			Word		symndx, shndx;
14921618Srie 			Sym		*sym;
14930Sstevel@tonic-gate 
14940Sstevel@tonic-gate 			/*
14950Sstevel@tonic-gate 			 * Check for null entries
14960Sstevel@tonic-gate 			 */
14971618Srie 			if ((move->m_info == 0) && (move->m_value == 0) &&
14981618Srie 			    (move->m_poffset == 0) && (move->m_repeat == 0) &&
14991618Srie 			    (move->m_stride == 0)) {
15001618Srie 				dbg_print(0, fmt, MSG_ORIG(MSG_STR_EMPTY),
15011618Srie 				    EC_XWORD(move->m_poffset), 0, 0, 0,
15021618Srie 				    EC_LWORD(0), MSG_ORIG(MSG_STR_EMPTY));
15030Sstevel@tonic-gate 				continue;
15040Sstevel@tonic-gate 			}
15051618Srie 			if (((symndx = ELF_M_SYM(move->m_info)) == 0) ||
15061618Srie 			    (symndx >= symnum)) {
15070Sstevel@tonic-gate 				(void) fprintf(stderr,
15080Sstevel@tonic-gate 				    MSG_INTL(MSG_ERR_BADMINFO), file,
15091618Srie 				    _cache->c_name, EC_XWORD(move->m_info));
15101618Srie 
15111618Srie 				(void) snprintf(index, MAXNDXSIZE,
15121618Srie 				    MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(symndx));
15131618Srie 				dbg_print(0, fmt, index,
15141618Srie 				    EC_XWORD(move->m_poffset),
15151618Srie 				    ELF_M_SIZE(move->m_info), move->m_repeat,
15161618Srie 				    move->m_stride, move->m_value,
15170Sstevel@tonic-gate 				    MSG_INTL(MSG_STR_UNKNOWN));
15180Sstevel@tonic-gate 				continue;
15190Sstevel@tonic-gate 			}
15200Sstevel@tonic-gate 
15211618Srie 			symname = relsymname(cache, _cache, strsec,
15221618Srie 			    symndx, symnum, ndx, syms, section, BUFSIZ, file,
15231618Srie 			    flags);
15241618Srie 			sym = (Sym *)(syms + symndx);
15250Sstevel@tonic-gate 
15260Sstevel@tonic-gate 			/*
15270Sstevel@tonic-gate 			 * Additional sanity check.
15280Sstevel@tonic-gate 			 */
15291618Srie 			shndx = sym->st_shndx;
15300Sstevel@tonic-gate 			if (!((shndx == SHN_COMMON) ||
15310Sstevel@tonic-gate 			    (((shndx >= 1) && (shndx <= shnum)) &&
15321618Srie 			    (cache[shndx].c_shdr)->sh_type == SHT_NOBITS))) {
15330Sstevel@tonic-gate 				(void) fprintf(stderr,
15341618Srie 				    MSG_INTL(MSG_ERR_BADSYM2), file,
15351618Srie 				    _cache->c_name, demangle(symname, flags));
15360Sstevel@tonic-gate 			}
15370Sstevel@tonic-gate 
15381618Srie 			(void) snprintf(index, MAXNDXSIZE,
15391618Srie 			    MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(symndx));
15401618Srie 			dbg_print(0, fmt, index, EC_XWORD(move->m_poffset),
15411618Srie 			    ELF_M_SIZE(move->m_info), move->m_repeat,
15421618Srie 			    move->m_stride, move->m_value,
15431618Srie 			    demangle(symname, flags));
15440Sstevel@tonic-gate 		}
15450Sstevel@tonic-gate 	}
15460Sstevel@tonic-gate }
15470Sstevel@tonic-gate 
15480Sstevel@tonic-gate /*
15490Sstevel@tonic-gate  * Traverse a note section analyzing each note information block.
15500Sstevel@tonic-gate  * The data buffers size is used to validate references before they are made,
15510Sstevel@tonic-gate  * and is decremented as each element is processed.
15520Sstevel@tonic-gate  */
15530Sstevel@tonic-gate void
15541618Srie note_entry(Cache *cache, Word *data, size_t size, const char *file)
15550Sstevel@tonic-gate {
15561618Srie 	size_t	bsize = size;
15571618Srie 
15580Sstevel@tonic-gate 	/*
15590Sstevel@tonic-gate 	 * Print out a single `note' information block.
15600Sstevel@tonic-gate 	 */
15610Sstevel@tonic-gate 	while (size > 0) {
15621618Srie 		size_t	namesz, descsz, type, pad, noteoff;
15630Sstevel@tonic-gate 
15640Sstevel@tonic-gate 		noteoff = bsize - size;
15650Sstevel@tonic-gate 		/*
15660Sstevel@tonic-gate 		 * Make sure we can at least reference the 3 initial entries
15670Sstevel@tonic-gate 		 * (4-byte words) of the note information block.
15680Sstevel@tonic-gate 		 */
15691618Srie 		if (size >= (sizeof (Word) * 3))
15701618Srie 			size -= (sizeof (Word) * 3);
15710Sstevel@tonic-gate 		else {
15721618Srie 			(void) fprintf(stderr, MSG_INTL(MSG_NOTE_BADDATASZ),
15731618Srie 			    file, cache->c_name, EC_WORD(noteoff));
15740Sstevel@tonic-gate 			return;
15750Sstevel@tonic-gate 		}
15760Sstevel@tonic-gate 
15770Sstevel@tonic-gate 		/*
15780Sstevel@tonic-gate 		 * Make sure any specified name string can be referenced.
15790Sstevel@tonic-gate 		 */
15800Sstevel@tonic-gate 		if ((namesz = *data++) != 0) {
15810Sstevel@tonic-gate 			if (size >= namesz)
15820Sstevel@tonic-gate 				size -= namesz;
15830Sstevel@tonic-gate 			else {
15840Sstevel@tonic-gate 				(void) fprintf(stderr,
15851618Srie 				    MSG_INTL(MSG_NOTE_BADNMSZ), file,
15861618Srie 				    cache->c_name, EC_WORD(noteoff),
15871618Srie 				    EC_WORD(namesz));
15880Sstevel@tonic-gate 				return;
15890Sstevel@tonic-gate 			}
15900Sstevel@tonic-gate 		}
15911618Srie 
15920Sstevel@tonic-gate 		/*
15930Sstevel@tonic-gate 		 * Make sure any specified descriptor can be referenced.
15940Sstevel@tonic-gate 		 */
15950Sstevel@tonic-gate 		if ((descsz = *data++) != 0) {
15960Sstevel@tonic-gate 			/*
15970Sstevel@tonic-gate 			 * If namesz isn't a 4-byte multiple, account for any
15980Sstevel@tonic-gate 			 * padding that must exist before the descriptor.
15990Sstevel@tonic-gate 			 */
16001618Srie 			if ((pad = (namesz & (sizeof (Word) - 1))) != 0) {
16011618Srie 				pad = sizeof (Word) - pad;
16020Sstevel@tonic-gate 				size -= pad;
16030Sstevel@tonic-gate 			}
16040Sstevel@tonic-gate 			if (size >= descsz)
16050Sstevel@tonic-gate 				size -= descsz;
16060Sstevel@tonic-gate 			else {
16070Sstevel@tonic-gate 				(void) fprintf(stderr,
16081618Srie 				    MSG_INTL(MSG_NOTE_BADDESZ), file,
16091618Srie 				    cache->c_name, EC_WORD(noteoff),
16101618Srie 				    EC_WORD(namesz));
16110Sstevel@tonic-gate 				return;
16120Sstevel@tonic-gate 			}
16130Sstevel@tonic-gate 		}
16140Sstevel@tonic-gate 
16150Sstevel@tonic-gate 		type = *data++;
16160Sstevel@tonic-gate 
16171618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
16181618Srie 		dbg_print(0, MSG_ORIG(MSG_NOTE_TYPE), EC_WORD(type));
16190Sstevel@tonic-gate 
16201618Srie 		dbg_print(0, MSG_ORIG(MSG_NOTE_NAMESZ), EC_WORD(namesz));
16210Sstevel@tonic-gate 		if (namesz) {
16220Sstevel@tonic-gate 			char	*name = (char *)data;
16230Sstevel@tonic-gate 
16240Sstevel@tonic-gate 			/*
16250Sstevel@tonic-gate 			 * Since the name string may have 'null' bytes
16260Sstevel@tonic-gate 			 * in it (ia32 .string) - we just write the
16270Sstevel@tonic-gate 			 * whole stream in a single fwrite.
16280Sstevel@tonic-gate 			 */
16290Sstevel@tonic-gate 			(void) fwrite(name, namesz, 1, stdout);
16300Sstevel@tonic-gate 			name = name + ((namesz + (sizeof (Word) - 1)) &
16310Sstevel@tonic-gate 			    ~(sizeof (Word) - 1));
16320Sstevel@tonic-gate 			/* LINTED */
16330Sstevel@tonic-gate 			data = (Word *)name;
16341618Srie 			dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
16350Sstevel@tonic-gate 		}
16360Sstevel@tonic-gate 
16370Sstevel@tonic-gate 		/*
16380Sstevel@tonic-gate 		 * If multiple information blocks exist within a .note section
16390Sstevel@tonic-gate 		 * account for any padding that must exist before the next
16400Sstevel@tonic-gate 		 * information block.
16410Sstevel@tonic-gate 		 */
16421618Srie 		if ((pad = (descsz & (sizeof (Word) - 1))) != 0) {
16431618Srie 			pad = sizeof (Word) - pad;
16440Sstevel@tonic-gate 			if (size > pad)
16450Sstevel@tonic-gate 				size -= pad;
16460Sstevel@tonic-gate 		}
16470Sstevel@tonic-gate 
16481618Srie 		dbg_print(0, MSG_ORIG(MSG_NOTE_DESCSZ), EC_WORD(descsz));
16490Sstevel@tonic-gate 		if (descsz) {
16500Sstevel@tonic-gate 			int		ndx, byte, word;
16511618Srie 			char		string[58], *str = string;
16520Sstevel@tonic-gate 			uchar_t		*desc = (uchar_t *)data;
16530Sstevel@tonic-gate 
16540Sstevel@tonic-gate 			/*
16550Sstevel@tonic-gate 			 * Dump descriptor bytes.
16560Sstevel@tonic-gate 			 */
16570Sstevel@tonic-gate 			for (ndx = byte = word = 0; descsz; descsz--, desc++) {
16580Sstevel@tonic-gate 				int	tok = *desc;
16590Sstevel@tonic-gate 
16600Sstevel@tonic-gate 				(void) snprintf(str, 58, MSG_ORIG(MSG_NOTE_TOK),
16610Sstevel@tonic-gate 				    tok);
16620Sstevel@tonic-gate 				str += 3;
16630Sstevel@tonic-gate 
16640Sstevel@tonic-gate 				if (++byte == 4) {
16650Sstevel@tonic-gate 					*str++ = ' ', *str++ = ' ';
16660Sstevel@tonic-gate 					word++;
16670Sstevel@tonic-gate 					byte = 0;
16680Sstevel@tonic-gate 				}
16690Sstevel@tonic-gate 				if (word == 4) {
16700Sstevel@tonic-gate 					*str = '\0';
16711618Srie 					dbg_print(0, MSG_ORIG(MSG_NOTE_DESC),
16720Sstevel@tonic-gate 					    ndx, string);
16730Sstevel@tonic-gate 					word = 0;
16740Sstevel@tonic-gate 					ndx += 16;
16750Sstevel@tonic-gate 					str = string;
16760Sstevel@tonic-gate 				}
16770Sstevel@tonic-gate 			}
16780Sstevel@tonic-gate 			if (byte || word) {
16790Sstevel@tonic-gate 				*str = '\0';
16801618Srie 				dbg_print(0, MSG_ORIG(MSG_NOTE_DESC),
16811618Srie 				    ndx, string);
16820Sstevel@tonic-gate 			}
16830Sstevel@tonic-gate 
16840Sstevel@tonic-gate 			desc += pad;
16850Sstevel@tonic-gate 			/* LINTED */
16860Sstevel@tonic-gate 			data = (Word *)desc;
16870Sstevel@tonic-gate 		}
16880Sstevel@tonic-gate 	}
16890Sstevel@tonic-gate }
16900Sstevel@tonic-gate 
16910Sstevel@tonic-gate /*
16920Sstevel@tonic-gate  * Search for and process a .note section.
16930Sstevel@tonic-gate  */
16940Sstevel@tonic-gate static void
16951618Srie note(Cache *cache, Word shnum, const char *name, const char *file)
16960Sstevel@tonic-gate {
16971618Srie 	Word	cnt;
16980Sstevel@tonic-gate 
16990Sstevel@tonic-gate 	/*
17000Sstevel@tonic-gate 	 * Otherwise look for any .note sections.
17010Sstevel@tonic-gate 	 */
17020Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
17031618Srie 		Cache	*_cache = &cache[cnt];
17041618Srie 		Shdr	*shdr = _cache->c_shdr;
17050Sstevel@tonic-gate 
17060Sstevel@tonic-gate 		if (shdr->sh_type != SHT_NOTE)
17070Sstevel@tonic-gate 			continue;
17080Sstevel@tonic-gate 		if (name && strcmp(name, _cache->c_name))
17090Sstevel@tonic-gate 			continue;
17100Sstevel@tonic-gate 
17110Sstevel@tonic-gate 		/*
17120Sstevel@tonic-gate 		 * As these sections are often hand rolled, make sure they're
17130Sstevel@tonic-gate 		 * properly aligned before proceeding.
17140Sstevel@tonic-gate 		 */
17150Sstevel@tonic-gate 		if (shdr->sh_offset & (sizeof (Word) - 1)) {
17160Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADALIGN),
17170Sstevel@tonic-gate 			    file, _cache->c_name);
17180Sstevel@tonic-gate 			continue;
17190Sstevel@tonic-gate 		}
17200Sstevel@tonic-gate 
17211618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
17221618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_NOTE), _cache->c_name);
17230Sstevel@tonic-gate 		note_entry(_cache, (Word *)_cache->c_data->d_buf,
17240Sstevel@tonic-gate 		/* LINTED */
17250Sstevel@tonic-gate 		    (Word)_cache->c_data->d_size, file);
17260Sstevel@tonic-gate 	}
17270Sstevel@tonic-gate }
17280Sstevel@tonic-gate 
17291618Srie /*
17301618Srie  * Determine an individual hash entry.  This may be the initial hash entry,
17311618Srie  * or an associated chain entry.
17321618Srie  */
17331618Srie static void
17341618Srie hash_entry(Cache *refsec, Cache *strsec, const char *hsecname, Word hashndx,
17351618Srie     Word symndx, Word symn, Sym *syms, const char *file, ulong_t bkts,
17361618Srie     uint_t flags, int chain)
17371618Srie {
17381618Srie 	Sym		*sym;
17391618Srie 	const char	*symname, *str;
17401618Srie 	char		_bucket[MAXNDXSIZE], _symndx[MAXNDXSIZE];
17411618Srie 	ulong_t		nbkt, nhash;
17421618Srie 
17431618Srie 	if (symndx > symn) {
17441618Srie 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_HSBADSYMNDX), file,
17451618Srie 		    EC_WORD(symndx), EC_WORD(hashndx));
17461618Srie 		symname = MSG_INTL(MSG_STR_UNKNOWN);
17471618Srie 	} else {
17481618Srie 		sym = (Sym *)(syms + symndx);
17491618Srie 		symname = string(refsec, symndx, strsec, file, sym->st_name);
17501618Srie 	}
17511618Srie 
17521618Srie 	if (chain == 0) {
17531618Srie 		(void) snprintf(_bucket, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INTEGER),
17541618Srie 		    hashndx);
17551618Srie 		str = (const char *)_bucket;
17561618Srie 	} else
17571618Srie 		str = MSG_ORIG(MSG_STR_EMPTY);
17581618Srie 
17591618Srie 	(void) snprintf(_symndx, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INDEX2),
17601618Srie 	    EC_WORD(symndx));
17611618Srie 	dbg_print(0, MSG_ORIG(MSG_FMT_HASH_INFO), str, _symndx,
17621618Srie 	    demangle(symname, flags));
17631618Srie 
17641618Srie 	/*
17651618Srie 	 * Determine if this string is in the correct bucket.
17661618Srie 	 */
17671618Srie 	nhash = elf_hash(symname);
17681618Srie 	nbkt = nhash % bkts;
17691618Srie 
17701618Srie 	if (nbkt != hashndx) {
17711618Srie 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADHASH), file,
17721618Srie 		    hsecname, symname, EC_WORD(hashndx), nbkt);
17731618Srie 	}
17741618Srie }
17750Sstevel@tonic-gate 
17760Sstevel@tonic-gate #define	MAXCOUNT	500
17770Sstevel@tonic-gate 
17780Sstevel@tonic-gate static void
17791618Srie hash(Cache *cache, Word shnum, const char *name, const char *file, uint_t flags)
17800Sstevel@tonic-gate {
17810Sstevel@tonic-gate 	static int	count[MAXCOUNT];
17821618Srie 	Word		cnt;
17830Sstevel@tonic-gate 	ulong_t		ndx, bkts;
17840Sstevel@tonic-gate 	char		number[MAXNDXSIZE];
17850Sstevel@tonic-gate 
17860Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
17870Sstevel@tonic-gate 		uint_t		*hash, *chain;
17880Sstevel@tonic-gate 		Cache		*_cache = &cache[cnt];
17891618Srie 		Shdr		*sshdr, *hshdr = _cache->c_shdr;
17901618Srie 		char		*ssecname, *hsecname = _cache->c_name;
17911618Srie 		Sym		*syms;
17921618Srie 		Word		symn;
17930Sstevel@tonic-gate 
17941618Srie 		if (hshdr->sh_type != SHT_HASH)
17950Sstevel@tonic-gate 			continue;
17961618Srie 		if (name && strcmp(name, hsecname))
17970Sstevel@tonic-gate 			continue;
17980Sstevel@tonic-gate 
17990Sstevel@tonic-gate 		/*
18000Sstevel@tonic-gate 		 * Determine the hash table data and size.
18010Sstevel@tonic-gate 		 */
18021618Srie 		if ((hshdr->sh_entsize == 0) || (hshdr->sh_size == 0)) {
18030Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
18041618Srie 			    file, hsecname);
18050Sstevel@tonic-gate 			continue;
18060Sstevel@tonic-gate 		}
18070Sstevel@tonic-gate 		hash = (uint_t *)_cache->c_data->d_buf;
18080Sstevel@tonic-gate 		bkts = *hash;
18090Sstevel@tonic-gate 		chain = hash + 2 + bkts;
18100Sstevel@tonic-gate 		hash += 2;
18110Sstevel@tonic-gate 
18120Sstevel@tonic-gate 		/*
18130Sstevel@tonic-gate 		 * Get the data buffer for the associated symbol table.
18140Sstevel@tonic-gate 		 */
18151618Srie 		if ((hshdr->sh_link == 0) || (hshdr->sh_link >= shnum)) {
18160Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
18171618Srie 			    file, hsecname, EC_WORD(hshdr->sh_link));
18180Sstevel@tonic-gate 			continue;
18190Sstevel@tonic-gate 		}
18201618Srie 
18211618Srie 		_cache = &cache[hshdr->sh_link];
18221618Srie 		ssecname = _cache->c_name;
18231618Srie 
18241618Srie 		if ((syms = (Sym *)_cache->c_data->d_buf) == 0) {
18250Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
18261618Srie 			    file, ssecname);
18270Sstevel@tonic-gate 			continue;
18280Sstevel@tonic-gate 		}
18290Sstevel@tonic-gate 
18301618Srie 		sshdr = _cache->c_shdr;
18311618Srie 		/* LINTED */
18321618Srie 		symn = (Word)(sshdr->sh_size / sshdr->sh_entsize);
18331618Srie 
18340Sstevel@tonic-gate 		/*
18350Sstevel@tonic-gate 		 * Get the associated string table section.
18360Sstevel@tonic-gate 		 */
18371618Srie 		if ((sshdr->sh_link == 0) || (sshdr->sh_link >= shnum)) {
18380Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHLINK),
18391618Srie 			    file, ssecname, EC_WORD(sshdr->sh_link));
18400Sstevel@tonic-gate 			continue;
18410Sstevel@tonic-gate 		}
18420Sstevel@tonic-gate 
18431618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
18441618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_HASH), hsecname);
18451618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_HASH_INFO));
18460Sstevel@tonic-gate 
18470Sstevel@tonic-gate 		/*
18480Sstevel@tonic-gate 		 * Loop through the hash buckets, printing the appropriate
18490Sstevel@tonic-gate 		 * symbols.
18500Sstevel@tonic-gate 		 */
18510Sstevel@tonic-gate 		for (ndx = 0; ndx < bkts; ndx++, hash++) {
18521618Srie 			Word	_ndx, _cnt;
18530Sstevel@tonic-gate 
18540Sstevel@tonic-gate 			if (*hash == 0) {
18550Sstevel@tonic-gate 				count[0]++;
18560Sstevel@tonic-gate 				continue;
18570Sstevel@tonic-gate 			}
18580Sstevel@tonic-gate 
18591618Srie 			hash_entry(_cache, &cache[sshdr->sh_link], hsecname,
18601618Srie 			    ndx, *hash, symn, syms, file, bkts, flags, 0);
18610Sstevel@tonic-gate 
18620Sstevel@tonic-gate 			/*
18630Sstevel@tonic-gate 			 * Determine if any other symbols are chained to this
18640Sstevel@tonic-gate 			 * bucket.
18650Sstevel@tonic-gate 			 */
18660Sstevel@tonic-gate 			_ndx = chain[*hash];
18670Sstevel@tonic-gate 			_cnt = 1;
18680Sstevel@tonic-gate 			while (_ndx) {
18691618Srie 				hash_entry(_cache, &cache[sshdr->sh_link],
18701618Srie 				    hsecname, ndx, _ndx, symn, syms, file,
18711618Srie 				    bkts, flags, 1);
18720Sstevel@tonic-gate 				_ndx = chain[_ndx];
18730Sstevel@tonic-gate 				_cnt++;
18740Sstevel@tonic-gate 			}
18750Sstevel@tonic-gate 
18760Sstevel@tonic-gate 			if (_cnt >= MAXCOUNT) {
18770Sstevel@tonic-gate 				(void) fprintf(stderr,
18781324Srie 				    MSG_INTL(MSG_HASH_OVERFLW), file,
18791618Srie 				    _cache->c_name, EC_WORD(ndx),
18801618Srie 				    EC_WORD(_cnt));
18810Sstevel@tonic-gate 			} else
18820Sstevel@tonic-gate 				count[_cnt]++;
18830Sstevel@tonic-gate 		}
18840Sstevel@tonic-gate 		break;
18850Sstevel@tonic-gate 	}
18860Sstevel@tonic-gate 
18870Sstevel@tonic-gate 	/*
18880Sstevel@tonic-gate 	 * Print out the count information.
18890Sstevel@tonic-gate 	 */
18900Sstevel@tonic-gate 	bkts = cnt = 0;
18911618Srie 	dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
18921618Srie 
18930Sstevel@tonic-gate 	for (ndx = 0; ndx < MAXCOUNT; ndx++) {
18941618Srie 		Word	_cnt;
18950Sstevel@tonic-gate 
18960Sstevel@tonic-gate 		if ((_cnt = count[ndx]) == 0)
18970Sstevel@tonic-gate 			continue;
18980Sstevel@tonic-gate 
18991618Srie 		(void) snprintf(number, MAXNDXSIZE,
19001618Srie 		    MSG_ORIG(MSG_FMT_INTEGER), _cnt);
19011618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_HASH_BKTS1), number,
19021618Srie 		    EC_WORD(ndx));
19030Sstevel@tonic-gate 		bkts += _cnt;
19041618Srie 		cnt += (Word)(ndx * _cnt);
19050Sstevel@tonic-gate 	}
19060Sstevel@tonic-gate 	if (cnt) {
19070Sstevel@tonic-gate 		(void) snprintf(number, MAXNDXSIZE, MSG_ORIG(MSG_FMT_INTEGER),
19081618Srie 		    bkts);
19091618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_HASH_BKTS2), number,
19101618Srie 		    EC_WORD(cnt));
19110Sstevel@tonic-gate 	}
19120Sstevel@tonic-gate }
19130Sstevel@tonic-gate 
19140Sstevel@tonic-gate static void
19151618Srie group(Cache *cache, Word shnum, const char *name, const char *file,
19161618Srie     uint_t flags)
19170Sstevel@tonic-gate {
19181618Srie 	Word	scnt;
19190Sstevel@tonic-gate 
19201618Srie 	for (scnt = 1; scnt < shnum; scnt++) {
19211618Srie 		Cache	*_cache = &cache[scnt];
19221618Srie 		Shdr	*shdr = _cache->c_shdr;
19231618Srie 		Word	*grpdata, gcnt, grpcnt, symnum, unknown;
19241618Srie 		Cache	*symsec, *strsec;
19251618Srie 		Sym	*syms, *sym;
19261618Srie 		char	flgstrbuf[MSG_GRP_COMDAT_SIZE + 10];
19270Sstevel@tonic-gate 
19280Sstevel@tonic-gate 		if (shdr->sh_type != SHT_GROUP)
19290Sstevel@tonic-gate 			continue;
19300Sstevel@tonic-gate 		if (name && strcmp(name, _cache->c_name))
19310Sstevel@tonic-gate 			continue;
19321618Srie 		if ((_cache->c_data == 0) ||
19331618Srie 		    ((grpdata = (Word *)_cache->c_data->d_buf) == 0))
19340Sstevel@tonic-gate 			continue;
19351618Srie 		grpcnt = shdr->sh_size / sizeof (Word);
19361618Srie 
19371618Srie 		/*
19381618Srie 		 * Get the data buffer for the associated symbol table and
19391618Srie 		 * string table.
19401618Srie 		 */
19411618Srie 		if (stringtbl(cache, 1, scnt, shnum, file,
19421618Srie 		    &symnum, &symsec, &strsec) == 0)
19431618Srie 			return;
19441618Srie 
19451618Srie 		syms = symsec->c_data->d_buf;
19461618Srie 
19471618Srie 		dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
19481618Srie 		dbg_print(0, MSG_INTL(MSG_ELF_SCN_GRP), _cache->c_name);
19491618Srie 		dbg_print(0, MSG_INTL(MSG_GRP_TITLE));
19501618Srie 
19511618Srie 		/*
19521618Srie 		 * The first element of the group defines the group.  The
19531618Srie 		 * associated symbol is defined by the sh_link field.
19541618Srie 		 */
19551618Srie 		if ((shdr->sh_info == SHN_UNDEF) || (shdr->sh_info > symnum)) {
19561618Srie 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSHINFO),
19571618Srie 			    file, _cache->c_name, EC_WORD(shdr->sh_info));
19581618Srie 			return;
19590Sstevel@tonic-gate 		}
19600Sstevel@tonic-gate 
19611618Srie 		(void) strcpy(flgstrbuf, MSG_ORIG(MSG_STR_OSQBRKT));
19621618Srie 		if (grpdata[0] & GRP_COMDAT) {
19631618Srie 			(void) strcat(flgstrbuf, MSG_ORIG(MSG_GRP_COMDAT));
19640Sstevel@tonic-gate 		}
19651618Srie 		if ((unknown = (grpdata[0] & ~GRP_COMDAT)) != 0) {
19661618Srie 			size_t	len = strlen(flgstrbuf);
19671618Srie 
19681618Srie 			(void) snprintf(&flgstrbuf[len],
19691618Srie 			    (MSG_GRP_COMDAT_SIZE + 10 - len),
19701618Srie 			    MSG_ORIG(MSG_GRP_UNKNOWN), unknown);
19710Sstevel@tonic-gate 		}
19721618Srie 		(void) strcat(flgstrbuf, MSG_ORIG(MSG_STR_CSQBRKT));
19731618Srie 		sym = (Sym *)(syms + shdr->sh_info);
19740Sstevel@tonic-gate 
19751618Srie 		dbg_print(0, MSG_INTL(MSG_GRP_SIGNATURE), flgstrbuf,
19761618Srie 		    demangle(string(_cache, 0, strsec, file, sym->st_name),
19771618Srie 		    flags));
19781618Srie 
19791618Srie 		for (gcnt = 1; gcnt < grpcnt; gcnt++) {
19800Sstevel@tonic-gate 			char		index[MAXNDXSIZE];
19811618Srie 			const char	*name;
19820Sstevel@tonic-gate 
19830Sstevel@tonic-gate 			(void) snprintf(index, MAXNDXSIZE,
19841618Srie 			    MSG_ORIG(MSG_FMT_INDEX), EC_XWORD(gcnt));
19851618Srie 
19861618Srie 			if (grpdata[gcnt] >= shnum)
19871618Srie 				name = MSG_INTL(MSG_GRP_INVALSCN);
19881618Srie 			else
19891618Srie 				name = cache[grpdata[gcnt]].c_name;
19901618Srie 
19911618Srie 			(void) printf(MSG_ORIG(MSG_GRP_ENTRY), index, name,
19921618Srie 				EC_XWORD(grpdata[gcnt]));
19930Sstevel@tonic-gate 		}
19940Sstevel@tonic-gate 	}
19950Sstevel@tonic-gate }
19960Sstevel@tonic-gate 
19970Sstevel@tonic-gate static void
19981618Srie got(Cache *cache, Word shnum, Ehdr *ehdr, const char *file, uint_t flags)
19990Sstevel@tonic-gate {
20000Sstevel@tonic-gate 	Cache		*gotcache = 0, *symtab = 0, *_cache;
20011618Srie 	Addr		gotbgn, gotend;
20021618Srie 	Shdr		*gotshdr;
20031618Srie 	Word		cnt, gotents, gotndx;
20040Sstevel@tonic-gate 	size_t		gentsize;
20050Sstevel@tonic-gate 	Got_info	*gottable;
20060Sstevel@tonic-gate 	char		*gotdata;
20071618Srie 	Sym		*gotsym;
20081618Srie 	Xword		gotsymaddr;
20090Sstevel@tonic-gate 
20100Sstevel@tonic-gate 	/*
20111324Srie 	 * First, find the got.
20120Sstevel@tonic-gate 	 */
20130Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
20140Sstevel@tonic-gate 		_cache = &cache[cnt];
20151324Srie 		if (strncmp(_cache->c_name, MSG_ORIG(MSG_ELF_GOT),
20161324Srie 		    MSG_ELF_GOT_SIZE) == 0) {
20170Sstevel@tonic-gate 			gotcache = _cache;
20180Sstevel@tonic-gate 			break;
20190Sstevel@tonic-gate 		}
20200Sstevel@tonic-gate 	}
20211618Srie 	if (gotcache == 0)
20220Sstevel@tonic-gate 		return;
20231324Srie 
20241324Srie 	/*
20251324Srie 	 * A got section within a relocatable object is suspicious.
20261324Srie 	 */
20271324Srie 	if (ehdr->e_type == ET_REL) {
20281324Srie 		(void) fprintf(stderr, MSG_INTL(MSG_GOT_UNEXPECTED), file,
20291324Srie 		    _cache->c_name);
20301324Srie 	}
20311324Srie 
20321618Srie 	gotshdr = gotcache->c_shdr;
20330Sstevel@tonic-gate 	if (gotshdr->sh_size == 0) {
20340Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
20350Sstevel@tonic-gate 		    file, gotcache->c_name);
20360Sstevel@tonic-gate 		return;
20370Sstevel@tonic-gate 	}
20381618Srie 
20391618Srie 	gotbgn = gotshdr->sh_addr;
20400Sstevel@tonic-gate 	gotend = gotbgn + gotshdr->sh_size;
20410Sstevel@tonic-gate 
20420Sstevel@tonic-gate 	/*
20431618Srie 	 * Some architectures don't properly set the sh_entsize for the GOT
20441618Srie 	 * table.  If it's not set, default to a size of a pointer.
20450Sstevel@tonic-gate 	 */
20461618Srie 	if ((gentsize = gotshdr->sh_entsize) == 0)
20471618Srie 		gentsize = sizeof (Xword);
20481618Srie 
20490Sstevel@tonic-gate 	/* LINTED */
20501618Srie 	gotents = (Word)(gotshdr->sh_size / gentsize);
20510Sstevel@tonic-gate 	gotdata = gotcache->c_data->d_buf;
20520Sstevel@tonic-gate 
20530Sstevel@tonic-gate 	if ((gottable = calloc(gotents, sizeof (Got_info))) == 0) {
20540Sstevel@tonic-gate 		int err = errno;
20551618Srie 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC), file,
20561618Srie 		    strerror(err));
20570Sstevel@tonic-gate 		return;
20580Sstevel@tonic-gate 	}
20590Sstevel@tonic-gate 
20600Sstevel@tonic-gate 	/*
20610Sstevel@tonic-gate 	 * Now we scan through all the sections looking for any relocations
20620Sstevel@tonic-gate 	 * that may be against the GOT.  Since these may not be isolated to a
20630Sstevel@tonic-gate 	 * .rel[a].got section we check them all.
20640Sstevel@tonic-gate 	 * While scanning sections save the symbol table entry (a symtab
20650Sstevel@tonic-gate 	 * overriding a dynsym) so that we can lookup _GLOBAL_OFFSET_TABLE_.
20660Sstevel@tonic-gate 	 */
20670Sstevel@tonic-gate 	for (cnt = 1; cnt < shnum; cnt++) {
20681618Srie 		Word		type, symnum;
20691618Srie 		Xword		relndx, relnum, relsize;
20701618Srie 		void		*rels;
20711618Srie 		Sym		*syms;
20721618Srie 		Cache		*symsec, *strsec;
20731618Srie 		Cache		*_cache = &cache[cnt];
20741618Srie 		Shdr		*shdr;
20750Sstevel@tonic-gate 
20761618Srie 		shdr = _cache->c_shdr;
20771618Srie 		type = shdr->sh_type;
20780Sstevel@tonic-gate 
20791618Srie 		if ((symtab == 0) && (type == SHT_DYNSYM)) {
20800Sstevel@tonic-gate 			symtab = _cache;
20810Sstevel@tonic-gate 			continue;
20820Sstevel@tonic-gate 		}
20831618Srie 		if (type == SHT_SYMTAB) {
20840Sstevel@tonic-gate 			symtab = _cache;
20850Sstevel@tonic-gate 			continue;
20860Sstevel@tonic-gate 		}
20871618Srie 		if ((type != SHT_RELA) && (type != SHT_REL))
20880Sstevel@tonic-gate 			continue;
20890Sstevel@tonic-gate 
20900Sstevel@tonic-gate 		/*
20911618Srie 		 * Decide entry size.
20920Sstevel@tonic-gate 		 */
20931618Srie 		if (((relsize = shdr->sh_entsize) == 0) ||
20941618Srie 		    (relsize > shdr->sh_size)) {
20951618Srie 			if (type == SHT_RELA)
20961618Srie 				relsize = sizeof (Rela);
20971618Srie 			else
20981618Srie 				relsize = sizeof (Rel);
20990Sstevel@tonic-gate 		}
21000Sstevel@tonic-gate 
21010Sstevel@tonic-gate 		/*
21021618Srie 		 * Determine the number of relocations available.
21030Sstevel@tonic-gate 		 */
21041618Srie 		if (shdr->sh_size == 0) {
21051618Srie 			(void) fprintf(stderr, MSG_INTL(MSG_ERR_BADSZ),
21061618Srie 			    file, _cache->c_name);
21070Sstevel@tonic-gate 			continue;
21080Sstevel@tonic-gate 		}
21091618Srie 		rels = _cache->c_data->d_buf;
21101618Srie 		relnum = shdr->sh_size / relsize;
21110Sstevel@tonic-gate 
21121618Srie 		/*
21131618Srie 		 * Get the data buffer for the associated symbol table and
21141618Srie 		 * string table.
21151618Srie 		 */
21161618Srie 		if (stringtbl(cache, 1, cnt, shnum, file,
21171618Srie 		    &symnum, &symsec, &strsec) == 0)
21181618Srie 			continue;
21191618Srie 
21201618Srie 		syms = symsec->c_data->d_buf;
21211618Srie 
21221618Srie 		/*
21231618Srie 		 * Loop through the relocation entries.
21241618Srie 		 */
21251618Srie 		for (relndx = 0; relndx < relnum; relndx++,
21261618Srie 		    rels = (void *)((char *)rels + relsize)) {
21271618Srie 			char		section[BUFSIZ];
21281618Srie 			Addr		offset;
21290Sstevel@tonic-gate 			Got_info	*gip;
21301618Srie 			Word		symndx, reltype;
21311618Srie 			Rela		*rela;
21321618Srie 			Rel		*rel;
21330Sstevel@tonic-gate 
21341618Srie 			/*
21351618Srie 			 * Unravel the relocation.
21361618Srie 			 */
21371618Srie 			if (type == SHT_RELA) {
21381618Srie 				rela = (Rela *)rels;
21391618Srie 				symndx = ELF_R_SYM(rela->r_info);
21401618Srie 				reltype = ELF_R_TYPE(rela->r_info);
21411618Srie 				offset = rela->r_offset;
21420Sstevel@tonic-gate 			} else {
21431618Srie 				rel = (Rel *)rels;
21441618Srie 				symndx = ELF_R_SYM(rel->r_info);
21451618Srie 				reltype = ELF_R_TYPE(rel->r_info);
21461618Srie 				offset = rel->r_offset;
21470Sstevel@tonic-gate 			}
21480Sstevel@tonic-gate 
21490Sstevel@tonic-gate 			/*
21500Sstevel@tonic-gate 			 * Only pay attention to relocations against the GOT.
21510Sstevel@tonic-gate 			 */
21520Sstevel@tonic-gate 			if ((offset < gotbgn) || (offset > gotend))
21530Sstevel@tonic-gate 				continue;
21540Sstevel@tonic-gate 
21550Sstevel@tonic-gate 			/* LINTED */
21561618Srie 			gotndx = (Word)((offset - gotbgn) /
21570Sstevel@tonic-gate 			    gotshdr->sh_entsize);
21580Sstevel@tonic-gate 			gip = &gottable[gotndx];
21591618Srie 
21601618Srie 			if (gip->g_reltype != 0) {
21610Sstevel@tonic-gate 				(void) fprintf(stderr,
21620Sstevel@tonic-gate 				    MSG_INTL(MSG_GOT_MULTIPLE), file,
21631618Srie 				    EC_WORD(gotndx), EC_ADDR(offset));
21640Sstevel@tonic-gate 				continue;
21650Sstevel@tonic-gate 			}
21660Sstevel@tonic-gate 
21671618Srie 			if (symndx)
21681618Srie 				gip->g_symname = relsymname(cache, _cache,
21691618Srie 				    strsec, symndx, symnum, relndx, syms,
21701618Srie 				    section, BUFSIZ, file, flags);
21711618Srie 			gip->g_reltype = reltype;
21721618Srie 			gip->g_rel = rels;
21730Sstevel@tonic-gate 		}
21740Sstevel@tonic-gate 	}
21750Sstevel@tonic-gate 
21761618Srie 	if (symlookup(MSG_ORIG(MSG_GOT_SYM), cache, shnum, &gotsym, symtab,
21771618Srie 	    file))
21781618Srie 		gotsymaddr = gotsym->st_value;
21790Sstevel@tonic-gate 	else
21801618Srie 		gotsymaddr = gotbgn;
21810Sstevel@tonic-gate 
21821618Srie 	dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
21831618Srie 	dbg_print(0, MSG_INTL(MSG_ELF_SCN_GOT), gotcache->c_name);
21841618Srie 	Elf_got_title(0);
21850Sstevel@tonic-gate 
21860Sstevel@tonic-gate 	for (gotndx = 0; gotndx < gotents; gotndx++) {
21870Sstevel@tonic-gate 		Got_info	*gip;
21880Sstevel@tonic-gate 		Sword		gindex;
21891618Srie 		Addr		gaddr;
21901618Srie 		Xword		gotentry;
21910Sstevel@tonic-gate 
21920Sstevel@tonic-gate 		gip = &gottable[gotndx];
21930Sstevel@tonic-gate 
21940Sstevel@tonic-gate 		gaddr = gotbgn + (gotndx * gentsize);
21951618Srie 		gindex = (Sword)(gaddr - gotsymaddr) / (Sword)gentsize;
21960Sstevel@tonic-gate 
21971618Srie 		if (gentsize == sizeof (Word))
21980Sstevel@tonic-gate 			/* LINTED */
21991618Srie 			gotentry = (Xword)(*((Word *)(gotdata) + gotndx));
22000Sstevel@tonic-gate 		else
22010Sstevel@tonic-gate 			/* LINTED */
22021618Srie 			gotentry = *((Xword *)(gotdata) + gotndx);
22030Sstevel@tonic-gate 
22041618Srie 		Elf_got_entry(0, gindex, gaddr, gotentry, ehdr->e_machine,
22051618Srie 		    gip->g_reltype, gip->g_rel, gip->g_symname);
22060Sstevel@tonic-gate 	}
22070Sstevel@tonic-gate 	free(gottable);
22080Sstevel@tonic-gate }
22090Sstevel@tonic-gate 
22100Sstevel@tonic-gate void
22110Sstevel@tonic-gate checksum(Elf *elf)
22120Sstevel@tonic-gate {
22131618Srie 	dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
22141618Srie 	dbg_print(0, MSG_INTL(MSG_STR_CHECKSUM), elf_checksum(elf));
22150Sstevel@tonic-gate }
22160Sstevel@tonic-gate 
22171618Srie void
22181618Srie regular(const char *file, Elf *elf, uint_t flags, char *Nname, int wfd)
22190Sstevel@tonic-gate {
22200Sstevel@tonic-gate 	Elf_Scn		*scn;
22211618Srie 	Ehdr		*ehdr;
22220Sstevel@tonic-gate 	Elf_Data	*data;
22231618Srie 	size_t		cnt, shstrndx, shnum, phnum;
22241618Srie 	Shdr		*nameshdr, *shdr;
22250Sstevel@tonic-gate 	char		*names = 0;
22260Sstevel@tonic-gate 	Cache		*cache, *_cache;
22271618Srie 	Cache		*versymcache = 0;
22280Sstevel@tonic-gate 
22291618Srie 	if ((ehdr = elf_getehdr(elf)) == NULL) {
22300Sstevel@tonic-gate 		failure(file, MSG_ORIG(MSG_ELF_GETEHDR));
22310Sstevel@tonic-gate 		return;
22320Sstevel@tonic-gate 	}
22330Sstevel@tonic-gate 
22341618Srie 	if (elf_getshnum(elf, &shnum) == 0) {
22350Sstevel@tonic-gate 		failure(file, MSG_ORIG(MSG_ELF_GETSHNUM));
22360Sstevel@tonic-gate 		return;
22370Sstevel@tonic-gate 	}
22380Sstevel@tonic-gate 
2239942Sahl 	if (elf_getshstrndx(elf, &shstrndx) == 0) {
22400Sstevel@tonic-gate 		failure(file, MSG_ORIG(MSG_ELF_GETSHSTRNDX));
22410Sstevel@tonic-gate 		return;
22420Sstevel@tonic-gate 	}
2243942Sahl 
22441618Srie 	if (elf_getphnum(elf, &phnum) == 0) {
2245942Sahl 		failure(file, MSG_ORIG(MSG_ELF_GETPHNUM));
2246942Sahl 		return;
2247942Sahl 	}
2248942Sahl 
22490Sstevel@tonic-gate 	if ((scn = elf_getscn(elf, 0)) != NULL) {
22501618Srie 		if ((shdr = elf_getshdr(scn)) == NULL) {
22510Sstevel@tonic-gate 			failure(file, MSG_ORIG(MSG_ELF_GETSHDR));
22520Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SCN), 0);
22530Sstevel@tonic-gate 			return;
22540Sstevel@tonic-gate 		}
22550Sstevel@tonic-gate 	} else
22561618Srie 		shdr = 0;
22570Sstevel@tonic-gate 
22580Sstevel@tonic-gate 	/*
22590Sstevel@tonic-gate 	 * Print the elf header.
22600Sstevel@tonic-gate 	 */
22610Sstevel@tonic-gate 	if (flags & FLG_EHDR)
22621618Srie 		Elf_ehdr(0, ehdr, shdr);
22630Sstevel@tonic-gate 
22640Sstevel@tonic-gate 	/*
22650Sstevel@tonic-gate 	 * Print the program headers.
22660Sstevel@tonic-gate 	 */
22671618Srie 	if ((flags & FLG_PHDR) && (phnum != 0)) {
22681618Srie 		Phdr *phdr;
22690Sstevel@tonic-gate 
22701618Srie 		if ((phdr = elf_getphdr(elf)) == NULL) {
22711618Srie 			failure(file, MSG_ORIG(MSG_ELF_GETPHDR));
22721618Srie 			return;
22731618Srie 		}
22740Sstevel@tonic-gate 
22751618Srie 		for (cnt = 0; cnt < phnum; phdr++, cnt++) {
22761618Srie 			dbg_print(0, MSG_ORIG(MSG_STR_EMPTY));
22771618Srie 			dbg_print(0, MSG_INTL(MSG_ELF_PHDR), EC_WORD(cnt));
22781618Srie 			Elf_phdr(0, ehdr->e_machine, phdr);
22790Sstevel@tonic-gate 		}
22800Sstevel@tonic-gate 	}
22810Sstevel@tonic-gate 
22820Sstevel@tonic-gate 
22830Sstevel@tonic-gate 	/*
2284942Sahl 	 * Return now if there are no section, if there's just one section to
2285942Sahl 	 * act as an extension of the ELF header, or if on section information
2286942Sahl 	 * was requested.
22870Sstevel@tonic-gate 	 */
2288942Sahl 	if ((shnum <= 1) || (flags && (flags & ~(FLG_EHDR | FLG_PHDR)) == 0)) {
22891618Srie 		if ((ehdr->e_type == ET_CORE) && (flags & FLG_NOTE))
22900Sstevel@tonic-gate 			note(0, shnum, 0, file);
22910Sstevel@tonic-gate 		return;
22920Sstevel@tonic-gate 	}
22930Sstevel@tonic-gate 
22941618Srie 
22950Sstevel@tonic-gate 	/*
22960Sstevel@tonic-gate 	 * Obtain the .shstrtab data buffer to provide the required section
22970Sstevel@tonic-gate 	 * name strings.
22980Sstevel@tonic-gate 	 */
22990Sstevel@tonic-gate 	if ((scn = elf_getscn(elf, shstrndx)) == NULL) {
23000Sstevel@tonic-gate 		failure(file, MSG_ORIG(MSG_ELF_GETSCN));
23010Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SHDR),
23020Sstevel@tonic-gate 		    EC_XWORD(shstrndx));
23031618Srie 
23040Sstevel@tonic-gate 	} else if ((data = elf_getdata(scn, NULL)) == NULL) {
23050Sstevel@tonic-gate 		failure(file, MSG_ORIG(MSG_ELF_GETDATA));
23060Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_DATA),
23070Sstevel@tonic-gate 		    EC_XWORD(shstrndx));
23081618Srie 
23091618Srie 	} else if ((nameshdr = elf_getshdr(scn)) == NULL) {
23100Sstevel@tonic-gate 		failure(file, MSG_ORIG(MSG_ELF_GETSHDR));
23110Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SCN),
23120Sstevel@tonic-gate 		    /* LINTED */
23130Sstevel@tonic-gate 		    (int)elf_ndxscn(scn));
23141618Srie 
23151618Srie 	} else if ((names = data->d_buf) == 0)
23160Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_SHSTRNULL), file);
23170Sstevel@tonic-gate 
23180Sstevel@tonic-gate 	/*
23190Sstevel@tonic-gate 	 * Fill in the cache descriptor with information for each section.
23200Sstevel@tonic-gate 	 */
23210Sstevel@tonic-gate 	if ((cache = malloc(shnum * sizeof (Cache))) == 0) {
23220Sstevel@tonic-gate 		int err = errno;
23230Sstevel@tonic-gate 		(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
23240Sstevel@tonic-gate 		    file, strerror(err));
23250Sstevel@tonic-gate 		return;
23260Sstevel@tonic-gate 	}
23270Sstevel@tonic-gate 
23281618Srie 	*cache = cache_init;
23290Sstevel@tonic-gate 	_cache = cache;
23300Sstevel@tonic-gate 	_cache++;
23310Sstevel@tonic-gate 
23320Sstevel@tonic-gate 	for (cnt = 1, scn = NULL; scn = elf_nextscn(elf, scn);
23330Sstevel@tonic-gate 	    cnt++, _cache++) {
23341618Srie 		if ((_cache->c_shdr = elf_getshdr(scn)) == NULL) {
23350Sstevel@tonic-gate 			failure(file, MSG_ORIG(MSG_ELF_GETSHDR));
23360Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SCN),
23370Sstevel@tonic-gate 			    /* LINTED */
23380Sstevel@tonic-gate 			    (int)elf_ndxscn(scn));
23390Sstevel@tonic-gate 		}
23400Sstevel@tonic-gate 
23411618Srie 		if (names && _cache->c_shdr->sh_name &&
23420Sstevel@tonic-gate 		    /* LINTED */
23431618Srie 		    (nameshdr->sh_size > _cache->c_shdr->sh_name))
23441618Srie 			_cache->c_name = names + _cache->c_shdr->sh_name;
23450Sstevel@tonic-gate 		else {
23460Sstevel@tonic-gate 			/*
23470Sstevel@tonic-gate 			 * If there exists no shstrtab data, or a section header
23480Sstevel@tonic-gate 			 * has no name (an invalid index of 0), then compose a
23490Sstevel@tonic-gate 			 * name for each section.
23500Sstevel@tonic-gate 			 */
23510Sstevel@tonic-gate 			char	scnndxnm[100];
23520Sstevel@tonic-gate 
23530Sstevel@tonic-gate 			(void) snprintf(scnndxnm, 100, MSG_INTL(MSG_FMT_SCNNDX),
23540Sstevel@tonic-gate 			    cnt);
23550Sstevel@tonic-gate 
23560Sstevel@tonic-gate 			/*
23570Sstevel@tonic-gate 			 * Although we have a valid shstrtab section inform the
23580Sstevel@tonic-gate 			 * user if this section name index exceeds the shstrtab
23590Sstevel@tonic-gate 			 * data.
23600Sstevel@tonic-gate 			 */
23610Sstevel@tonic-gate 			if (names &&
23620Sstevel@tonic-gate 			    /* LINTED */
23631618Srie 			    (nameshdr->sh_size <= _cache->c_shdr->sh_name)) {
23640Sstevel@tonic-gate 				(void) fprintf(stderr,
23650Sstevel@tonic-gate 				    MSG_INTL(MSG_ERR_BADSHNAME), file,
23660Sstevel@tonic-gate 				    _cache->c_name,
23671618Srie 				    EC_XWORD(_cache->c_shdr->sh_name));
23680Sstevel@tonic-gate 			}
23690Sstevel@tonic-gate 
23700Sstevel@tonic-gate 			if ((_cache->c_name =
23710Sstevel@tonic-gate 			    malloc(strlen(scnndxnm) + 1)) == 0) {
23720Sstevel@tonic-gate 				int err = errno;
23730Sstevel@tonic-gate 				(void) fprintf(stderr, MSG_INTL(MSG_ERR_MALLOC),
23740Sstevel@tonic-gate 				    file, strerror(err));
23750Sstevel@tonic-gate 				return;
23760Sstevel@tonic-gate 			}
23770Sstevel@tonic-gate 			(void) strcpy(_cache->c_name, scnndxnm);
23780Sstevel@tonic-gate 		}
23790Sstevel@tonic-gate 
23800Sstevel@tonic-gate 		if ((_cache->c_data = elf_getdata(scn, NULL)) == NULL) {
23810Sstevel@tonic-gate 			failure(file, MSG_ORIG(MSG_ELF_GETDATA));
23820Sstevel@tonic-gate 			(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SCNDATA),
23830Sstevel@tonic-gate 			    /* LINTED */
23840Sstevel@tonic-gate 			    (int)elf_ndxscn(scn));
23850Sstevel@tonic-gate 		}
23860Sstevel@tonic-gate 
23870Sstevel@tonic-gate 		/*
23880Sstevel@tonic-gate 		 * Do we wish to write the section out?
23890Sstevel@tonic-gate 		 */
23900Sstevel@tonic-gate 		if (wfd && Nname && (strcmp(Nname, _cache->c_name) == 0)) {
23910Sstevel@tonic-gate 			(void) write(wfd, _cache->c_data->d_buf,
23920Sstevel@tonic-gate 			    _cache->c_data->d_size);
23930Sstevel@tonic-gate 		}
23940Sstevel@tonic-gate 	}
23950Sstevel@tonic-gate 
23960Sstevel@tonic-gate 	if (flags & FLG_SHDR)
23971618Srie 		sections(file, cache, shnum, ehdr, Nname);
23980Sstevel@tonic-gate 
23990Sstevel@tonic-gate 	if (flags & FLG_INTERP)
24001618Srie 		interp(file, cache, shnum, phnum, elf);
24010Sstevel@tonic-gate 
24020Sstevel@tonic-gate 	versymcache = versions(cache, shnum, file, flags);
24030Sstevel@tonic-gate 
24040Sstevel@tonic-gate 	if (flags & FLG_SYMBOLS)
24051618Srie 		symbols(cache, shnum, ehdr, Nname, versymcache, file, flags);
24060Sstevel@tonic-gate 
24070Sstevel@tonic-gate 	if (flags & FLG_HASH)
24080Sstevel@tonic-gate 		hash(cache, shnum, Nname, file, flags);
24090Sstevel@tonic-gate 
24100Sstevel@tonic-gate 	if (flags & FLG_GOT)
24111618Srie 		got(cache, shnum, ehdr, file, flags);
24120Sstevel@tonic-gate 
24130Sstevel@tonic-gate 	if (flags & FLG_GROUP)
24140Sstevel@tonic-gate 		group(cache, shnum, Nname, file, flags);
24150Sstevel@tonic-gate 
24160Sstevel@tonic-gate 	if (flags & FLG_SYMINFO)
24170Sstevel@tonic-gate 		syminfo(cache, shnum, file);
24180Sstevel@tonic-gate 
24190Sstevel@tonic-gate 	if (flags & FLG_RELOC)
24201618Srie 		reloc(cache, shnum, ehdr, Nname, file, flags);
24210Sstevel@tonic-gate 
24220Sstevel@tonic-gate 	if (flags & FLG_DYNAMIC)
24231618Srie 		dynamic(cache, shnum, ehdr, file);
24240Sstevel@tonic-gate 
24250Sstevel@tonic-gate 	if (flags & FLG_NOTE)
24260Sstevel@tonic-gate 		note(cache, shnum, Nname, file);
24270Sstevel@tonic-gate 
24280Sstevel@tonic-gate 	if (flags & FLG_MOVE)
24290Sstevel@tonic-gate 		move(cache, shnum, Nname, file, flags);
24300Sstevel@tonic-gate 
24310Sstevel@tonic-gate 	if (flags & FLG_CHECKSUM)
24320Sstevel@tonic-gate 		checksum(elf);
24330Sstevel@tonic-gate 
24340Sstevel@tonic-gate 	if (flags & FLG_CAP)
24351618Srie 		cap(file, cache, shnum, phnum, ehdr, elf);
24360Sstevel@tonic-gate 
24370Sstevel@tonic-gate 	if (flags & FLG_UNWIND)
24381618Srie 		unwind(cache, shnum, phnum, ehdr, Nname, file, elf);
24390Sstevel@tonic-gate 
24400Sstevel@tonic-gate 	free(cache);
24410Sstevel@tonic-gate }
2442