xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/elf.c (revision 5088:26c540f30cd3)
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  */
211618Srie 
220Sstevel@tonic-gate /*
233850Sab196087  * Copyright 2007 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  * String conversion routines for ELF header attributes.
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate #include	<stdio.h>
320Sstevel@tonic-gate #include	<string.h>
330Sstevel@tonic-gate #include	"_conv.h"
340Sstevel@tonic-gate #include	"elf_msg.h"
350Sstevel@tonic-gate #include	<sys/elf_SPARC.h>
360Sstevel@tonic-gate 
371976Sab196087 
381976Sab196087 
391976Sab196087 /* Instantiate a local copy of conv_map2str() from _conv.h */
401976Sab196087 DEFINE_conv_map2str
411976Sab196087 
421976Sab196087 
431976Sab196087 
440Sstevel@tonic-gate const char *
45*5088Sab196087 conv_ehdr_class(uchar_t class, Conv_fmt_flags_t fmt_flags,
46*5088Sab196087     Conv_inv_buf_t *inv_buf)
470Sstevel@tonic-gate {
481618Srie 	static const Msg	classes[] = {
491976Sab196087 		MSG_ELFCLASSNONE, MSG_ELFCLASS32, MSG_ELFCLASS64
501976Sab196087 	};
511976Sab196087 	static const Msg	classes_alt[] = {
521976Sab196087 		MSG_ELFCLASSNONE_ALT, MSG_ELFCLASS32_ALT, MSG_ELFCLASS64_ALT
531618Srie 	};
540Sstevel@tonic-gate 
55*5088Sab196087 	/* Use alternative strings? */
56*5088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
57*5088Sab196087 	case CONV_FMT_ALT_DUMP:
58*5088Sab196087 	case CONV_FMT_ALT_FILE:
59*5088Sab196087 		return (conv_map2str(inv_buf, class, fmt_flags,
60*5088Sab196087 		    ARRAY_NELTS(classes_alt), classes_alt));
61*5088Sab196087 	}
62*5088Sab196087 
63*5088Sab196087 	/* Use default strings */
644734Sab196087 	return (conv_map2str(inv_buf, class, fmt_flags,
65*5088Sab196087 	    ARRAY_NELTS(classes), classes));
660Sstevel@tonic-gate }
670Sstevel@tonic-gate 
680Sstevel@tonic-gate const char *
69*5088Sab196087 conv_ehdr_data(uchar_t data, Conv_fmt_flags_t fmt_flags,
70*5088Sab196087     Conv_inv_buf_t *inv_buf)
710Sstevel@tonic-gate {
721618Srie 	static const Msg	datas[] = {
731976Sab196087 		MSG_ELFDATANONE, MSG_ELFDATA2LSB, MSG_ELFDATA2MSB
741976Sab196087 	};
751976Sab196087 	static const Msg	datas_dump[] = {
761976Sab196087 		MSG_ELFDATANONE_ALT, MSG_ELFDATA2LSB_ALT1, MSG_ELFDATA2MSB_ALT1
771976Sab196087 	};
781976Sab196087 	static const Msg	datas_file[] = {
791976Sab196087 		MSG_ELFDATANONE_ALT, MSG_ELFDATA2LSB_ALT2, MSG_ELFDATA2MSB_ALT2
801618Srie 	};
810Sstevel@tonic-gate 
82*5088Sab196087 	/* Use alternative strings? */
83*5088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
84*5088Sab196087 	case CONV_FMT_ALT_DUMP:
85*5088Sab196087 		return (conv_map2str(inv_buf, data, fmt_flags,
86*5088Sab196087 		    ARRAY_NELTS(datas_dump), datas_dump));
87*5088Sab196087 	case CONV_FMT_ALT_FILE:
88*5088Sab196087 		return (conv_map2str(inv_buf, data, fmt_flags,
89*5088Sab196087 		    ARRAY_NELTS(datas_file), datas_file));
90*5088Sab196087 	}
91*5088Sab196087 
92*5088Sab196087 	/* Use default strings */
934734Sab196087 	return (conv_map2str(inv_buf, data, fmt_flags,
94*5088Sab196087 	    ARRAY_NELTS(datas), datas));
950Sstevel@tonic-gate }
960Sstevel@tonic-gate 
970Sstevel@tonic-gate static const Msg machines[EM_NUM] = {
981618Srie 	MSG_EM_NONE,		MSG_EM_M32,		MSG_EM_SPARC,
991618Srie 	MSG_EM_386,		MSG_EM_68K,		MSG_EM_88K,
1001618Srie 	MSG_EM_486,		MSG_EM_860,		MSG_EM_MIPS,
1012802Sab196087 	MSG_EM_S370,		MSG_EM_MIPS_RS3_LE,	MSG_EM_RS6000,
1021618Srie 	MSG_EM_UNKNOWN12,	MSG_EM_UNKNOWN13,	MSG_EM_UNKNOWN14,
1031618Srie 	MSG_EM_PA_RISC,		MSG_EM_nCUBE,		MSG_EM_VPP500,
1042802Sab196087 	MSG_EM_SPARC32PLUS,	MSG_EM_960,		MSG_EM_PPC,
1052802Sab196087 	MSG_EM_PPC64,		MSG_EM_S390,		MSG_EM_UNKNOWN23,
1061618Srie 	MSG_EM_UNKNOWN24,	MSG_EM_UNKNOWN25,	MSG_EM_UNKNOWN26,
1071618Srie 	MSG_EM_UNKNOWN27,	MSG_EM_UNKNOWN28,	MSG_EM_UNKNOWN29,
1081618Srie 	MSG_EM_UNKNOWN30,	MSG_EM_UNKNOWN31,	MSG_EM_UNKNOWN32,
1091618Srie 	MSG_EM_UNKNOWN33,	MSG_EM_UNKNOWN34,	MSG_EM_UNKNOWN35,
1103850Sab196087 	MSG_EM_V800,		MSG_EM_FR20,		MSG_EM_RH32,
1111618Srie 	MSG_EM_RCE,		MSG_EM_ARM,		MSG_EM_ALPHA,
1121618Srie 	MSG_EM_SH,		MSG_EM_SPARCV9,		MSG_EM_TRICORE,
1131618Srie 	MSG_EM_ARC,		MSG_EM_H8_300,		MSG_EM_H8_300H,
1141618Srie 	MSG_EM_H8S,		MSG_EM_H8_500,		MSG_EM_IA_64,
1151618Srie 	MSG_EM_MIPS_X,		MSG_EM_COLDFIRE,	MSG_EM_68HC12,
1161618Srie 	MSG_EM_MMA,		MSG_EM_PCP,		MSG_EM_NCPU,
1171618Srie 	MSG_EM_NDR1,		MSG_EM_STARCORE,	MSG_EM_ME16,
1181618Srie 	MSG_EM_ST100,		MSG_EM_TINYJ,		MSG_EM_AMD64,
1192802Sab196087 	MSG_EM_PDSP,		MSG_EM_UNKNOWN64,	MSG_EM_UNKNOWN65,
1201618Srie 	MSG_EM_FX66,		MSG_EM_ST9PLUS,		MSG_EM_ST7,
1211618Srie 	MSG_EM_68HC16,		MSG_EM_68HC11,		MSG_EM_68HC08,
1221618Srie 	MSG_EM_68HC05,		MSG_EM_SVX,		MSG_EM_ST19,
1231618Srie 	MSG_EM_VAX,		MSG_EM_CRIS,		MSG_EM_JAVELIN,
1241618Srie 	MSG_EM_FIREPATH,	MSG_EM_ZSP,		MSG_EM_MMIX,
1251618Srie 	MSG_EM_HUANY,		MSG_EM_PRISM,		MSG_EM_AVR,
1261618Srie 	MSG_EM_FR30,		MSG_EM_D10V,		MSG_EM_D30V,
1271618Srie 	MSG_EM_V850,		MSG_EM_M32R,		MSG_EM_MN10300,
1281618Srie 	MSG_EM_MN10200,		MSG_EM_PJ,		MSG_EM_OPENRISC,
1291618Srie 	MSG_EM_ARC_A5,		MSG_EM_XTENSA
1300Sstevel@tonic-gate };
1311976Sab196087 static const Msg machines_alt[EM_NUM] = {
1321976Sab196087 	MSG_EM_NONE_ALT,	MSG_EM_M32_ALT,		MSG_EM_SPARC_ALT,
1331976Sab196087 	MSG_EM_386_ALT,		MSG_EM_68K_ALT,		MSG_EM_88K_ALT,
1341976Sab196087 	MSG_EM_486_ALT,		MSG_EM_860_ALT,		MSG_EM_MIPS_ALT,
1352802Sab196087 	MSG_EM_S370,		MSG_EM_MIPS_RS3_LE_ALT,	MSG_EM_RS6000_ALT,
1361976Sab196087 	MSG_EM_UNKNOWN12,	MSG_EM_UNKNOWN13,	MSG_EM_UNKNOWN14,
1371976Sab196087 	MSG_EM_PA_RISC_ALT,	MSG_EM_nCUBE_ALT,	MSG_EM_VPP500_ALT,
1382802Sab196087 	MSG_EM_SPARC32PLUS_ALT,	MSG_EM_960,		MSG_EM_PPC_ALT,
1392802Sab196087 	MSG_EM_PPC64_ALT,	MSG_EM_S390,		MSG_EM_UNKNOWN23,
1401976Sab196087 	MSG_EM_UNKNOWN24,	MSG_EM_UNKNOWN25,	MSG_EM_UNKNOWN26,
1411976Sab196087 	MSG_EM_UNKNOWN27,	MSG_EM_UNKNOWN28,	MSG_EM_UNKNOWN29,
1421976Sab196087 	MSG_EM_UNKNOWN30,	MSG_EM_UNKNOWN31,	MSG_EM_UNKNOWN32,
1431976Sab196087 	MSG_EM_UNKNOWN33,	MSG_EM_UNKNOWN34,	MSG_EM_UNKNOWN35,
1443850Sab196087 	MSG_EM_V800,		MSG_EM_FR20,		MSG_EM_RH32,
1451976Sab196087 	MSG_EM_RCE,		MSG_EM_ARM_ALT,		MSG_EM_ALPHA_ALT,
1461976Sab196087 	MSG_EM_SH,		MSG_EM_SPARCV9_ALT,	MSG_EM_TRICORE,
1471976Sab196087 	MSG_EM_ARC,		MSG_EM_H8_300,		MSG_EM_H8_300H,
1481976Sab196087 	MSG_EM_H8S,		MSG_EM_H8_500,		MSG_EM_IA_64_ALT,
1491976Sab196087 	MSG_EM_MIPS_X,		MSG_EM_COLDFIRE,	MSG_EM_68HC12,
1501976Sab196087 	MSG_EM_MMA,		MSG_EM_PCP,		MSG_EM_NCPU,
1511976Sab196087 	MSG_EM_NDR1,		MSG_EM_STARCORE,	MSG_EM_ME16,
1521976Sab196087 	MSG_EM_ST100,		MSG_EM_TINYJ,		MSG_EM_AMD64_ALT,
1532802Sab196087 	MSG_EM_PDSP,		MSG_EM_UNKNOWN64,	MSG_EM_UNKNOWN65,
1541976Sab196087 	MSG_EM_FX66,		MSG_EM_ST9PLUS,		MSG_EM_ST7,
1551976Sab196087 	MSG_EM_68HC16,		MSG_EM_68HC11,		MSG_EM_68HC08,
1561976Sab196087 	MSG_EM_68HC05,		MSG_EM_SVX,		MSG_EM_ST19,
1571976Sab196087 	MSG_EM_VAX_ALT,		MSG_EM_CRIS,		MSG_EM_JAVELIN,
1581976Sab196087 	MSG_EM_FIREPATH,	MSG_EM_ZSP,		MSG_EM_MMIX,
1591976Sab196087 	MSG_EM_HUANY,		MSG_EM_PRISM,		MSG_EM_AVR,
1601976Sab196087 	MSG_EM_FR30,		MSG_EM_D10V,		MSG_EM_D30V,
1611976Sab196087 	MSG_EM_V850,		MSG_EM_M32R,		MSG_EM_MN10300,
1621976Sab196087 	MSG_EM_MN10200,		MSG_EM_PJ,		MSG_EM_OPENRISC,
1631976Sab196087 	MSG_EM_ARC_A5,		MSG_EM_XTENSA
1641976Sab196087 };
1650Sstevel@tonic-gate #if	(EM_NUM != (EM_XTENSA + 1))
1660Sstevel@tonic-gate #error	"EM_NUM has grown"
1670Sstevel@tonic-gate #endif
1681618Srie 
1691618Srie const char *
170*5088Sab196087 conv_ehdr_mach(Half machine, Conv_fmt_flags_t fmt_flags,
171*5088Sab196087     Conv_inv_buf_t *inv_buf)
1721618Srie {
173*5088Sab196087 	/* Use alternative strings? */
174*5088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
175*5088Sab196087 	case CONV_FMT_ALT_DUMP:
176*5088Sab196087 	case CONV_FMT_ALT_FILE:
177*5088Sab196087 		return (conv_map2str(inv_buf, machine, fmt_flags,
178*5088Sab196087 		    ARRAY_NELTS(machines_alt), machines_alt));
179*5088Sab196087 	}
180*5088Sab196087 
181*5088Sab196087 	/* Use default strings */
1824734Sab196087 	return (conv_map2str(inv_buf, machine, fmt_flags,
183*5088Sab196087 	    ARRAY_NELTS(machines), machines));
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate 
1861976Sab196087 
1870Sstevel@tonic-gate const char *
188*5088Sab196087 conv_ehdr_type(Half etype, Conv_fmt_flags_t fmt_flags, Conv_inv_buf_t *inv_buf)
1890Sstevel@tonic-gate {
1901618Srie 	static const Msg	etypes[] = {
1911618Srie 		MSG_ET_NONE,		MSG_ET_REL,		MSG_ET_EXEC,
1921618Srie 		MSG_ET_DYN,		MSG_ET_CORE
1931618Srie 	};
1941976Sab196087 	static const Msg	etypes_alt[] = {
1951976Sab196087 		MSG_ET_NONE_ALT,	MSG_ET_REL_ALT,		MSG_ET_EXEC_ALT,
1961976Sab196087 		MSG_ET_DYN_ALT,		MSG_ET_CORE_ALT
1971976Sab196087 	};
1980Sstevel@tonic-gate 
1991976Sab196087 	if (etype == ET_SUNWPSEUDO) {
200*5088Sab196087 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
201*5088Sab196087 		case CONV_FMT_ALT_DUMP:
202*5088Sab196087 		case CONV_FMT_ALT_FILE:
203*5088Sab196087 			return (MSG_ORIG(MSG_ET_SUNWPSEUDO_ALT));
204*5088Sab196087 		default:
205*5088Sab196087 			return (MSG_ORIG(MSG_ET_SUNWPSEUDO));
206*5088Sab196087 		}
2071976Sab196087 	}
2081976Sab196087 
209*5088Sab196087 	/* Use alternative strings? */
210*5088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
211*5088Sab196087 	case CONV_FMT_ALT_DUMP:
212*5088Sab196087 	case CONV_FMT_ALT_FILE:
213*5088Sab196087 		return (conv_map2str(inv_buf, etype, fmt_flags,
214*5088Sab196087 		    ARRAY_NELTS(etypes_alt), etypes_alt));
215*5088Sab196087 	}
216*5088Sab196087 
217*5088Sab196087 	/* Use default strings */
2184734Sab196087 	return (conv_map2str(inv_buf, etype, fmt_flags,
219*5088Sab196087 	    ARRAY_NELTS(etypes), etypes));
2201976Sab196087 
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate const char *
224*5088Sab196087 conv_ehdr_vers(Word version, Conv_fmt_flags_t fmt_flags,
225*5088Sab196087     Conv_inv_buf_t *inv_buf)
2260Sstevel@tonic-gate {
2271618Srie 	static const Msg	versions[] = {
2281618Srie 		MSG_EV_NONE,		MSG_EV_CURRENT
2291618Srie 	};
2301976Sab196087 	static const Msg	versions_alt[] = {
2311976Sab196087 		MSG_EV_NONE_ALT,	MSG_EV_CURRENT_ALT
2321976Sab196087 	};
2330Sstevel@tonic-gate 
234*5088Sab196087 	/* Use alternative strings? */
235*5088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
236*5088Sab196087 	case CONV_FMT_ALT_DUMP:
237*5088Sab196087 	case CONV_FMT_ALT_FILE:
238*5088Sab196087 		return (conv_map2str(inv_buf, version, fmt_flags,
239*5088Sab196087 		    ARRAY_NELTS(versions_alt), versions_alt));
240*5088Sab196087 	}
241*5088Sab196087 
242*5088Sab196087 	/* Use default strings */
2434734Sab196087 	return (conv_map2str(inv_buf, version, fmt_flags,
244*5088Sab196087 	    ARRAY_NELTS(versions), versions));
2450Sstevel@tonic-gate }
2460Sstevel@tonic-gate 
2472352Sab196087 #define	EFLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
2482352Sab196087 		MSG_EF_SPARCV9_TSO_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
2492352Sab196087 		MSG_EF_SPARC_SUN_US1_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
2502352Sab196087 		MSG_EF_SPARC_HAL_R1_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
2512352Sab196087 		MSG_EF_SPARC_SUN_US3_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
2524734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
2534734Sab196087 
2544734Sab196087 /*
2554734Sab196087  * Ensure that Conv_ehdr_flags_buf_t is large enough:
2564734Sab196087  *
2574734Sab196087  * EFLAGSZ is the real minimum size of the buffer required by conv_ehdr_flags().
2584734Sab196087  * However, Conv_ehdr_flags_buf_t uses CONV_EHDR_FLAG_BUFSIZE to set the
2594734Sab196087  * buffer size. We do things this way because the definition of EFLAGSZ uses
2604734Sab196087  * information that is not available in the environment of other programs
2614734Sab196087  * that include the conv.h header file.
2624734Sab196087  */
2634734Sab196087 #if CONV_EHDR_FLAGS_BUFSIZE < EFLAGSZ
2644734Sab196087 #error "CONV_EHDR_FLAGS_BUFSIZE is not large enough"
2654734Sab196087 #endif
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate /*
2681618Srie  * Make a string representation of the e_flags field.
2690Sstevel@tonic-gate  */
2700Sstevel@tonic-gate const char *
271*5088Sab196087 conv_ehdr_flags(Half mach, Word flags, Conv_fmt_flags_t fmt_flags,
272*5088Sab196087     Conv_ehdr_flags_buf_t *flags_buf)
2730Sstevel@tonic-gate {
2741618Srie 	static Val_desc vda[] = {
2751618Srie 		{ EF_SPARC_32PLUS,	MSG_ORIG(MSG_EF_SPARC_32PLUS) },
2761618Srie 		{ EF_SPARC_SUN_US1,	MSG_ORIG(MSG_EF_SPARC_SUN_US1) },
2771618Srie 		{ EF_SPARC_HAL_R1,	MSG_ORIG(MSG_EF_SPARC_HAL_R1) },
2781618Srie 		{ EF_SPARC_SUN_US3,	MSG_ORIG(MSG_EF_SPARC_SUN_US3) },
2791618Srie 		{ 0,			0 }
2801618Srie 	};
2811618Srie 	static const Msg mm_flags[] = {
2821618Srie 		MSG_EF_SPARCV9_TSO,	MSG_EF_SPARCV9_PSO,
2831618Srie 		MSG_EF_SPARCV9_RMO
2841618Srie 	};
2852352Sab196087 	static const char *leading_str_arr[2];
2864734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
2874734Sab196087 	    NULL, sizeof (flags_buf->buf), vda, leading_str_arr };
2882352Sab196087 
2892352Sab196087 	const char **lstr = leading_str_arr;
2900Sstevel@tonic-gate 
2914734Sab196087 	conv_arg.buf = flags_buf->buf;
2924734Sab196087 
2930Sstevel@tonic-gate 	/*
2941618Srie 	 * Non-SPARC architectures presently provide no known flags.
2950Sstevel@tonic-gate 	 */
2960Sstevel@tonic-gate 	if ((mach == EM_SPARCV9) || (((mach == EM_SPARC) ||
2970Sstevel@tonic-gate 	    (mach == EM_SPARC32PLUS)) && flags)) {
2981618Srie 		/*
2991618Srie 		 * Valid vendor extension bits for SPARCV9.  These must be
3001618Srie 		 * updated along with elf_SPARC.h.
3011618Srie 		 */
3020Sstevel@tonic-gate 
3032352Sab196087 		conv_arg.oflags = conv_arg.rflags = flags;
3041618Srie 		if ((mach == EM_SPARCV9) && (flags <= EF_SPARCV9_RMO)) {
3052352Sab196087 			*lstr++ = MSG_ORIG(mm_flags[flags & EF_SPARCV9_MM]);
3062352Sab196087 			conv_arg.rflags &= ~EF_SPARCV9_MM;
3070Sstevel@tonic-gate 		}
3082352Sab196087 		*lstr = NULL;
3090Sstevel@tonic-gate 
310*5088Sab196087 		(void) conv_expn_field(&conv_arg, fmt_flags);
3110Sstevel@tonic-gate 
3124734Sab196087 		return (conv_arg.buf);
3131618Srie 	}
3144734Sab196087 
3154734Sab196087 	return (conv_invalid_val(&flags_buf->inv_buf, flags, CONV_FMT_DECIMAL));
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate /*
3193850Sab196087  * Make a string representation of the e_ident[EI_OSABI] field.
3203850Sab196087  */
3213850Sab196087 const char *
322*5088Sab196087 conv_ehdr_osabi(uchar_t osabi, Conv_fmt_flags_t fmt_flags,
323*5088Sab196087     Conv_inv_buf_t *inv_buf)
3243850Sab196087 {
3253850Sab196087 	static const Msg	osabi_arr[] = {
3263850Sab196087 		MSG_OSABI_NONE,		MSG_OSABI_HPUX,
3273850Sab196087 		MSG_OSABI_NETBSD,	MSG_OSABI_LINUX,
3283850Sab196087 		MSG_OSABI_UNKNOWN4,	MSG_OSABI_UNKNOWN5,
3293850Sab196087 		MSG_OSABI_SOLARIS,	MSG_OSABI_AIX,
3303850Sab196087 		MSG_OSABI_IRIX,		MSG_OSABI_FREEBSD,
3313850Sab196087 		MSG_OSABI_TRU64,	MSG_OSABI_MODESTO,
3323850Sab196087 		MSG_OSABI_OPENBSD,	MSG_OSABI_OPENVMS,
3333850Sab196087 		MSG_OSABI_NSK,		MSG_OSABI_AROS
3343850Sab196087 	};
3353850Sab196087 	static const Msg	osabi_arr_alt[] = {
3363850Sab196087 		MSG_OSABI_NONE_ALT,	MSG_OSABI_HPUX_ALT,
3373850Sab196087 		MSG_OSABI_NETBSD_ALT,	MSG_OSABI_LINUX_ALT,
3383850Sab196087 		MSG_OSABI_UNKNOWN4,	MSG_OSABI_UNKNOWN5,
3393850Sab196087 		MSG_OSABI_SOLARIS_ALT,	MSG_OSABI_AIX_ALT,
3403850Sab196087 		MSG_OSABI_IRIX_ALT,	MSG_OSABI_FREEBSD_ALT,
3413850Sab196087 		MSG_OSABI_TRU64_ALT,	MSG_OSABI_MODESTO_ALT,
3423850Sab196087 		MSG_OSABI_OPENBSD_ALT,	MSG_OSABI_OPENVMS_ALT,
3433850Sab196087 		MSG_OSABI_NSK_ALT,	MSG_OSABI_AROS_ALT
3443850Sab196087 	};
3453850Sab196087 
3463850Sab196087 	const char *str;
3473850Sab196087 
3483850Sab196087 	switch (osabi) {
3493850Sab196087 	case ELFOSABI_ARM:
350*5088Sab196087 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
351*5088Sab196087 		case CONV_FMT_ALT_DUMP:
352*5088Sab196087 		case CONV_FMT_ALT_FILE:
353*5088Sab196087 			str = MSG_ORIG(MSG_OSABI_ARM_ALT);
354*5088Sab196087 			break;
355*5088Sab196087 		default:
356*5088Sab196087 			str = MSG_ORIG(MSG_OSABI_ARM);
357*5088Sab196087 		}
3583850Sab196087 		break;
3593850Sab196087 
3603850Sab196087 	case ELFOSABI_STANDALONE:
361*5088Sab196087 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
362*5088Sab196087 		case CONV_FMT_ALT_DUMP:
363*5088Sab196087 		case CONV_FMT_ALT_FILE:
364*5088Sab196087 			str = MSG_ORIG(MSG_OSABI_STANDALONE_ALT);
365*5088Sab196087 			break;
366*5088Sab196087 		default:
367*5088Sab196087 			str = MSG_ORIG(MSG_OSABI_STANDALONE);
368*5088Sab196087 		}
3693850Sab196087 		break;
3703850Sab196087 
3713850Sab196087 	default:
372*5088Sab196087 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
373*5088Sab196087 		case CONV_FMT_ALT_DUMP:
374*5088Sab196087 		case CONV_FMT_ALT_FILE:
375*5088Sab196087 			str = conv_map2str(inv_buf, osabi, fmt_flags,
376*5088Sab196087 			    ARRAY_NELTS(osabi_arr_alt), osabi_arr_alt);
377*5088Sab196087 			break;
378*5088Sab196087 		default:
379*5088Sab196087 			str = conv_map2str(inv_buf, osabi, fmt_flags,
380*5088Sab196087 			    ARRAY_NELTS(osabi_arr), osabi_arr);
381*5088Sab196087 		}
3823850Sab196087 		break;
3833850Sab196087 	}
3843850Sab196087 
3853850Sab196087 	return (str);
3863850Sab196087 }
3873850Sab196087 
3883850Sab196087 /*
3890Sstevel@tonic-gate  * A generic means of returning additional information for a rejected file in
3900Sstevel@tonic-gate  * terms of a string.
3910Sstevel@tonic-gate  */
3920Sstevel@tonic-gate const char *
3934734Sab196087 conv_reject_desc(Rej_desc * rej, Conv_reject_desc_buf_t *reject_desc_buf)
3940Sstevel@tonic-gate {
3954734Sab196087 	ushort_t	type = rej->rej_type;
3964734Sab196087 	uint_t		info = rej->rej_info;
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate 	if (type == SGS_REJ_MACH)
3990Sstevel@tonic-gate 		/* LINTED */
4004734Sab196087 		return (conv_ehdr_mach((Half)info, 0,
4014734Sab196087 		    &reject_desc_buf->inv_buf));
4020Sstevel@tonic-gate 	else if (type == SGS_REJ_CLASS)
4030Sstevel@tonic-gate 		/* LINTED */
4044734Sab196087 		return (conv_ehdr_class((uchar_t)info, 0,
4054734Sab196087 		    &reject_desc_buf->inv_buf));
4060Sstevel@tonic-gate 	else if (type == SGS_REJ_DATA)
4070Sstevel@tonic-gate 		/* LINTED */
4084734Sab196087 		return (conv_ehdr_data((uchar_t)info, 0,
4094734Sab196087 		    &reject_desc_buf->inv_buf));
4100Sstevel@tonic-gate 	else if (type == SGS_REJ_TYPE)
4110Sstevel@tonic-gate 		/* LINTED */
4124734Sab196087 		return (conv_ehdr_type((Half)info, 0,
4134734Sab196087 		    &reject_desc_buf->inv_buf));
4140Sstevel@tonic-gate 	else if ((type == SGS_REJ_BADFLAG) || (type == SGS_REJ_MISFLAG) ||
4150Sstevel@tonic-gate 	    (type == SGS_REJ_HAL) || (type == SGS_REJ_US3))
4160Sstevel@tonic-gate 		/*
4170Sstevel@tonic-gate 		 * Only called from ld.so.1, thus M_MACH is hardcoded.
4180Sstevel@tonic-gate 		 */
419*5088Sab196087 		return (conv_ehdr_flags(M_MACH, (Word)info, 0,
4204734Sab196087 		    &reject_desc_buf->flags_buf));
4210Sstevel@tonic-gate 	else if (type == SGS_REJ_UNKFILE)
4220Sstevel@tonic-gate 		return ((const char *)0);
4230Sstevel@tonic-gate 	else if ((type == SGS_REJ_STR) || (type == SGS_REJ_HWCAP_1)) {
4240Sstevel@tonic-gate 		if (rej->rej_str)
4250Sstevel@tonic-gate 			return ((const char *)rej->rej_str);
4260Sstevel@tonic-gate 		else
4270Sstevel@tonic-gate 			return (MSG_ORIG(MSG_STR_EMPTY));
4280Sstevel@tonic-gate 	} else
4294734Sab196087 		return (conv_invalid_val(&reject_desc_buf->inv_buf, info,
4301976Sab196087 		    CONV_FMT_DECIMAL));
4310Sstevel@tonic-gate }
432