xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/elf.c (revision 5152:fa5ab16f3606)
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 *
455088Sab196087 conv_ehdr_class(uchar_t class, Conv_fmt_flags_t fmt_flags,
465088Sab196087     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 
555088Sab196087 	/* Use alternative strings? */
565088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
575088Sab196087 	case CONV_FMT_ALT_DUMP:
585088Sab196087 	case CONV_FMT_ALT_FILE:
595088Sab196087 		return (conv_map2str(inv_buf, class, fmt_flags,
605088Sab196087 		    ARRAY_NELTS(classes_alt), classes_alt));
615088Sab196087 	}
625088Sab196087 
635088Sab196087 	/* Use default strings */
644734Sab196087 	return (conv_map2str(inv_buf, class, fmt_flags,
655088Sab196087 	    ARRAY_NELTS(classes), classes));
660Sstevel@tonic-gate }
670Sstevel@tonic-gate 
680Sstevel@tonic-gate const char *
695088Sab196087 conv_ehdr_data(uchar_t data, Conv_fmt_flags_t fmt_flags,
705088Sab196087     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 
825088Sab196087 	/* Use alternative strings? */
835088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
845088Sab196087 	case CONV_FMT_ALT_DUMP:
855088Sab196087 		return (conv_map2str(inv_buf, data, fmt_flags,
865088Sab196087 		    ARRAY_NELTS(datas_dump), datas_dump));
875088Sab196087 	case CONV_FMT_ALT_FILE:
885088Sab196087 		return (conv_map2str(inv_buf, data, fmt_flags,
895088Sab196087 		    ARRAY_NELTS(datas_file), datas_file));
905088Sab196087 	}
915088Sab196087 
925088Sab196087 	/* Use default strings */
934734Sab196087 	return (conv_map2str(inv_buf, data, fmt_flags,
945088Sab196087 	    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 *
1705088Sab196087 conv_ehdr_mach(Half machine, Conv_fmt_flags_t fmt_flags,
1715088Sab196087     Conv_inv_buf_t *inv_buf)
1721618Srie {
1735088Sab196087 	/* Use alternative strings? */
1745088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
1755088Sab196087 	case CONV_FMT_ALT_DUMP:
1765088Sab196087 	case CONV_FMT_ALT_FILE:
1775088Sab196087 		return (conv_map2str(inv_buf, machine, fmt_flags,
1785088Sab196087 		    ARRAY_NELTS(machines_alt), machines_alt));
1795088Sab196087 	}
1805088Sab196087 
1815088Sab196087 	/* Use default strings */
1824734Sab196087 	return (conv_map2str(inv_buf, machine, fmt_flags,
1835088Sab196087 	    ARRAY_NELTS(machines), machines));
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate 
1861976Sab196087 
1870Sstevel@tonic-gate const char *
1885088Sab196087 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) {
2005088Sab196087 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
2015088Sab196087 		case CONV_FMT_ALT_DUMP:
2025088Sab196087 		case CONV_FMT_ALT_FILE:
2035088Sab196087 			return (MSG_ORIG(MSG_ET_SUNWPSEUDO_ALT));
2045088Sab196087 		default:
2055088Sab196087 			return (MSG_ORIG(MSG_ET_SUNWPSEUDO));
2065088Sab196087 		}
2071976Sab196087 	}
2081976Sab196087 
2095088Sab196087 	/* Use alternative strings? */
2105088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
2115088Sab196087 	case CONV_FMT_ALT_DUMP:
2125088Sab196087 	case CONV_FMT_ALT_FILE:
2135088Sab196087 		return (conv_map2str(inv_buf, etype, fmt_flags,
2145088Sab196087 		    ARRAY_NELTS(etypes_alt), etypes_alt));
2155088Sab196087 	}
2165088Sab196087 
2175088Sab196087 	/* Use default strings */
2184734Sab196087 	return (conv_map2str(inv_buf, etype, fmt_flags,
2195088Sab196087 	    ARRAY_NELTS(etypes), etypes));
2201976Sab196087 
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate 
2230Sstevel@tonic-gate const char *
2245088Sab196087 conv_ehdr_vers(Word version, Conv_fmt_flags_t fmt_flags,
2255088Sab196087     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 
2345088Sab196087 	/* Use alternative strings? */
2355088Sab196087 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
2365088Sab196087 	case CONV_FMT_ALT_DUMP:
2375088Sab196087 	case CONV_FMT_ALT_FILE:
2385088Sab196087 		return (conv_map2str(inv_buf, version, fmt_flags,
2395088Sab196087 		    ARRAY_NELTS(versions_alt), versions_alt));
2405088Sab196087 	}
2415088Sab196087 
2425088Sab196087 	/* Use default strings */
2434734Sab196087 	return (conv_map2str(inv_buf, version, fmt_flags,
2445088Sab196087 	    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  */
263*5152Sab196087 #if (CONV_EHDR_FLAGS_BUFSIZE != EFLAGSZ) && !defined(__lint)
264*5152Sab196087 #define	REPORT_BUFSIZE EFLAGSZ
265*5152Sab196087 #include "report_bufsize.h"
266*5152Sab196087 #error "CONV_EHDR_FLAGS_BUFSIZE does not match EFLAGSZ"
2674734Sab196087 #endif
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate /*
2701618Srie  * Make a string representation of the e_flags field.
2710Sstevel@tonic-gate  */
2720Sstevel@tonic-gate const char *
2735088Sab196087 conv_ehdr_flags(Half mach, Word flags, Conv_fmt_flags_t fmt_flags,
2745088Sab196087     Conv_ehdr_flags_buf_t *flags_buf)
2750Sstevel@tonic-gate {
2761618Srie 	static Val_desc vda[] = {
2771618Srie 		{ EF_SPARC_32PLUS,	MSG_ORIG(MSG_EF_SPARC_32PLUS) },
2781618Srie 		{ EF_SPARC_SUN_US1,	MSG_ORIG(MSG_EF_SPARC_SUN_US1) },
2791618Srie 		{ EF_SPARC_HAL_R1,	MSG_ORIG(MSG_EF_SPARC_HAL_R1) },
2801618Srie 		{ EF_SPARC_SUN_US3,	MSG_ORIG(MSG_EF_SPARC_SUN_US3) },
2811618Srie 		{ 0,			0 }
2821618Srie 	};
2831618Srie 	static const Msg mm_flags[] = {
2841618Srie 		MSG_EF_SPARCV9_TSO,	MSG_EF_SPARCV9_PSO,
2851618Srie 		MSG_EF_SPARCV9_RMO
2861618Srie 	};
2872352Sab196087 	static const char *leading_str_arr[2];
2884734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
2894734Sab196087 	    NULL, sizeof (flags_buf->buf), vda, leading_str_arr };
2902352Sab196087 
2912352Sab196087 	const char **lstr = leading_str_arr;
2920Sstevel@tonic-gate 
2934734Sab196087 	conv_arg.buf = flags_buf->buf;
2944734Sab196087 
2950Sstevel@tonic-gate 	/*
2961618Srie 	 * Non-SPARC architectures presently provide no known flags.
2970Sstevel@tonic-gate 	 */
2980Sstevel@tonic-gate 	if ((mach == EM_SPARCV9) || (((mach == EM_SPARC) ||
2990Sstevel@tonic-gate 	    (mach == EM_SPARC32PLUS)) && flags)) {
3001618Srie 		/*
3011618Srie 		 * Valid vendor extension bits for SPARCV9.  These must be
3021618Srie 		 * updated along with elf_SPARC.h.
3031618Srie 		 */
3040Sstevel@tonic-gate 
3052352Sab196087 		conv_arg.oflags = conv_arg.rflags = flags;
3061618Srie 		if ((mach == EM_SPARCV9) && (flags <= EF_SPARCV9_RMO)) {
3072352Sab196087 			*lstr++ = MSG_ORIG(mm_flags[flags & EF_SPARCV9_MM]);
3082352Sab196087 			conv_arg.rflags &= ~EF_SPARCV9_MM;
3090Sstevel@tonic-gate 		}
3102352Sab196087 		*lstr = NULL;
3110Sstevel@tonic-gate 
3125088Sab196087 		(void) conv_expn_field(&conv_arg, fmt_flags);
3130Sstevel@tonic-gate 
3144734Sab196087 		return (conv_arg.buf);
3151618Srie 	}
3164734Sab196087 
3174734Sab196087 	return (conv_invalid_val(&flags_buf->inv_buf, flags, CONV_FMT_DECIMAL));
3180Sstevel@tonic-gate }
3190Sstevel@tonic-gate 
3200Sstevel@tonic-gate /*
3213850Sab196087  * Make a string representation of the e_ident[EI_OSABI] field.
3223850Sab196087  */
3233850Sab196087 const char *
3245088Sab196087 conv_ehdr_osabi(uchar_t osabi, Conv_fmt_flags_t fmt_flags,
3255088Sab196087     Conv_inv_buf_t *inv_buf)
3263850Sab196087 {
3273850Sab196087 	static const Msg	osabi_arr[] = {
3283850Sab196087 		MSG_OSABI_NONE,		MSG_OSABI_HPUX,
3293850Sab196087 		MSG_OSABI_NETBSD,	MSG_OSABI_LINUX,
3303850Sab196087 		MSG_OSABI_UNKNOWN4,	MSG_OSABI_UNKNOWN5,
3313850Sab196087 		MSG_OSABI_SOLARIS,	MSG_OSABI_AIX,
3323850Sab196087 		MSG_OSABI_IRIX,		MSG_OSABI_FREEBSD,
3333850Sab196087 		MSG_OSABI_TRU64,	MSG_OSABI_MODESTO,
3343850Sab196087 		MSG_OSABI_OPENBSD,	MSG_OSABI_OPENVMS,
3353850Sab196087 		MSG_OSABI_NSK,		MSG_OSABI_AROS
3363850Sab196087 	};
3373850Sab196087 	static const Msg	osabi_arr_alt[] = {
3383850Sab196087 		MSG_OSABI_NONE_ALT,	MSG_OSABI_HPUX_ALT,
3393850Sab196087 		MSG_OSABI_NETBSD_ALT,	MSG_OSABI_LINUX_ALT,
3403850Sab196087 		MSG_OSABI_UNKNOWN4,	MSG_OSABI_UNKNOWN5,
3413850Sab196087 		MSG_OSABI_SOLARIS_ALT,	MSG_OSABI_AIX_ALT,
3423850Sab196087 		MSG_OSABI_IRIX_ALT,	MSG_OSABI_FREEBSD_ALT,
3433850Sab196087 		MSG_OSABI_TRU64_ALT,	MSG_OSABI_MODESTO_ALT,
3443850Sab196087 		MSG_OSABI_OPENBSD_ALT,	MSG_OSABI_OPENVMS_ALT,
3453850Sab196087 		MSG_OSABI_NSK_ALT,	MSG_OSABI_AROS_ALT
3463850Sab196087 	};
3473850Sab196087 
3483850Sab196087 	const char *str;
3493850Sab196087 
3503850Sab196087 	switch (osabi) {
3513850Sab196087 	case ELFOSABI_ARM:
3525088Sab196087 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
3535088Sab196087 		case CONV_FMT_ALT_DUMP:
3545088Sab196087 		case CONV_FMT_ALT_FILE:
3555088Sab196087 			str = MSG_ORIG(MSG_OSABI_ARM_ALT);
3565088Sab196087 			break;
3575088Sab196087 		default:
3585088Sab196087 			str = MSG_ORIG(MSG_OSABI_ARM);
3595088Sab196087 		}
3603850Sab196087 		break;
3613850Sab196087 
3623850Sab196087 	case ELFOSABI_STANDALONE:
3635088Sab196087 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
3645088Sab196087 		case CONV_FMT_ALT_DUMP:
3655088Sab196087 		case CONV_FMT_ALT_FILE:
3665088Sab196087 			str = MSG_ORIG(MSG_OSABI_STANDALONE_ALT);
3675088Sab196087 			break;
3685088Sab196087 		default:
3695088Sab196087 			str = MSG_ORIG(MSG_OSABI_STANDALONE);
3705088Sab196087 		}
3713850Sab196087 		break;
3723850Sab196087 
3733850Sab196087 	default:
3745088Sab196087 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
3755088Sab196087 		case CONV_FMT_ALT_DUMP:
3765088Sab196087 		case CONV_FMT_ALT_FILE:
3775088Sab196087 			str = conv_map2str(inv_buf, osabi, fmt_flags,
3785088Sab196087 			    ARRAY_NELTS(osabi_arr_alt), osabi_arr_alt);
3795088Sab196087 			break;
3805088Sab196087 		default:
3815088Sab196087 			str = conv_map2str(inv_buf, osabi, fmt_flags,
3825088Sab196087 			    ARRAY_NELTS(osabi_arr), osabi_arr);
3835088Sab196087 		}
3843850Sab196087 		break;
3853850Sab196087 	}
3863850Sab196087 
3873850Sab196087 	return (str);
3883850Sab196087 }
3893850Sab196087 
3903850Sab196087 /*
3910Sstevel@tonic-gate  * A generic means of returning additional information for a rejected file in
3920Sstevel@tonic-gate  * terms of a string.
3930Sstevel@tonic-gate  */
3940Sstevel@tonic-gate const char *
3954734Sab196087 conv_reject_desc(Rej_desc * rej, Conv_reject_desc_buf_t *reject_desc_buf)
3960Sstevel@tonic-gate {
3974734Sab196087 	ushort_t	type = rej->rej_type;
3984734Sab196087 	uint_t		info = rej->rej_info;
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate 	if (type == SGS_REJ_MACH)
4010Sstevel@tonic-gate 		/* LINTED */
4024734Sab196087 		return (conv_ehdr_mach((Half)info, 0,
4034734Sab196087 		    &reject_desc_buf->inv_buf));
4040Sstevel@tonic-gate 	else if (type == SGS_REJ_CLASS)
4050Sstevel@tonic-gate 		/* LINTED */
4064734Sab196087 		return (conv_ehdr_class((uchar_t)info, 0,
4074734Sab196087 		    &reject_desc_buf->inv_buf));
4080Sstevel@tonic-gate 	else if (type == SGS_REJ_DATA)
4090Sstevel@tonic-gate 		/* LINTED */
4104734Sab196087 		return (conv_ehdr_data((uchar_t)info, 0,
4114734Sab196087 		    &reject_desc_buf->inv_buf));
4120Sstevel@tonic-gate 	else if (type == SGS_REJ_TYPE)
4130Sstevel@tonic-gate 		/* LINTED */
4144734Sab196087 		return (conv_ehdr_type((Half)info, 0,
4154734Sab196087 		    &reject_desc_buf->inv_buf));
4160Sstevel@tonic-gate 	else if ((type == SGS_REJ_BADFLAG) || (type == SGS_REJ_MISFLAG) ||
4170Sstevel@tonic-gate 	    (type == SGS_REJ_HAL) || (type == SGS_REJ_US3))
4180Sstevel@tonic-gate 		/*
4190Sstevel@tonic-gate 		 * Only called from ld.so.1, thus M_MACH is hardcoded.
4200Sstevel@tonic-gate 		 */
4215088Sab196087 		return (conv_ehdr_flags(M_MACH, (Word)info, 0,
4224734Sab196087 		    &reject_desc_buf->flags_buf));
4230Sstevel@tonic-gate 	else if (type == SGS_REJ_UNKFILE)
4240Sstevel@tonic-gate 		return ((const char *)0);
4250Sstevel@tonic-gate 	else if ((type == SGS_REJ_STR) || (type == SGS_REJ_HWCAP_1)) {
4260Sstevel@tonic-gate 		if (rej->rej_str)
4270Sstevel@tonic-gate 			return ((const char *)rej->rej_str);
4280Sstevel@tonic-gate 		else
4290Sstevel@tonic-gate 			return (MSG_ORIG(MSG_STR_EMPTY));
4300Sstevel@tonic-gate 	} else
4314734Sab196087 		return (conv_invalid_val(&reject_desc_buf->inv_buf, info,
4321976Sab196087 		    CONV_FMT_DECIMAL));
4330Sstevel@tonic-gate }
434