xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/elf.c (revision 4734:a4708faa3e85)
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*4734Sab196087 conv_ehdr_class(uchar_t class, int fmt_flags, Conv_inv_buf_t *inv_buf)
460Sstevel@tonic-gate {
471618Srie 	static const Msg	classes[] = {
481976Sab196087 		MSG_ELFCLASSNONE, MSG_ELFCLASS32, MSG_ELFCLASS64
491976Sab196087 	};
501976Sab196087 	static const Msg	classes_alt[] = {
511976Sab196087 		MSG_ELFCLASSNONE_ALT, MSG_ELFCLASS32_ALT, MSG_ELFCLASS64_ALT
521618Srie 	};
530Sstevel@tonic-gate 
54*4734Sab196087 	return (conv_map2str(inv_buf, class, fmt_flags,
55*4734Sab196087 	    ARRAY_NELTS(classes), classes, classes_alt, classes_alt));
560Sstevel@tonic-gate }
570Sstevel@tonic-gate 
580Sstevel@tonic-gate const char *
59*4734Sab196087 conv_ehdr_data(uchar_t data, int fmt_flags, Conv_inv_buf_t *inv_buf)
600Sstevel@tonic-gate {
611618Srie 	static const Msg	datas[] = {
621976Sab196087 		MSG_ELFDATANONE, MSG_ELFDATA2LSB, MSG_ELFDATA2MSB
631976Sab196087 	};
641976Sab196087 	static const Msg	datas_dump[] = {
651976Sab196087 		MSG_ELFDATANONE_ALT, MSG_ELFDATA2LSB_ALT1, MSG_ELFDATA2MSB_ALT1
661976Sab196087 	};
671976Sab196087 	static const Msg	datas_file[] = {
681976Sab196087 		MSG_ELFDATANONE_ALT, MSG_ELFDATA2LSB_ALT2, MSG_ELFDATA2MSB_ALT2
691618Srie 	};
700Sstevel@tonic-gate 
71*4734Sab196087 	return (conv_map2str(inv_buf, data, fmt_flags,
72*4734Sab196087 	    ARRAY_NELTS(datas), datas, datas_dump, datas_file));
730Sstevel@tonic-gate }
740Sstevel@tonic-gate 
750Sstevel@tonic-gate static const Msg machines[EM_NUM] = {
761618Srie 	MSG_EM_NONE,		MSG_EM_M32,		MSG_EM_SPARC,
771618Srie 	MSG_EM_386,		MSG_EM_68K,		MSG_EM_88K,
781618Srie 	MSG_EM_486,		MSG_EM_860,		MSG_EM_MIPS,
792802Sab196087 	MSG_EM_S370,		MSG_EM_MIPS_RS3_LE,	MSG_EM_RS6000,
801618Srie 	MSG_EM_UNKNOWN12,	MSG_EM_UNKNOWN13,	MSG_EM_UNKNOWN14,
811618Srie 	MSG_EM_PA_RISC,		MSG_EM_nCUBE,		MSG_EM_VPP500,
822802Sab196087 	MSG_EM_SPARC32PLUS,	MSG_EM_960,		MSG_EM_PPC,
832802Sab196087 	MSG_EM_PPC64,		MSG_EM_S390,		MSG_EM_UNKNOWN23,
841618Srie 	MSG_EM_UNKNOWN24,	MSG_EM_UNKNOWN25,	MSG_EM_UNKNOWN26,
851618Srie 	MSG_EM_UNKNOWN27,	MSG_EM_UNKNOWN28,	MSG_EM_UNKNOWN29,
861618Srie 	MSG_EM_UNKNOWN30,	MSG_EM_UNKNOWN31,	MSG_EM_UNKNOWN32,
871618Srie 	MSG_EM_UNKNOWN33,	MSG_EM_UNKNOWN34,	MSG_EM_UNKNOWN35,
883850Sab196087 	MSG_EM_V800,		MSG_EM_FR20,		MSG_EM_RH32,
891618Srie 	MSG_EM_RCE,		MSG_EM_ARM,		MSG_EM_ALPHA,
901618Srie 	MSG_EM_SH,		MSG_EM_SPARCV9,		MSG_EM_TRICORE,
911618Srie 	MSG_EM_ARC,		MSG_EM_H8_300,		MSG_EM_H8_300H,
921618Srie 	MSG_EM_H8S,		MSG_EM_H8_500,		MSG_EM_IA_64,
931618Srie 	MSG_EM_MIPS_X,		MSG_EM_COLDFIRE,	MSG_EM_68HC12,
941618Srie 	MSG_EM_MMA,		MSG_EM_PCP,		MSG_EM_NCPU,
951618Srie 	MSG_EM_NDR1,		MSG_EM_STARCORE,	MSG_EM_ME16,
961618Srie 	MSG_EM_ST100,		MSG_EM_TINYJ,		MSG_EM_AMD64,
972802Sab196087 	MSG_EM_PDSP,		MSG_EM_UNKNOWN64,	MSG_EM_UNKNOWN65,
981618Srie 	MSG_EM_FX66,		MSG_EM_ST9PLUS,		MSG_EM_ST7,
991618Srie 	MSG_EM_68HC16,		MSG_EM_68HC11,		MSG_EM_68HC08,
1001618Srie 	MSG_EM_68HC05,		MSG_EM_SVX,		MSG_EM_ST19,
1011618Srie 	MSG_EM_VAX,		MSG_EM_CRIS,		MSG_EM_JAVELIN,
1021618Srie 	MSG_EM_FIREPATH,	MSG_EM_ZSP,		MSG_EM_MMIX,
1031618Srie 	MSG_EM_HUANY,		MSG_EM_PRISM,		MSG_EM_AVR,
1041618Srie 	MSG_EM_FR30,		MSG_EM_D10V,		MSG_EM_D30V,
1051618Srie 	MSG_EM_V850,		MSG_EM_M32R,		MSG_EM_MN10300,
1061618Srie 	MSG_EM_MN10200,		MSG_EM_PJ,		MSG_EM_OPENRISC,
1071618Srie 	MSG_EM_ARC_A5,		MSG_EM_XTENSA
1080Sstevel@tonic-gate };
1091976Sab196087 static const Msg machines_alt[EM_NUM] = {
1101976Sab196087 	MSG_EM_NONE_ALT,	MSG_EM_M32_ALT,		MSG_EM_SPARC_ALT,
1111976Sab196087 	MSG_EM_386_ALT,		MSG_EM_68K_ALT,		MSG_EM_88K_ALT,
1121976Sab196087 	MSG_EM_486_ALT,		MSG_EM_860_ALT,		MSG_EM_MIPS_ALT,
1132802Sab196087 	MSG_EM_S370,		MSG_EM_MIPS_RS3_LE_ALT,	MSG_EM_RS6000_ALT,
1141976Sab196087 	MSG_EM_UNKNOWN12,	MSG_EM_UNKNOWN13,	MSG_EM_UNKNOWN14,
1151976Sab196087 	MSG_EM_PA_RISC_ALT,	MSG_EM_nCUBE_ALT,	MSG_EM_VPP500_ALT,
1162802Sab196087 	MSG_EM_SPARC32PLUS_ALT,	MSG_EM_960,		MSG_EM_PPC_ALT,
1172802Sab196087 	MSG_EM_PPC64_ALT,	MSG_EM_S390,		MSG_EM_UNKNOWN23,
1181976Sab196087 	MSG_EM_UNKNOWN24,	MSG_EM_UNKNOWN25,	MSG_EM_UNKNOWN26,
1191976Sab196087 	MSG_EM_UNKNOWN27,	MSG_EM_UNKNOWN28,	MSG_EM_UNKNOWN29,
1201976Sab196087 	MSG_EM_UNKNOWN30,	MSG_EM_UNKNOWN31,	MSG_EM_UNKNOWN32,
1211976Sab196087 	MSG_EM_UNKNOWN33,	MSG_EM_UNKNOWN34,	MSG_EM_UNKNOWN35,
1223850Sab196087 	MSG_EM_V800,		MSG_EM_FR20,		MSG_EM_RH32,
1231976Sab196087 	MSG_EM_RCE,		MSG_EM_ARM_ALT,		MSG_EM_ALPHA_ALT,
1241976Sab196087 	MSG_EM_SH,		MSG_EM_SPARCV9_ALT,	MSG_EM_TRICORE,
1251976Sab196087 	MSG_EM_ARC,		MSG_EM_H8_300,		MSG_EM_H8_300H,
1261976Sab196087 	MSG_EM_H8S,		MSG_EM_H8_500,		MSG_EM_IA_64_ALT,
1271976Sab196087 	MSG_EM_MIPS_X,		MSG_EM_COLDFIRE,	MSG_EM_68HC12,
1281976Sab196087 	MSG_EM_MMA,		MSG_EM_PCP,		MSG_EM_NCPU,
1291976Sab196087 	MSG_EM_NDR1,		MSG_EM_STARCORE,	MSG_EM_ME16,
1301976Sab196087 	MSG_EM_ST100,		MSG_EM_TINYJ,		MSG_EM_AMD64_ALT,
1312802Sab196087 	MSG_EM_PDSP,		MSG_EM_UNKNOWN64,	MSG_EM_UNKNOWN65,
1321976Sab196087 	MSG_EM_FX66,		MSG_EM_ST9PLUS,		MSG_EM_ST7,
1331976Sab196087 	MSG_EM_68HC16,		MSG_EM_68HC11,		MSG_EM_68HC08,
1341976Sab196087 	MSG_EM_68HC05,		MSG_EM_SVX,		MSG_EM_ST19,
1351976Sab196087 	MSG_EM_VAX_ALT,		MSG_EM_CRIS,		MSG_EM_JAVELIN,
1361976Sab196087 	MSG_EM_FIREPATH,	MSG_EM_ZSP,		MSG_EM_MMIX,
1371976Sab196087 	MSG_EM_HUANY,		MSG_EM_PRISM,		MSG_EM_AVR,
1381976Sab196087 	MSG_EM_FR30,		MSG_EM_D10V,		MSG_EM_D30V,
1391976Sab196087 	MSG_EM_V850,		MSG_EM_M32R,		MSG_EM_MN10300,
1401976Sab196087 	MSG_EM_MN10200,		MSG_EM_PJ,		MSG_EM_OPENRISC,
1411976Sab196087 	MSG_EM_ARC_A5,		MSG_EM_XTENSA
1421976Sab196087 };
1430Sstevel@tonic-gate #if	(EM_NUM != (EM_XTENSA + 1))
1440Sstevel@tonic-gate #error	"EM_NUM has grown"
1450Sstevel@tonic-gate #endif
1461618Srie 
1471618Srie const char *
148*4734Sab196087 conv_ehdr_mach(Half machine, int fmt_flags, Conv_inv_buf_t *inv_buf)
1491618Srie {
150*4734Sab196087 	return (conv_map2str(inv_buf, machine, fmt_flags,
151*4734Sab196087 	    ARRAY_NELTS(machines), machines, machines_alt, machines_alt));
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate 
1541976Sab196087 
1550Sstevel@tonic-gate const char *
156*4734Sab196087 conv_ehdr_type(Half etype, int fmt_flags, Conv_inv_buf_t *inv_buf)
1570Sstevel@tonic-gate {
1581618Srie 	static const Msg	etypes[] = {
1591618Srie 		MSG_ET_NONE,		MSG_ET_REL,		MSG_ET_EXEC,
1601618Srie 		MSG_ET_DYN,		MSG_ET_CORE
1611618Srie 	};
1621976Sab196087 	static const Msg	etypes_alt[] = {
1631976Sab196087 		MSG_ET_NONE_ALT,	MSG_ET_REL_ALT,		MSG_ET_EXEC_ALT,
1641976Sab196087 		MSG_ET_DYN_ALT,		MSG_ET_CORE_ALT
1651976Sab196087 	};
1660Sstevel@tonic-gate 
1671976Sab196087 	if (etype == ET_SUNWPSEUDO) {
1681976Sab196087 		return ((fmt_flags & CONV_FMTALTMASK)
169*4734Sab196087 		    ? MSG_ORIG(MSG_ET_SUNWPSEUDO_ALT)
170*4734Sab196087 		    : MSG_ORIG(MSG_ET_SUNWPSEUDO));
1711976Sab196087 	}
1721976Sab196087 
173*4734Sab196087 	return (conv_map2str(inv_buf, etype, fmt_flags,
174*4734Sab196087 	    ARRAY_NELTS(etypes), etypes, etypes_alt, etypes_alt));
1751976Sab196087 
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate const char *
179*4734Sab196087 conv_ehdr_vers(Word version, int fmt_flags, Conv_inv_buf_t *inv_buf)
1800Sstevel@tonic-gate {
1811618Srie 	static const Msg	versions[] = {
1821618Srie 		MSG_EV_NONE,		MSG_EV_CURRENT
1831618Srie 	};
1841976Sab196087 	static const Msg	versions_alt[] = {
1851976Sab196087 		MSG_EV_NONE_ALT,	MSG_EV_CURRENT_ALT
1861976Sab196087 	};
1870Sstevel@tonic-gate 
188*4734Sab196087 	return (conv_map2str(inv_buf, version, fmt_flags,
189*4734Sab196087 	    ARRAY_NELTS(versions), versions, versions_alt, versions_alt));
1900Sstevel@tonic-gate }
1910Sstevel@tonic-gate 
1922352Sab196087 #define	EFLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
1932352Sab196087 		MSG_EF_SPARCV9_TSO_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
1942352Sab196087 		MSG_EF_SPARC_SUN_US1_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
1952352Sab196087 		MSG_EF_SPARC_HAL_R1_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
1962352Sab196087 		MSG_EF_SPARC_SUN_US3_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
197*4734Sab196087 		CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
198*4734Sab196087 
199*4734Sab196087 /*
200*4734Sab196087  * Ensure that Conv_ehdr_flags_buf_t is large enough:
201*4734Sab196087  *
202*4734Sab196087  * EFLAGSZ is the real minimum size of the buffer required by conv_ehdr_flags().
203*4734Sab196087  * However, Conv_ehdr_flags_buf_t uses CONV_EHDR_FLAG_BUFSIZE to set the
204*4734Sab196087  * buffer size. We do things this way because the definition of EFLAGSZ uses
205*4734Sab196087  * information that is not available in the environment of other programs
206*4734Sab196087  * that include the conv.h header file.
207*4734Sab196087  */
208*4734Sab196087 #if CONV_EHDR_FLAGS_BUFSIZE < EFLAGSZ
209*4734Sab196087 #error "CONV_EHDR_FLAGS_BUFSIZE is not large enough"
210*4734Sab196087 #endif
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate /*
2131618Srie  * Make a string representation of the e_flags field.
2140Sstevel@tonic-gate  */
2150Sstevel@tonic-gate const char *
216*4734Sab196087 conv_ehdr_flags(Half mach, Word flags, Conv_ehdr_flags_buf_t *flags_buf)
2170Sstevel@tonic-gate {
2181618Srie 	static Val_desc vda[] = {
2191618Srie 		{ EF_SPARC_32PLUS,	MSG_ORIG(MSG_EF_SPARC_32PLUS) },
2201618Srie 		{ EF_SPARC_SUN_US1,	MSG_ORIG(MSG_EF_SPARC_SUN_US1) },
2211618Srie 		{ EF_SPARC_HAL_R1,	MSG_ORIG(MSG_EF_SPARC_HAL_R1) },
2221618Srie 		{ EF_SPARC_SUN_US3,	MSG_ORIG(MSG_EF_SPARC_SUN_US3) },
2231618Srie 		{ 0,			0 }
2241618Srie 	};
2251618Srie 	static const Msg mm_flags[] = {
2261618Srie 		MSG_EF_SPARCV9_TSO,	MSG_EF_SPARCV9_PSO,
2271618Srie 		MSG_EF_SPARCV9_RMO
2281618Srie 	};
2292352Sab196087 	static const char *leading_str_arr[2];
230*4734Sab196087 	static CONV_EXPN_FIELD_ARG conv_arg = {
231*4734Sab196087 	    NULL, sizeof (flags_buf->buf), vda, leading_str_arr };
2322352Sab196087 
2332352Sab196087 	const char **lstr = leading_str_arr;
2340Sstevel@tonic-gate 
235*4734Sab196087 	conv_arg.buf = flags_buf->buf;
236*4734Sab196087 
2370Sstevel@tonic-gate 	/*
2381618Srie 	 * Non-SPARC architectures presently provide no known flags.
2390Sstevel@tonic-gate 	 */
2400Sstevel@tonic-gate 	if ((mach == EM_SPARCV9) || (((mach == EM_SPARC) ||
2410Sstevel@tonic-gate 	    (mach == EM_SPARC32PLUS)) && flags)) {
2421618Srie 		/*
2431618Srie 		 * Valid vendor extension bits for SPARCV9.  These must be
2441618Srie 		 * updated along with elf_SPARC.h.
2451618Srie 		 */
2460Sstevel@tonic-gate 
2472352Sab196087 		conv_arg.oflags = conv_arg.rflags = flags;
2481618Srie 		if ((mach == EM_SPARCV9) && (flags <= EF_SPARCV9_RMO)) {
2492352Sab196087 			*lstr++ = MSG_ORIG(mm_flags[flags & EF_SPARCV9_MM]);
2502352Sab196087 			conv_arg.rflags &= ~EF_SPARCV9_MM;
2510Sstevel@tonic-gate 		}
2522352Sab196087 		*lstr = NULL;
2530Sstevel@tonic-gate 
2542352Sab196087 		(void) conv_expn_field(&conv_arg);
2550Sstevel@tonic-gate 
256*4734Sab196087 		return (conv_arg.buf);
2571618Srie 	}
258*4734Sab196087 
259*4734Sab196087 	return (conv_invalid_val(&flags_buf->inv_buf, flags, CONV_FMT_DECIMAL));
2600Sstevel@tonic-gate }
2610Sstevel@tonic-gate 
2620Sstevel@tonic-gate /*
2633850Sab196087  * Make a string representation of the e_ident[EI_OSABI] field.
2643850Sab196087  */
2653850Sab196087 const char *
266*4734Sab196087 conv_ehdr_osabi(uchar_t osabi, int fmt_flags, Conv_inv_buf_t *inv_buf)
2673850Sab196087 {
2683850Sab196087 	static const Msg	osabi_arr[] = {
2693850Sab196087 		MSG_OSABI_NONE,		MSG_OSABI_HPUX,
2703850Sab196087 		MSG_OSABI_NETBSD,	MSG_OSABI_LINUX,
2713850Sab196087 		MSG_OSABI_UNKNOWN4,	MSG_OSABI_UNKNOWN5,
2723850Sab196087 		MSG_OSABI_SOLARIS,	MSG_OSABI_AIX,
2733850Sab196087 		MSG_OSABI_IRIX,		MSG_OSABI_FREEBSD,
2743850Sab196087 		MSG_OSABI_TRU64,	MSG_OSABI_MODESTO,
2753850Sab196087 		MSG_OSABI_OPENBSD,	MSG_OSABI_OPENVMS,
2763850Sab196087 		MSG_OSABI_NSK,		MSG_OSABI_AROS
2773850Sab196087 	};
2783850Sab196087 	static const Msg	osabi_arr_alt[] = {
2793850Sab196087 		MSG_OSABI_NONE_ALT,	MSG_OSABI_HPUX_ALT,
2803850Sab196087 		MSG_OSABI_NETBSD_ALT,	MSG_OSABI_LINUX_ALT,
2813850Sab196087 		MSG_OSABI_UNKNOWN4,	MSG_OSABI_UNKNOWN5,
2823850Sab196087 		MSG_OSABI_SOLARIS_ALT,	MSG_OSABI_AIX_ALT,
2833850Sab196087 		MSG_OSABI_IRIX_ALT,	MSG_OSABI_FREEBSD_ALT,
2843850Sab196087 		MSG_OSABI_TRU64_ALT,	MSG_OSABI_MODESTO_ALT,
2853850Sab196087 		MSG_OSABI_OPENBSD_ALT,	MSG_OSABI_OPENVMS_ALT,
2863850Sab196087 		MSG_OSABI_NSK_ALT,	MSG_OSABI_AROS_ALT
2873850Sab196087 	};
2883850Sab196087 
2893850Sab196087 	const char *str;
2903850Sab196087 
2913850Sab196087 	switch (osabi) {
2923850Sab196087 	case ELFOSABI_ARM:
2933850Sab196087 		str = (fmt_flags & CONV_FMTALTMASK) ?
2943850Sab196087 		    MSG_ORIG(MSG_OSABI_ARM_ALT) : MSG_ORIG(MSG_OSABI_ARM);
2953850Sab196087 		break;
2963850Sab196087 
2973850Sab196087 	case ELFOSABI_STANDALONE:
2983850Sab196087 		str = (fmt_flags & CONV_FMTALTMASK) ?
2993850Sab196087 		    MSG_ORIG(MSG_OSABI_STANDALONE_ALT) :
3003850Sab196087 		    MSG_ORIG(MSG_OSABI_STANDALONE);
3013850Sab196087 		break;
3023850Sab196087 
3033850Sab196087 	default:
304*4734Sab196087 		str = conv_map2str(inv_buf, osabi, fmt_flags,
305*4734Sab196087 		    ARRAY_NELTS(osabi_arr), osabi_arr, osabi_arr_alt,
306*4734Sab196087 		    osabi_arr_alt);
3073850Sab196087 		break;
3083850Sab196087 	}
3093850Sab196087 
3103850Sab196087 	return (str);
3113850Sab196087 }
3123850Sab196087 
3133850Sab196087 /*
3140Sstevel@tonic-gate  * A generic means of returning additional information for a rejected file in
3150Sstevel@tonic-gate  * terms of a string.
3160Sstevel@tonic-gate  */
3170Sstevel@tonic-gate const char *
318*4734Sab196087 conv_reject_desc(Rej_desc * rej, Conv_reject_desc_buf_t *reject_desc_buf)
3190Sstevel@tonic-gate {
320*4734Sab196087 	ushort_t	type = rej->rej_type;
321*4734Sab196087 	uint_t		info = rej->rej_info;
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate 	if (type == SGS_REJ_MACH)
3240Sstevel@tonic-gate 		/* LINTED */
325*4734Sab196087 		return (conv_ehdr_mach((Half)info, 0,
326*4734Sab196087 		    &reject_desc_buf->inv_buf));
3270Sstevel@tonic-gate 	else if (type == SGS_REJ_CLASS)
3280Sstevel@tonic-gate 		/* LINTED */
329*4734Sab196087 		return (conv_ehdr_class((uchar_t)info, 0,
330*4734Sab196087 		    &reject_desc_buf->inv_buf));
3310Sstevel@tonic-gate 	else if (type == SGS_REJ_DATA)
3320Sstevel@tonic-gate 		/* LINTED */
333*4734Sab196087 		return (conv_ehdr_data((uchar_t)info, 0,
334*4734Sab196087 		    &reject_desc_buf->inv_buf));
3350Sstevel@tonic-gate 	else if (type == SGS_REJ_TYPE)
3360Sstevel@tonic-gate 		/* LINTED */
337*4734Sab196087 		return (conv_ehdr_type((Half)info, 0,
338*4734Sab196087 		    &reject_desc_buf->inv_buf));
3390Sstevel@tonic-gate 	else if ((type == SGS_REJ_BADFLAG) || (type == SGS_REJ_MISFLAG) ||
3400Sstevel@tonic-gate 	    (type == SGS_REJ_HAL) || (type == SGS_REJ_US3))
3410Sstevel@tonic-gate 		/*
3420Sstevel@tonic-gate 		 * Only called from ld.so.1, thus M_MACH is hardcoded.
3430Sstevel@tonic-gate 		 */
344*4734Sab196087 		return (conv_ehdr_flags(M_MACH, (Word)info,
345*4734Sab196087 		    &reject_desc_buf->flags_buf));
3460Sstevel@tonic-gate 	else if (type == SGS_REJ_UNKFILE)
3470Sstevel@tonic-gate 		return ((const char *)0);
3480Sstevel@tonic-gate 	else if ((type == SGS_REJ_STR) || (type == SGS_REJ_HWCAP_1)) {
3490Sstevel@tonic-gate 		if (rej->rej_str)
3500Sstevel@tonic-gate 			return ((const char *)rej->rej_str);
3510Sstevel@tonic-gate 		else
3520Sstevel@tonic-gate 			return (MSG_ORIG(MSG_STR_EMPTY));
3530Sstevel@tonic-gate 	} else
354*4734Sab196087 		return (conv_invalid_val(&reject_desc_buf->inv_buf, info,
3551976Sab196087 		    CONV_FMT_DECIMAL));
3560Sstevel@tonic-gate }
357