xref: /illumos-gate/usr/src/cmd/sgs/libconv/common/elf.c (revision ab5344c6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright (c) 2018, Joyent, Inc.
25  * Copyright 2022 Oxide Computer Company
26  */
27 
28 /*
29  * String conversion routines for ELF header attributes.
30  */
31 #include	<stdio.h>
32 #include	<string.h>
33 #include	"_conv.h"
34 #include	"elf_msg.h"
35 #include	<sys/elf_SPARC.h>
36 
37 
38 
39 static const conv_ds_t **
ehdr_class_strings(Conv_fmt_flags_t fmt_flags)40 ehdr_class_strings(Conv_fmt_flags_t fmt_flags)
41 {
42 	static const Msg	class_cf[] = {
43 		MSG_ELFCLASSNONE_CF, MSG_ELFCLASS32_CF, MSG_ELFCLASS64_CF
44 	};
45 	static const Msg	class_nf[] = {
46 		MSG_ELFCLASSNONE_NF, MSG_ELFCLASS32_NF, MSG_ELFCLASS64_NF
47 	};
48 	static const Msg	class_dump[] = {
49 		MSG_ELFCLASSNONE_DMP, MSG_ELFCLASS32_DMP, MSG_ELFCLASS64_DMP
50 	};
51 
52 	static const conv_ds_msg_t ds_classes_cf = {
53 	    CONV_DS_MSG_INIT(ELFCLASSNONE, class_cf) };
54 	static const conv_ds_msg_t ds_classes_nf = {
55 	    CONV_DS_MSG_INIT(ELFCLASSNONE, class_nf) };
56 	static const conv_ds_msg_t ds_classes_dump = {
57 	    CONV_DS_MSG_INIT(ELFCLASSNONE, class_dump) };
58 
59 	static const conv_ds_t *ds_cf[] = { CONV_DS_ADDR(ds_classes_cf), NULL };
60 	static const conv_ds_t *ds_nf[] = { CONV_DS_ADDR(ds_classes_nf), NULL };
61 	static const conv_ds_t *ds_dump[] = {
62 	    CONV_DS_ADDR(ds_classes_dump), NULL };
63 
64 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
65 	case CONV_FMT_ALT_DUMP:
66 	case CONV_FMT_ALT_FILE:
67 		return (ds_dump);
68 	case CONV_FMT_ALT_NF:
69 		return (ds_nf);
70 	}
71 
72 	return (ds_cf);
73 }
74 
75 const char *
conv_ehdr_class(uchar_t class,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)76 conv_ehdr_class(uchar_t class, Conv_fmt_flags_t fmt_flags,
77     Conv_inv_buf_t *inv_buf)
78 {
79 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, class,
80 	    ehdr_class_strings(fmt_flags), fmt_flags, inv_buf));
81 }
82 
83 conv_iter_ret_t
conv_iter_ehdr_class(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)84 conv_iter_ehdr_class(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
85     void *uvalue)
86 {
87 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
88 	    ehdr_class_strings(fmt_flags), func, uvalue));
89 }
90 
91 static const conv_ds_t **
ehdr_data_strings(Conv_fmt_flags_t fmt_flags)92 ehdr_data_strings(Conv_fmt_flags_t fmt_flags)
93 {
94 	static const Msg	data_cf[] = {
95 		MSG_ELFDATANONE_CF, MSG_ELFDATA2LSB_CF, MSG_ELFDATA2MSB_CF
96 	};
97 	static const Msg	data_nf[] = {
98 		MSG_ELFDATANONE_NF, MSG_ELFDATA2LSB_NF, MSG_ELFDATA2MSB_NF
99 	};
100 	static const Msg	data_dump[] = {
101 		MSG_ELFDATANONE_DMP, MSG_ELFDATA2LSB_DMP, MSG_ELFDATA2MSB_DMP
102 	};
103 	static const Msg	data_file[] = {
104 		MSG_ELFDATANONE_DMP, MSG_ELFDATA2LSB_FIL, MSG_ELFDATA2MSB_FIL
105 	};
106 
107 
108 	static const conv_ds_msg_t ds_data_cf = {
109 	    CONV_DS_MSG_INIT(ELFCLASSNONE, data_cf) };
110 	static const conv_ds_msg_t ds_data_nf = {
111 	    CONV_DS_MSG_INIT(ELFCLASSNONE, data_nf) };
112 	static const conv_ds_msg_t ds_data_dump = {
113 	    CONV_DS_MSG_INIT(ELFCLASSNONE, data_dump) };
114 	static const conv_ds_msg_t ds_data_file = {
115 	    CONV_DS_MSG_INIT(ELFCLASSNONE, data_file) };
116 
117 	static const conv_ds_t *ds_cf[] = { CONV_DS_ADDR(ds_data_cf), NULL };
118 	static const conv_ds_t *ds_nf[] = { CONV_DS_ADDR(ds_data_nf), NULL };
119 	static const conv_ds_t *ds_dump[] = { CONV_DS_ADDR(ds_data_dump),
120 	    NULL };
121 	static const conv_ds_t *ds_file[] = { CONV_DS_ADDR(ds_data_file),
122 	    NULL };
123 
124 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
125 	case CONV_FMT_ALT_DUMP:
126 		return (ds_dump);
127 	case CONV_FMT_ALT_FILE:
128 		return (ds_file);
129 	case CONV_FMT_ALT_NF:
130 		return (ds_nf);
131 	}
132 
133 	return (ds_cf);
134 }
135 
136 const char *
conv_ehdr_data(uchar_t data,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)137 conv_ehdr_data(uchar_t data, Conv_fmt_flags_t fmt_flags,
138     Conv_inv_buf_t *inv_buf)
139 {
140 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, data,
141 	    ehdr_data_strings(fmt_flags), fmt_flags, inv_buf));
142 }
143 
144 conv_iter_ret_t
conv_iter_ehdr_data(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)145 conv_iter_ehdr_data(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
146     void *uvalue)
147 {
148 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
149 	    ehdr_data_strings(fmt_flags), func, uvalue));
150 }
151 
152 static const conv_ds_t **
ehdr_mach_strings(Conv_fmt_flags_t fmt_flags)153 ehdr_mach_strings(Conv_fmt_flags_t fmt_flags)
154 {
155 
156 	static const Msg mach_0_11_cf[] = {
157 		MSG_EM_NONE_CF,		MSG_EM_M32_CF,
158 		MSG_EM_SPARC_CF,	MSG_EM_386_CF,
159 		MSG_EM_68K_CF,		MSG_EM_88K_CF,
160 		MSG_EM_486_CF,		MSG_EM_860_CF,
161 		MSG_EM_MIPS_CF,		MSG_EM_S370_CF,
162 		MSG_EM_MIPS_RS3_LE_CF,	MSG_EM_RS6000_CF
163 	};
164 	static const Msg mach_0_11_nf[] = {
165 		MSG_EM_NONE_NF,		MSG_EM_M32_NF,
166 		MSG_EM_SPARC_NF,	MSG_EM_386_NF,
167 		MSG_EM_68K_NF,		MSG_EM_88K_NF,
168 		MSG_EM_486_NF,		MSG_EM_860_NF,
169 		MSG_EM_MIPS_NF,		MSG_EM_S370_NF,
170 		MSG_EM_MIPS_RS3_LE_NF,	MSG_EM_RS6000_NF
171 	};
172 	static const Msg mach_0_11_dmp[] = {
173 		MSG_EM_NONE_DMP,	MSG_EM_M32_DMP,
174 		MSG_EM_SPARC_DMP,	MSG_EM_386_DMP,
175 		MSG_EM_68K_DMP,		MSG_EM_88K_DMP,
176 		MSG_EM_486_DMP,		MSG_EM_860_DMP,
177 		MSG_EM_MIPS_DMP,	MSG_EM_S370_CF,
178 		MSG_EM_MIPS_RS3_LE_DMP,	MSG_EM_RS6000_DMP
179 	};
180 	static const conv_ds_msg_t ds_mach_0_11_cf = {
181 	    CONV_DS_MSG_INIT(EM_NONE, mach_0_11_cf) };
182 	static const conv_ds_msg_t ds_mach_0_11_nf = {
183 	    CONV_DS_MSG_INIT(EM_NONE, mach_0_11_nf) };
184 	static const conv_ds_msg_t ds_mach_0_11_dmp = {
185 	    CONV_DS_MSG_INIT(EM_NONE, mach_0_11_dmp) };
186 
187 
188 	static const Msg mach_15_22_cf[] = {
189 		MSG_EM_PA_RISC_CF,	MSG_EM_NCUBE_CF,
190 		MSG_EM_VPP500_CF,	MSG_EM_SPARC32PLUS_CF,
191 		MSG_EM_960_CF,		MSG_EM_PPC_CF,
192 		MSG_EM_PPC64_CF,	MSG_EM_S390_CF
193 	};
194 	static const Msg mach_15_22_nf[] = {
195 		MSG_EM_PA_RISC_NF,	MSG_EM_NCUBE_NF,
196 		MSG_EM_VPP500_NF,	MSG_EM_SPARC32PLUS_NF,
197 		MSG_EM_960_NF,		MSG_EM_PPC_NF,
198 		MSG_EM_PPC64_NF,	MSG_EM_S390_NF
199 	};
200 	static const Msg mach_15_22_dmp[] = {
201 		MSG_EM_PA_RISC_DMP,	MSG_EM_NCUBE_DMP,
202 		MSG_EM_VPP500_DMP,	MSG_EM_SPARC32PLUS_DMP,
203 		MSG_EM_960_CF,		MSG_EM_PPC_DMP,
204 		MSG_EM_PPC64_DMP,	MSG_EM_S390_CF
205 	};
206 	static const conv_ds_msg_t ds_mach_15_22_cf = {
207 	    CONV_DS_MSG_INIT(EM_PA_RISC, mach_15_22_cf) };
208 	static const conv_ds_msg_t ds_mach_15_22_nf = {
209 	    CONV_DS_MSG_INIT(EM_PA_RISC, mach_15_22_nf) };
210 	static const conv_ds_msg_t ds_mach_15_22_dmp = {
211 	    CONV_DS_MSG_INIT(EM_PA_RISC, mach_15_22_dmp) };
212 
213 
214 	static const Msg mach_36_63_cf[] = {
215 		MSG_EM_V800_CF,		MSG_EM_FR20_CF,
216 		MSG_EM_RH32_CF,		MSG_EM_RCE_CF,
217 		MSG_EM_ARM_CF,		MSG_EM_ALPHA_CF,
218 		MSG_EM_SH_CF,		MSG_EM_SPARCV9_CF,
219 		MSG_EM_TRICORE_CF,	MSG_EM_ARC_CF,
220 		MSG_EM_H8_300_CF,	MSG_EM_H8_300H_CF,
221 		MSG_EM_H8S_CF,		MSG_EM_H8_500_CF,
222 		MSG_EM_IA_64_CF,	MSG_EM_MIPS_X_CF,
223 		MSG_EM_COLDFIRE_CF,	MSG_EM_68HC12_CF,
224 		MSG_EM_MMA_CF,		MSG_EM_PCP_CF,
225 		MSG_EM_NCPU_CF,		MSG_EM_NDR1_CF,
226 		MSG_EM_STARCORE_CF,	MSG_EM_ME16_CF,
227 		MSG_EM_ST100_CF,	MSG_EM_TINYJ_CF,
228 		MSG_EM_AMD64_CF,	MSG_EM_PDSP_CF
229 	};
230 	static const Msg mach_36_63_nf[] = {
231 		MSG_EM_V800_NF,		MSG_EM_FR20_NF,
232 		MSG_EM_RH32_NF,		MSG_EM_RCE_NF,
233 		MSG_EM_ARM_NF,		MSG_EM_ALPHA_NF,
234 		MSG_EM_SH_NF,		MSG_EM_SPARCV9_NF,
235 		MSG_EM_TRICORE_NF,	MSG_EM_ARC_NF,
236 		MSG_EM_H8_300_NF,	MSG_EM_H8_300H_NF,
237 		MSG_EM_H8S_NF,		MSG_EM_H8_500_NF,
238 		MSG_EM_IA_64_NF,	MSG_EM_MIPS_X_NF,
239 		MSG_EM_COLDFIRE_NF,	MSG_EM_68HC12_NF,
240 		MSG_EM_MMA_NF,		MSG_EM_PCP_NF,
241 		MSG_EM_NCPU_NF,		MSG_EM_NDR1_NF,
242 		MSG_EM_STARCORE_NF,	MSG_EM_ME16_NF,
243 		MSG_EM_ST100_NF,	MSG_EM_TINYJ_NF,
244 		MSG_EM_AMD64_NF,	MSG_EM_PDSP_NF
245 	};
246 	static const Msg mach_36_63_dmp[] = {
247 		MSG_EM_V800_CF,		MSG_EM_FR20_CF,
248 		MSG_EM_RH32_CF,		MSG_EM_RCE_CF,
249 		MSG_EM_ARM_DMP,		MSG_EM_ALPHA_DMP,
250 		MSG_EM_SH_CF,		MSG_EM_SPARCV9_DMP,
251 		MSG_EM_TRICORE_CF,	MSG_EM_ARC_CF,
252 		MSG_EM_H8_300_CF,	MSG_EM_H8_300H_CF,
253 		MSG_EM_H8S_CF,		MSG_EM_H8_500_CF,
254 		MSG_EM_IA_64_DMP,	MSG_EM_MIPS_X_CF,
255 		MSG_EM_COLDFIRE_CF,	MSG_EM_68HC12_CF,
256 		MSG_EM_MMA_CF,		MSG_EM_PCP_CF,
257 		MSG_EM_NCPU_CF,		MSG_EM_NDR1_CF,
258 		MSG_EM_STARCORE_CF,	MSG_EM_ME16_CF,
259 		MSG_EM_ST100_CF,	MSG_EM_TINYJ_CF,
260 		MSG_EM_AMD64_DMP,	MSG_EM_PDSP_CF
261 	};
262 	static const conv_ds_msg_t ds_mach_36_63_cf = {
263 	    CONV_DS_MSG_INIT(EM_V800, mach_36_63_cf) };
264 	static const conv_ds_msg_t ds_mach_36_63_nf = {
265 	    CONV_DS_MSG_INIT(EM_V800, mach_36_63_nf) };
266 	static const conv_ds_msg_t ds_mach_36_63_dmp = {
267 	    CONV_DS_MSG_INIT(EM_V800, mach_36_63_dmp) };
268 
269 
270 	static const Msg mach_66_120_cf[] = {
271 		MSG_EM_FX66_CF,		MSG_EM_ST9PLUS_CF,
272 		MSG_EM_ST7_CF,		MSG_EM_68HC16_CF,
273 		MSG_EM_68HC11_CF,	MSG_EM_68HC08_CF,
274 		MSG_EM_68HC05_CF,	MSG_EM_SVX_CF,
275 		MSG_EM_ST19_CF,		MSG_EM_VAX_CF,
276 		MSG_EM_CRIS_CF,		MSG_EM_JAVELIN_CF,
277 		MSG_EM_FIREPATH_CF,	MSG_EM_ZSP_CF,
278 		MSG_EM_MMIX_CF,		MSG_EM_HUANY_CF,
279 		MSG_EM_PRISM_CF,	MSG_EM_AVR_CF,
280 		MSG_EM_FR30_CF,		MSG_EM_D10V_CF,
281 		MSG_EM_D30V_CF,		MSG_EM_V850_CF,
282 		MSG_EM_M32R_CF,		MSG_EM_MN10300_CF,
283 		MSG_EM_MN10200_CF,	MSG_EM_PJ_CF,
284 		MSG_EM_OPENRISC_CF,	MSG_EM_ARC_A5_CF,
285 		MSG_EM_XTENSA_CF,	MSG_EM_VIDEOCORE_CF,
286 		MSG_EM_TMM_GPP_CF,	MSG_EM_NS32K_CF,
287 		MSG_EM_TPC_CF,		MSG_EM_SNP1K_CF,
288 		MSG_EM_ST200_CF,	MSG_EM_IP2K_CF,
289 		MSG_EM_MAX_CF,		MSG_EM_CR_CF,
290 		MSG_EM_F2MC16_CF,	MSG_EM_MSP430_CF,
291 		MSG_EM_BLACKFIN_CF,	MSG_EM_SE_C33_CF,
292 		MSG_EM_SEP_CF,		MSG_EM_ARCA_CF,
293 		MSG_EM_UNICORE_CF,	MSG_EM_EXCESS_CF,
294 		MSG_EM_DXP_CF,		MSG_EM_ALTERA_NIOS2_CF,
295 		MSG_EM_CRX_CF,		MSG_EM_XGATE_CF,
296 		MSG_EM_C166_CF,		MSG_EM_M16C_CF,
297 		MSG_EM_DSPIC30F_CF,	MSG_EM_CE_CF,
298 		MSG_EM_M32C_CF
299 	};
300 	static const Msg mach_66_120_nf[] = {
301 		MSG_EM_FX66_NF,		MSG_EM_ST9PLUS_NF,
302 		MSG_EM_ST7_NF,		MSG_EM_68HC16_NF,
303 		MSG_EM_68HC11_NF,	MSG_EM_68HC08_NF,
304 		MSG_EM_68HC05_NF,	MSG_EM_SVX_NF,
305 		MSG_EM_ST19_NF,		MSG_EM_VAX_NF,
306 		MSG_EM_CRIS_NF,		MSG_EM_JAVELIN_NF,
307 		MSG_EM_FIREPATH_NF,	MSG_EM_ZSP_NF,
308 		MSG_EM_MMIX_NF,		MSG_EM_HUANY_NF,
309 		MSG_EM_PRISM_NF,	MSG_EM_AVR_NF,
310 		MSG_EM_FR30_NF,		MSG_EM_D10V_NF,
311 		MSG_EM_D30V_NF,		MSG_EM_V850_NF,
312 		MSG_EM_M32R_NF,		MSG_EM_MN10300_NF,
313 		MSG_EM_MN10200_NF,	MSG_EM_PJ_NF,
314 		MSG_EM_OPENRISC_NF,	MSG_EM_ARC_A5_NF,
315 		MSG_EM_XTENSA_NF,	MSG_EM_VIDEOCORE_NF,
316 		MSG_EM_TMM_GPP_NF,	MSG_EM_NS32K_NF,
317 		MSG_EM_TPC_NF,		MSG_EM_SNP1K_NF,
318 		MSG_EM_ST200_NF,	MSG_EM_IP2K_NF,
319 		MSG_EM_MAX_NF,		MSG_EM_CR_NF,
320 		MSG_EM_F2MC16_NF,	MSG_EM_MSP430_NF,
321 		MSG_EM_BLACKFIN_NF,	MSG_EM_SE_C33_NF,
322 		MSG_EM_SEP_NF,		MSG_EM_ARCA_NF,
323 		MSG_EM_UNICORE_NF,	MSG_EM_EXCESS_NF,
324 		MSG_EM_DXP_NF,		MSG_EM_ALTERA_NIOS2_NF,
325 		MSG_EM_CRX_NF,		MSG_EM_XGATE_NF,
326 		MSG_EM_C166_NF,		MSG_EM_M16C_NF,
327 		MSG_EM_DSPIC30F_NF,	MSG_EM_CE_NF,
328 		MSG_EM_TSK3000_NF,	MSG_EM_RS08_NF,
329 		MSG_EM_SHARC_NF,	MSG_EM_ECOG2_NF,
330 		MSG_EM_SCORE7_NF,	MSG_EM_DSP24_NF,
331 		MSG_EM_VIDEOCORE3_NF,	MSG_EM_LATTICEMICO32_NF,
332 		MSG_EM_SE_C17_NF,	MSG_EM_TI_C6000_NF,
333 		MSG_EM_TI_C2000_NF,	MSG_EM_TI_C5500_NF,
334 		MSG_EM_TI_ARP32_NF,	MSG_EM_TI_PRU_NF
335 	};
336 	static const Msg mach_66_120_dmp[] = {
337 		MSG_EM_FX66_CF,		MSG_EM_ST9PLUS_CF,
338 		MSG_EM_ST7_CF,		MSG_EM_68HC16_CF,
339 		MSG_EM_68HC11_CF,	MSG_EM_68HC08_CF,
340 		MSG_EM_68HC05_CF,	MSG_EM_SVX_CF,
341 		MSG_EM_ST19_CF,		MSG_EM_VAX_DMP,
342 		MSG_EM_CRIS_CF,		MSG_EM_JAVELIN_CF,
343 		MSG_EM_FIREPATH_CF,	MSG_EM_ZSP_CF,
344 		MSG_EM_MMIX_CF,		MSG_EM_HUANY_CF,
345 		MSG_EM_PRISM_CF,	MSG_EM_AVR_CF,
346 		MSG_EM_FR30_CF,		MSG_EM_D10V_CF,
347 		MSG_EM_D30V_CF,		MSG_EM_V850_CF,
348 		MSG_EM_M32R_CF,		MSG_EM_MN10300_CF,
349 		MSG_EM_MN10200_CF,	MSG_EM_PJ_CF,
350 		MSG_EM_OPENRISC_CF,	MSG_EM_ARC_A5_CF,
351 		MSG_EM_XTENSA_CF,	MSG_EM_VIDEOCORE_CF,
352 		MSG_EM_TMM_GPP_CF,	MSG_EM_NS32K_CF,
353 		MSG_EM_TPC_CF,		MSG_EM_SNP1K_CF,
354 		MSG_EM_ST200_CF,	MSG_EM_IP2K_CF,
355 		MSG_EM_MAX_CF,		MSG_EM_CR_CF,
356 		MSG_EM_F2MC16_CF,	MSG_EM_MSP430_CF,
357 		MSG_EM_BLACKFIN_CF,	MSG_EM_SE_C33_CF,
358 		MSG_EM_SEP_CF,		MSG_EM_ARCA_CF,
359 		MSG_EM_UNICORE_CF,	MSG_EM_EXCESS_CF,
360 		MSG_EM_DXP_CF,		MSG_EM_ALTERA_NIOS2_CF,
361 		MSG_EM_CRX_CF,		MSG_EM_XGATE_CF,
362 		MSG_EM_C166_CF,		MSG_EM_M16C_CF,
363 		MSG_EM_DSPIC30F_CF,	MSG_EM_CE_CF,
364 		MSG_EM_M32C_CF
365 	};
366 
367 	static const conv_ds_msg_t ds_mach_66_120_cf = {
368 	    CONV_DS_MSG_INIT(EM_FX66, mach_66_120_cf) };
369 	static const conv_ds_msg_t ds_mach_66_120_nf = {
370 	    CONV_DS_MSG_INIT(EM_FX66, mach_66_120_nf) };
371 	static const conv_ds_msg_t ds_mach_66_120_dmp = {
372 	    CONV_DS_MSG_INIT(EM_FX66, mach_66_120_dmp) };
373 
374 	static const Msg mach_131_144_cf[] = {
375 		MSG_EM_TSK3000_CF,	MSG_EM_RS08_CF,
376 		MSG_EM_SHARC_CF,	MSG_EM_ECOG2_CF,
377 		MSG_EM_SCORE7_CF,	MSG_EM_DSP24_CF,
378 		MSG_EM_VIDEOCORE3_CF,	MSG_EM_LATTICEMICO32_CF,
379 		MSG_EM_SE_C17_CF,	MSG_EM_TI_C6000_CF,
380 		MSG_EM_TI_C2000_CF,	MSG_EM_TI_C5500_CF,
381 		MSG_EM_TI_ARP32_CF,	MSG_EM_TI_PRU_CF
382 	};
383 	static const Msg mach_131_144_nf[] = {
384 		MSG_EM_TSK3000_NF,	MSG_EM_RS08_NF,
385 		MSG_EM_SHARC_NF,	MSG_EM_ECOG2_NF,
386 		MSG_EM_SCORE7_NF,	MSG_EM_DSP24_NF,
387 		MSG_EM_VIDEOCORE3_NF,	MSG_EM_LATTICEMICO32_NF,
388 		MSG_EM_SE_C17_NF,	MSG_EM_TI_C6000_NF,
389 		MSG_EM_TI_C2000_NF,	MSG_EM_TI_C5500_NF,
390 		MSG_EM_TI_ARP32_NF,	MSG_EM_TI_PRU_NF
391 	};
392 	static const Msg mach_131_144_dmp[] = {
393 		MSG_EM_TSK3000_CF,	MSG_EM_RS08_CF,
394 		MSG_EM_SHARC_CF,	MSG_EM_ECOG2_CF,
395 		MSG_EM_SCORE7_CF,	MSG_EM_DSP24_CF,
396 		MSG_EM_VIDEOCORE3_CF,	MSG_EM_LATTICEMICO32_CF,
397 		MSG_EM_SE_C17_CF,	MSG_EM_TI_C6000_CF,
398 		MSG_EM_TI_C2000_CF,	MSG_EM_TI_C5500_CF,
399 		MSG_EM_TI_ARP32_CF,	MSG_EM_TI_PRU_CF
400 	};
401 	static const conv_ds_msg_t ds_mach_131_144_cf = {
402 	    CONV_DS_MSG_INIT(EM_TSK3000, mach_131_144_cf) };
403 	static const conv_ds_msg_t ds_mach_131_144_nf = {
404 	    CONV_DS_MSG_INIT(EM_TSK3000, mach_131_144_nf) };
405 	static const conv_ds_msg_t ds_mach_131_144_dmp = {
406 	    CONV_DS_MSG_INIT(EM_TSK3000, mach_131_144_dmp) };
407 
408 	static const Msg mach_160_181_cf[] = {
409 		MSG_EM_MMDSP_PLUS_CF,	MSG_EM_CYPRESS_M8C_CF,
410 		MSG_EM_R32C_CF,		MSG_EM_TRIMEDIA_CF,
411 		MSG_EM_QDSP6_CF,	MSG_EM_8051_CF,
412 		MSG_EM_STXP7X_CF,	MSG_EM_NDS32_CF,
413 		MSG_EM_ECOG1_CF,	MSG_EM_MAXQ30_CF,
414 		MSG_EM_XIMO16_CF,	MSG_EM_MANIK_CF,
415 		MSG_EM_CRAYNV2_CF,	MSG_EM_RX_CF,
416 		MSG_EM_METAG_CF,	MSG_EM_MCST_ELBRUS_CF,
417 		MSG_EM_ECOG16_CF,	MSG_EM_CR16_CF,
418 		MSG_EM_ETPU_CF,		MSG_EM_SLE9X_CF,
419 		MSG_EM_L10M_CF,		MSG_EM_K10M_CF,
420 	};
421 	static const Msg mach_160_181_nf[] = {
422 		MSG_EM_MMDSP_PLUS_NF,	MSG_EM_CYPRESS_M8C_NF,
423 		MSG_EM_R32C_NF,		MSG_EM_TRIMEDIA_NF,
424 		MSG_EM_QDSP6_NF,	MSG_EM_8051_NF,
425 		MSG_EM_STXP7X_NF,	MSG_EM_NDS32_NF,
426 		MSG_EM_ECOG1_NF,	MSG_EM_MAXQ30_NF,
427 		MSG_EM_XIMO16_NF,	MSG_EM_MANIK_NF,
428 		MSG_EM_CRAYNV2_NF,	MSG_EM_RX_NF,
429 		MSG_EM_METAG_NF,	MSG_EM_MCST_ELBRUS_NF,
430 		MSG_EM_ECOG16_NF,	MSG_EM_CR16_NF,
431 		MSG_EM_ETPU_NF,		MSG_EM_SLE9X_NF,
432 		MSG_EM_L10M_NF,		MSG_EM_K10M_NF,
433 	};
434 	static const Msg mach_160_181_dmp[] = {
435 		MSG_EM_MMDSP_PLUS_CF,	MSG_EM_CYPRESS_M8C_CF,
436 		MSG_EM_R32C_CF,		MSG_EM_TRIMEDIA_CF,
437 		MSG_EM_QDSP6_CF,	MSG_EM_8051_CF,
438 		MSG_EM_STXP7X_CF,	MSG_EM_NDS32_CF,
439 		MSG_EM_ECOG1_CF,	MSG_EM_MAXQ30_CF,
440 		MSG_EM_XIMO16_CF,	MSG_EM_MANIK_CF,
441 		MSG_EM_CRAYNV2_CF,	MSG_EM_RX_CF,
442 		MSG_EM_METAG_CF,	MSG_EM_MCST_ELBRUS_CF,
443 		MSG_EM_ECOG16_CF,	MSG_EM_CR16_CF,
444 		MSG_EM_ETPU_CF,		MSG_EM_SLE9X_CF,
445 		MSG_EM_L10M_CF,		MSG_EM_K10M_CF,
446 	};
447 	static const conv_ds_msg_t ds_mach_160_181_cf = {
448 	    CONV_DS_MSG_INIT(EM_MMDSP_PLUS, mach_160_181_cf) };
449 	static const conv_ds_msg_t ds_mach_160_181_nf = {
450 	    CONV_DS_MSG_INIT(EM_MMDSP_PLUS, mach_160_181_nf) };
451 	static const conv_ds_msg_t ds_mach_160_181_dmp = {
452 	    CONV_DS_MSG_INIT(EM_MMDSP_PLUS, mach_160_181_dmp) };
453 
454 	static const Msg mach_183_cf[] = {
455 		MSG_EM_AARCH64_CF
456 	};
457 	static const Msg mach_183_nf[] = {
458 		MSG_EM_AARCH64_NF
459 	};
460 	static const Msg mach_183_dmp[] = {
461 		MSG_EM_AARCH64_CF
462 	};
463 	static const conv_ds_msg_t ds_mach_183_cf = {
464 	    CONV_DS_MSG_INIT(EM_AARCH64, mach_183_cf) };
465 	static const conv_ds_msg_t ds_mach_183_nf = {
466 	    CONV_DS_MSG_INIT(EM_AARCH64, mach_183_nf) };
467 	static const conv_ds_msg_t ds_mach_183_dmp = {
468 	    CONV_DS_MSG_INIT(EM_AARCH64, mach_183_dmp) };
469 
470 	static const Msg mach_185_224_cf[] = {
471 		MSG_EM_AVR32_CF,	MSG_EM_STM8_CF,
472 		MSG_EM_TILE64_CF,	MSG_EM_TILEPRO_CF,
473 		MSG_EM_MICROBLAZE_CF,	MSG_EM_CUDA_CF,
474 		MSG_EM_TILEGX_CF,	MSG_EM_CLOUDSHIELD_CF,
475 		MSG_EM_COREA_1ST_CF,	MSG_EM_COREA_2ND_CF,
476 		MSG_EM_ARC_COMPACT2_CF,	MSG_EM_OPEN8_CF,
477 		MSG_EM_RL78_CF,		MSG_EM_VIDEOCORE5_CF,
478 		MSG_EM_78KOR_CF,	MSG_EM_56800EX_CF,
479 		MSG_EM_BA1_CF,		MSG_EM_BA2_CF,
480 		MSG_EM_XCORE_CF,	MSG_EM_MCHP_PIC_CF,
481 		MSG_EM_INTEL205_CF,	MSG_EM_INTEL206_CF,
482 		MSG_EM_INTEL207_CF,	MSG_EM_INTEL208_CF,
483 		MSG_EM_INTEL209_CF,	MSG_EM_KM32_CF,
484 		MSG_EM_KMX32_CF,	MSG_EM_KMX16_CF,
485 		MSG_EM_KMX8_CF,		MSG_EM_KVARC_CF,
486 		MSG_EM_CDP_CF,		MSG_EM_COGE_CF,
487 		MSG_EM_COOL_CF,		MSG_EM_NORC_CF,
488 		MSG_EM_CSR_KALIMBA_CF,	MSG_EM_Z80_CF,
489 		MSG_EM_VISIUM_CF,	MSG_EM_FT32_CF,
490 		MSG_EM_MOXIE_CF,	MSG_EM_AMDGPU_CF
491 	};
492 	static const Msg mach_185_224_nf[] = {
493 		MSG_EM_AVR32_NF,	MSG_EM_STM8_NF,
494 		MSG_EM_TILE64_NF,	MSG_EM_TILEPRO_NF,
495 		MSG_EM_MICROBLAZE_NF,	MSG_EM_CUDA_NF,
496 		MSG_EM_TILEGX_NF,	MSG_EM_CLOUDSHIELD_NF,
497 		MSG_EM_COREA_1ST_NF,	MSG_EM_COREA_2ND_NF,
498 		MSG_EM_ARC_COMPACT2_NF,	MSG_EM_OPEN8_NF,
499 		MSG_EM_RL78_NF,		MSG_EM_VIDEOCORE5_NF,
500 		MSG_EM_78KOR_NF,	MSG_EM_56800EX_NF,
501 		MSG_EM_BA1_NF,		MSG_EM_BA2_NF,
502 		MSG_EM_XCORE_NF,	MSG_EM_MCHP_PIC_NF,
503 		MSG_EM_INTEL205_NF,	MSG_EM_INTEL206_NF,
504 		MSG_EM_INTEL207_NF,	MSG_EM_INTEL208_NF,
505 		MSG_EM_INTEL209_NF,	MSG_EM_KM32_NF,
506 		MSG_EM_KMX32_NF,	MSG_EM_KMX16_NF,
507 		MSG_EM_KMX8_NF,		MSG_EM_KVARC_NF,
508 		MSG_EM_CDP_NF,		MSG_EM_COGE_NF,
509 		MSG_EM_COOL_NF,		MSG_EM_NORC_NF,
510 		MSG_EM_CSR_KALIMBA_NF,	MSG_EM_Z80_NF,
511 		MSG_EM_VISIUM_NF,	MSG_EM_FT32_NF,
512 		MSG_EM_MOXIE_NF,	MSG_EM_AMDGPU_NF
513 	};
514 	static const Msg mach_185_224_dmp[] = {
515 		MSG_EM_AVR32_CF,	MSG_EM_STM8_CF,
516 		MSG_EM_TILE64_CF,	MSG_EM_TILEPRO_CF,
517 		MSG_EM_MICROBLAZE_CF,	MSG_EM_CUDA_CF,
518 		MSG_EM_TILEGX_CF,	MSG_EM_CLOUDSHIELD_CF,
519 		MSG_EM_COREA_1ST_CF,	MSG_EM_COREA_2ND_CF,
520 		MSG_EM_ARC_COMPACT2_CF,	MSG_EM_OPEN8_CF,
521 		MSG_EM_RL78_CF,		MSG_EM_VIDEOCORE5_CF,
522 		MSG_EM_78KOR_CF,	MSG_EM_56800EX_CF,
523 		MSG_EM_BA1_CF,		MSG_EM_BA2_CF,
524 		MSG_EM_XCORE_CF,	MSG_EM_MCHP_PIC_CF,
525 		MSG_EM_INTEL205_CF,	MSG_EM_INTEL206_CF,
526 		MSG_EM_INTEL207_CF,	MSG_EM_INTEL208_CF,
527 		MSG_EM_INTEL209_CF,	MSG_EM_KM32_CF,
528 		MSG_EM_KMX32_CF,	MSG_EM_KMX16_CF,
529 		MSG_EM_KMX8_CF,		MSG_EM_KVARC_CF,
530 		MSG_EM_CDP_CF,		MSG_EM_COGE_CF,
531 		MSG_EM_COOL_CF,		MSG_EM_NORC_CF,
532 		MSG_EM_CSR_KALIMBA_CF,	MSG_EM_Z80_CF,
533 		MSG_EM_VISIUM_CF,	MSG_EM_FT32_CF,
534 		MSG_EM_MOXIE_CF,	MSG_EM_AMDGPU_CF
535 	};
536 
537 	static const conv_ds_msg_t ds_mach_185_224_cf = {
538 	    CONV_DS_MSG_INIT(EM_AVR32, mach_185_224_cf) };
539 	static const conv_ds_msg_t ds_mach_185_224_nf = {
540 	    CONV_DS_MSG_INIT(EM_AVR32, mach_185_224_nf) };
541 	static const conv_ds_msg_t ds_mach_185_224_dmp = {
542 	    CONV_DS_MSG_INIT(EM_AVR32, mach_185_224_dmp) };
543 
544 
545 	static const Msg mach_243_cf[] = {
546 		MSG_EM_RISCV_CF
547 	};
548 	static const Msg mach_243_nf[] = {
549 		MSG_EM_RISCV_NF
550 	};
551 	static const Msg mach_243_dmp[] = {
552 		MSG_EM_RISCV_CF
553 	};
554 
555 	static const conv_ds_msg_t ds_mach_243_cf = {
556 	    CONV_DS_MSG_INIT(EM_RISCV, mach_243_cf) };
557 	static const conv_ds_msg_t ds_mach_243_nf = {
558 	    CONV_DS_MSG_INIT(EM_RISCV, mach_243_nf) };
559 	static const conv_ds_msg_t ds_mach_243_dmp = {
560 	    CONV_DS_MSG_INIT(EM_RISCV, mach_243_dmp) };
561 
562 #if	(EM_NUM != (EM_RISCV + 1))
563 #error	"EM_NUM has grown"
564 #endif
565 	/* Build NULL terminated return arrays for each string style */
566 	static const conv_ds_t	*ds_cf[] = {
567 		CONV_DS_ADDR(ds_mach_0_11_cf),
568 		CONV_DS_ADDR(ds_mach_15_22_cf),
569 		CONV_DS_ADDR(ds_mach_36_63_cf),
570 		CONV_DS_ADDR(ds_mach_66_120_cf),
571 		CONV_DS_ADDR(ds_mach_131_144_cf),
572 		CONV_DS_ADDR(ds_mach_160_181_cf),
573 		CONV_DS_ADDR(ds_mach_183_cf),
574 		CONV_DS_ADDR(ds_mach_185_224_cf),
575 		CONV_DS_ADDR(ds_mach_243_cf),
576 		NULL
577 	};
578 	static const conv_ds_t	*ds_nf[] = {
579 		CONV_DS_ADDR(ds_mach_0_11_nf),
580 		CONV_DS_ADDR(ds_mach_15_22_nf),
581 		CONV_DS_ADDR(ds_mach_36_63_nf),
582 		CONV_DS_ADDR(ds_mach_66_120_nf),
583 		CONV_DS_ADDR(ds_mach_131_144_nf),
584 		CONV_DS_ADDR(ds_mach_160_181_nf),
585 		CONV_DS_ADDR(ds_mach_183_nf),
586 		CONV_DS_ADDR(ds_mach_185_224_nf),
587 		CONV_DS_ADDR(ds_mach_243_nf),
588 		NULL
589 	};
590 	static const conv_ds_t	*ds_dmp[] = {
591 		CONV_DS_ADDR(ds_mach_0_11_dmp),
592 		CONV_DS_ADDR(ds_mach_15_22_dmp),
593 		CONV_DS_ADDR(ds_mach_36_63_dmp),
594 		CONV_DS_ADDR(ds_mach_66_120_dmp),
595 		CONV_DS_ADDR(ds_mach_131_144_dmp),
596 		CONV_DS_ADDR(ds_mach_160_181_dmp),
597 		CONV_DS_ADDR(ds_mach_183_dmp),
598 		CONV_DS_ADDR(ds_mach_185_224_dmp),
599 		CONV_DS_ADDR(ds_mach_243_dmp),
600 		NULL
601 	};
602 
603 
604 	/* Select the strings to use */
605 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
606 	case CONV_FMT_ALT_DUMP:
607 	case CONV_FMT_ALT_FILE:
608 		return (ds_dmp);
609 	case CONV_FMT_ALT_NF:
610 		return (ds_nf);
611 	}
612 
613 	return (ds_cf);
614 }
615 
616 const char *
conv_ehdr_mach(Half machine,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)617 conv_ehdr_mach(Half machine, Conv_fmt_flags_t fmt_flags,
618     Conv_inv_buf_t *inv_buf)
619 {
620 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, machine,
621 	    ehdr_mach_strings(fmt_flags), fmt_flags, inv_buf));
622 }
623 
624 conv_iter_ret_t
conv_iter_ehdr_mach(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)625 conv_iter_ehdr_mach(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
626     void *uvalue)
627 {
628 	static const Val_desc extra_dmp_nf[] = {
629 		{ EM_M32,		MSG_EM_M32_DMP},
630 		{ EM_386,		MSG_EM_386_DMP },
631 		{ EM_68K,		MSG_EM_68K_DMP },
632 		{ EM_88K,		MSG_EM_88K_DMP },
633 		{ EM_486,		MSG_EM_486_DMP },
634 		{ EM_860,		MSG_EM_860_DMP },
635 		{ EM_MIPS,		MSG_EM_MIPS_DMP },
636 		{ EM_MIPS_RS3_LE,	MSG_EM_MIPS_RS3_LE_DMP },
637 		{ EM_PPC,		MSG_EM_PPC_DMP },
638 		{ EM_PPC64,		MSG_EM_PPC64_DMP },
639 
640 		{ 0 }
641 	};
642 
643 	if (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
644 	    ehdr_mach_strings(fmt_flags), func, uvalue) == CONV_ITER_DONE)
645 		return (CONV_ITER_DONE);
646 
647 	/*
648 	 * For the NF style, we also supply a few of the traditional
649 	 * dump versions for iteration, but not for display.
650 	 */
651 	if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF)
652 		return (conv_iter_vd(extra_dmp_nf, func, uvalue));
653 
654 	return (CONV_ITER_CONT);
655 }
656 
657 
658 
659 static const conv_ds_t **
ehdr_eident_strings(Conv_fmt_flags_t fmt_flags)660 ehdr_eident_strings(Conv_fmt_flags_t fmt_flags)
661 {
662 	static const Msg	eident_cf[] = {
663 		MSG_EI_MAG0_CF,		MSG_EI_MAG1_CF,
664 		MSG_EI_MAG2_CF,		MSG_EI_MAG3_CF,
665 		MSG_EI_CLASS_CF,	MSG_EI_DATA_CF,
666 		MSG_EI_VERSION_CF,	MSG_EI_OSABI_CF,
667 		MSG_EI_ABIVERSION_CF
668 	};
669 	static const Msg	eident_nf[] = {
670 		MSG_EI_MAG0_NF,		MSG_EI_MAG1_NF,
671 		MSG_EI_MAG2_NF,		MSG_EI_MAG3_NF,
672 		MSG_EI_CLASS_NF,	MSG_EI_DATA_NF,
673 		MSG_EI_VERSION_NF,	MSG_EI_OSABI_NF,
674 		MSG_EI_ABIVERSION_NF
675 	};
676 #if EI_PAD != (EI_ABIVERSION + 1)
677 error "EI_PAD has grown. Update etypes[]"
678 #endif
679 	static const conv_ds_msg_t ds_eident_cf = {
680 		CONV_DS_MSG_INIT(EI_MAG0, eident_cf) };
681 	static const conv_ds_msg_t ds_eident_nf = {
682 		CONV_DS_MSG_INIT(EI_MAG0, eident_nf) };
683 
684 	/* Build NULL terminated return arrays for each string style */
685 	static const conv_ds_t	*ds_cf[] = {
686 		CONV_DS_ADDR(ds_eident_cf), NULL };
687 	static const conv_ds_t	*ds_nf[] = {
688 		CONV_DS_ADDR(ds_eident_nf), NULL };
689 
690 	/* Select the strings to use */
691 	return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_CF) ?
692 	    ds_cf : ds_nf);
693 }
694 
695 conv_iter_ret_t
conv_iter_ehdr_eident(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)696 conv_iter_ehdr_eident(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
697     void *uvalue)
698 {
699 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
700 	    ehdr_eident_strings(fmt_flags), func, uvalue));
701 }
702 
703 static const conv_ds_t **
ehdr_type_strings(Conv_fmt_flags_t fmt_flags)704 ehdr_type_strings(Conv_fmt_flags_t fmt_flags)
705 {
706 #define	SOL	ELFOSABI_SOLARIS, EM_NONE
707 
708 	static const Msg	type_cf[] = {
709 		MSG_ET_NONE_CF,		MSG_ET_REL_CF,		MSG_ET_EXEC_CF,
710 		MSG_ET_DYN_CF,		MSG_ET_CORE_CF
711 	};
712 	static const Msg	type_nf[] = {
713 		MSG_ET_NONE_NF,		MSG_ET_REL_NF,		MSG_ET_EXEC_NF,
714 		MSG_ET_DYN_NF,		MSG_ET_CORE_NF
715 	};
716 	static const Msg	type_dmp[] = {
717 		MSG_ET_NONE_DMP,	MSG_ET_REL_DMP,		MSG_ET_EXEC_DMP,
718 		MSG_ET_DYN_DMP,		MSG_ET_CORE_DMP
719 	};
720 #if ET_NUM != (ET_CORE + 1)
721 error "ET_NUM has grown. Update types[]"
722 #endif
723 	static const conv_ds_msg_t ds_type_cf = {
724 		CONV_DS_MSG_INIT(ET_NONE, type_cf) };
725 	static const conv_ds_msg_t ds_type_nf = {
726 		CONV_DS_MSG_INIT(ET_NONE, type_nf) };
727 	static const conv_ds_msg_t ds_type_dmp = {
728 		CONV_DS_MSG_INIT(ET_NONE, type_dmp) };
729 
730 	static const Val_desc2 type_osabi_cf[] = {
731 		{ ET_SUNWPSEUDO,	SOL,	MSG_ET_SUNWPSEUDO_CF },
732 		{ 0 }
733 	};
734 	static const Val_desc2 type_osabi_nf[] = {
735 		{ ET_SUNWPSEUDO,	SOL,	MSG_ET_SUNWPSEUDO_NF },
736 		{ 0 }
737 	};
738 	static const Val_desc2 type_osabi_dmp[] = {
739 		{ ET_SUNWPSEUDO,	SOL,	MSG_ET_SUNWPSEUDO_DMP },
740 		{ 0 }
741 	};
742 #if ET_LOSUNW != ET_SUNWPSEUDO
743 error "ET_LOSUNW has grown. Update type_osabi[]"
744 #endif
745 	static const conv_ds_vd2_t ds_type_osabi_cf = {
746 	    CONV_DS_VD2, ET_LOOS, ET_HIOS, type_osabi_cf };
747 	static const conv_ds_vd2_t ds_type_osabi_nf = {
748 	    CONV_DS_VD2, ET_LOOS, ET_HIOS, type_osabi_nf };
749 	static const conv_ds_vd2_t ds_type_osabi_dmp = {
750 	    CONV_DS_VD2, ET_LOOS, ET_HIOS, type_osabi_dmp };
751 
752 
753 	/* Build NULL terminated return arrays for each string style */
754 	static const conv_ds_t	*ds_cf[] = {
755 		CONV_DS_ADDR(ds_type_cf), CONV_DS_ADDR(ds_type_osabi_cf),
756 		NULL };
757 	static const conv_ds_t	*ds_nf[] = {
758 		CONV_DS_ADDR(ds_type_nf), CONV_DS_ADDR(ds_type_osabi_nf),
759 		NULL };
760 	static const conv_ds_t	*ds_dmp[] = {
761 		CONV_DS_ADDR(ds_type_dmp), CONV_DS_ADDR(ds_type_osabi_dmp),
762 		NULL };
763 
764 	/* Select the strings to use */
765 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
766 	case CONV_FMT_ALT_DUMP:
767 		return (ds_dmp);
768 	case CONV_FMT_ALT_NF:
769 		return (ds_nf);
770 	}
771 
772 	return (ds_cf);
773 
774 #undef SOL
775 }
776 
777 const char *
conv_ehdr_type(uchar_t osabi,Half etype,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)778 conv_ehdr_type(uchar_t osabi, Half etype, Conv_fmt_flags_t fmt_flags,
779     Conv_inv_buf_t *inv_buf)
780 {
781 	return (conv_map_ds(osabi, EM_NONE, etype,
782 	    ehdr_type_strings(fmt_flags), fmt_flags, inv_buf));
783 }
784 
785 conv_iter_ret_t
conv_iter_ehdr_type(conv_iter_osabi_t osabi,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)786 conv_iter_ehdr_type(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags,
787     conv_iter_cb_t func, void *uvalue)
788 {
789 	return (conv_iter_ds(osabi, EM_NONE,
790 	    ehdr_type_strings(fmt_flags), func, uvalue));
791 }
792 
793 static const conv_ds_t **
ehdr_vers_strings(Conv_fmt_flags_t fmt_flags)794 ehdr_vers_strings(Conv_fmt_flags_t fmt_flags)
795 {
796 	static const Msg	versions_cf[] = {
797 		MSG_EV_NONE_CF,		MSG_EV_CURRENT_CF
798 	};
799 	static const Msg	versions_nf[] = {
800 		MSG_EV_NONE_NF,		MSG_EV_CURRENT_NF
801 	};
802 	static const Msg	versions_dmp[] = {
803 		MSG_EV_NONE_DMP,	MSG_EV_CURRENT_DMP
804 	};
805 #if EV_NUM != 2
806 error "EV_NUM has grown. Update versions[]"
807 #endif
808 	static const conv_ds_msg_t ds_versions_cf = {
809 		CONV_DS_MSG_INIT(EV_NONE, versions_cf) };
810 	static const conv_ds_msg_t ds_versions_nf = {
811 		CONV_DS_MSG_INIT(EV_NONE, versions_nf) };
812 	static const conv_ds_msg_t ds_versions_dmp = {
813 		CONV_DS_MSG_INIT(EV_NONE, versions_dmp) };
814 
815 	/* Build NULL terminated return arrays for each string style */
816 	static const conv_ds_t	*ds_cf[] = {
817 		CONV_DS_ADDR(ds_versions_cf), NULL };
818 	static const conv_ds_t	*ds_nf[] = {
819 		CONV_DS_ADDR(ds_versions_nf), NULL };
820 	static const conv_ds_t	*ds_dmp[] = {
821 		CONV_DS_ADDR(ds_versions_dmp), NULL };
822 
823 	/* Select the strings to use */
824 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
825 	case CONV_FMT_ALT_DUMP:
826 		return (ds_dmp);
827 	case CONV_FMT_ALT_NF:
828 		return (ds_nf);
829 	}
830 
831 	return (ds_cf);
832 }
833 
834 const char *
conv_ehdr_vers(Word version,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)835 conv_ehdr_vers(Word version, Conv_fmt_flags_t fmt_flags,
836     Conv_inv_buf_t *inv_buf)
837 {
838 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, version,
839 	    ehdr_vers_strings(fmt_flags), fmt_flags, inv_buf));
840 }
841 
842 conv_iter_ret_t
conv_iter_ehdr_vers(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)843 conv_iter_ehdr_vers(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
844     void *uvalue)
845 {
846 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
847 	    ehdr_vers_strings(fmt_flags), func, uvalue));
848 }
849 
850 static void
conv_ehdr_sparc_flags_strings(Conv_fmt_flags_t fmt_flags,const conv_ds_msg_t ** mm_msg,const Val_desc ** flag_desc)851 conv_ehdr_sparc_flags_strings(Conv_fmt_flags_t fmt_flags,
852     const conv_ds_msg_t **mm_msg, const Val_desc **flag_desc)
853 {
854 #define	EFLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
855 	MSG_EF_SPARCV9_TSO_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
856 	MSG_EF_SPARC_SUN_US1_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
857 	MSG_EF_SPARC_HAL_R1_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
858 	MSG_EF_SPARC_SUN_US3_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE +  \
859 	CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
860 
861 	/*
862 	 * Ensure that Conv_ehdr_flags_buf_t is large enough:
863 	 *
864 	 * EFLAGSZ is the real minimum size of the buffer required by
865 	 * conv_ehdr_flags(). However, Conv_ehdr_flags_buf_t uses
866 	 * CONV_EHDR_FLAG_BUFSIZE to set the buffer size. We do things
867 	 * this way because the definition of EFLAGSZ uses information
868 	 * that is not available in the environment of other programs
869 	 * that include the conv.h header file.
870 	 */
871 #if (CONV_EHDR_FLAGS_BUFSIZE != EFLAGSZ) && !defined(__lint)
872 #define	REPORT_BUFSIZE EFLAGSZ
873 #include "report_bufsize.h"
874 #error "CONV_EHDR_FLAGS_BUFSIZE does not match EFLAGSZ"
875 #endif
876 
877 	static const Msg mm_flags_cf[] = {
878 		MSG_EF_SPARCV9_TSO_CF,	MSG_EF_SPARCV9_PSO_CF,
879 		MSG_EF_SPARCV9_RMO_CF
880 	};
881 	static const Msg mm_flags_nf[] = {
882 		MSG_EF_SPARCV9_TSO_NF,	MSG_EF_SPARCV9_PSO_NF,
883 		MSG_EF_SPARCV9_RMO_NF
884 	};
885 	static const conv_ds_msg_t ds_mm_flags_cf = {
886 		CONV_DS_MSG_INIT(EF_SPARCV9_TSO, mm_flags_cf) };
887 	static const conv_ds_msg_t ds_mm_flags_nf = {
888 		CONV_DS_MSG_INIT(EF_SPARCV9_TSO, mm_flags_nf) };
889 
890 
891 	static const Val_desc vda_cf[] = {
892 		{ EF_SPARC_32PLUS,	MSG_EF_SPARC_32PLUS_CF },
893 		{ EF_SPARC_SUN_US1,	MSG_EF_SPARC_SUN_US1_CF },
894 		{ EF_SPARC_HAL_R1,	MSG_EF_SPARC_HAL_R1_CF },
895 		{ EF_SPARC_SUN_US3,	MSG_EF_SPARC_SUN_US3_CF },
896 		{ 0 }
897 	};
898 	static const Val_desc vda_nf[] = {
899 		{ EF_SPARC_32PLUS,	MSG_EF_SPARC_32PLUS_NF },
900 		{ EF_SPARC_SUN_US1,	MSG_EF_SPARC_SUN_US1_NF },
901 		{ EF_SPARC_HAL_R1,	MSG_EF_SPARC_HAL_R1_NF },
902 		{ EF_SPARC_SUN_US3,	MSG_EF_SPARC_SUN_US3_NF },
903 		{ 0 }
904 	};
905 
906 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
907 	default:
908 		*mm_msg = &ds_mm_flags_cf;
909 		*flag_desc = vda_cf;
910 		break;
911 	case CONV_FMT_ALT_NF:
912 		*mm_msg = &ds_mm_flags_nf;
913 		*flag_desc = vda_nf;
914 		break;
915 	}
916 }
917 
918 /*
919  * Make a string representation of the e_flags field.
920  */
921 const char *
conv_ehdr_flags(Half mach,Word flags,Conv_fmt_flags_t fmt_flags,Conv_ehdr_flags_buf_t * flags_buf)922 conv_ehdr_flags(Half mach, Word flags, Conv_fmt_flags_t fmt_flags,
923     Conv_ehdr_flags_buf_t *flags_buf)
924 {
925 	static const char *leading_str_arr[2];
926 	static CONV_EXPN_FIELD_ARG conv_arg = {
927 	    NULL, sizeof (flags_buf->buf), leading_str_arr };
928 
929 	const char **lstr;
930 	const conv_ds_msg_t	*mm_msg;
931 	const Val_desc		*vdp;
932 	Word			mm;
933 
934 	/*
935 	 * Non-SPARC architectures presently provide no known flags.
936 	 */
937 	if ((mach != EM_SPARCV9) && (((mach != EM_SPARC) &&
938 	    (mach != EM_SPARC32PLUS)) || (flags == 0)))
939 		return (conv_invalid_val(&flags_buf->inv_buf, flags,
940 		    CONV_FMT_DECIMAL));
941 
942 	conv_arg.buf = flags_buf->buf;
943 	conv_ehdr_sparc_flags_strings(fmt_flags, &mm_msg, &vdp);
944 	conv_arg.oflags = conv_arg.rflags = flags;
945 
946 	mm = flags & EF_SPARCV9_MM;
947 	lstr = leading_str_arr;
948 	if ((mach == EM_SPARCV9) && (mm <= mm_msg->ds_topval)) {
949 		*lstr++ = MSG_ORIG(mm_msg->ds_msg[mm]);
950 		conv_arg.rflags &= ~EF_SPARCV9_MM;
951 	}
952 	*lstr = NULL;
953 
954 	(void) conv_expn_field(&conv_arg, vdp, fmt_flags);
955 
956 	return (conv_arg.buf);
957 }
958 
959 conv_iter_ret_t
conv_iter_ehdr_flags(Half mach,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)960 conv_iter_ehdr_flags(Half mach, Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
961     void *uvalue)
962 {
963 
964 	if ((mach == EM_SPARCV9) || (mach == EM_SPARC) ||
965 	    (mach == EM_SPARC32PLUS) || (mach == CONV_MACH_ALL)) {
966 		const conv_ds_msg_t	*ds_msg_mm;
967 		const Val_desc		*vdp;
968 
969 		conv_ehdr_sparc_flags_strings(fmt_flags, &ds_msg_mm, &vdp);
970 
971 		if (mach == EM_SPARCV9) {
972 			const conv_ds_t *ds[2];
973 
974 			ds[0] = CONV_DS_ADDR(ds_msg_mm);
975 			ds[1] = NULL;
976 
977 			if (conv_iter_ds(ELFOSABI_NONE, mach, ds,
978 			    func, uvalue) == CONV_ITER_DONE)
979 				return (CONV_ITER_DONE);
980 		}
981 
982 		return (conv_iter_vd(vdp, func, uvalue));
983 	}
984 
985 	return (CONV_ITER_CONT);
986 }
987 
988 static const conv_ds_t **
ehdr_osabi_strings(Conv_fmt_flags_t fmt_flags)989 ehdr_osabi_strings(Conv_fmt_flags_t fmt_flags)
990 {
991 
992 	static const Msg osabi_0_3_cf[] = {
993 		MSG_OSABI_NONE_CF,	MSG_OSABI_HPUX_CF,
994 		MSG_OSABI_NETBSD_CF,	MSG_OSABI_LINUX_CF
995 	};
996 	static const Msg osabi_0_3_nf[] = {
997 		MSG_OSABI_NONE_NF,	MSG_OSABI_HPUX_NF,
998 		MSG_OSABI_NETBSD_NF,	MSG_OSABI_LINUX_NF
999 	};
1000 	static const Msg osabi_0_3_dmp[] = {
1001 		MSG_OSABI_NONE_DMP,	MSG_OSABI_HPUX_DMP,
1002 		MSG_OSABI_NETBSD_DMP,	MSG_OSABI_LINUX_DMP
1003 	};
1004 	static const conv_ds_msg_t ds_osabi_0_3_cf = {
1005 	    CONV_DS_MSG_INIT(ELFOSABI_NONE, osabi_0_3_cf) };
1006 	static const conv_ds_msg_t ds_osabi_0_3_nf = {
1007 	    CONV_DS_MSG_INIT(ELFOSABI_NONE, osabi_0_3_nf) };
1008 	static const conv_ds_msg_t ds_osabi_0_3_dmp = {
1009 	    CONV_DS_MSG_INIT(ELFOSABI_NONE, osabi_0_3_dmp) };
1010 
1011 
1012 	static const Msg osabi_6_18_cf[] = {
1013 		MSG_OSABI_SOLARIS_CF,	MSG_OSABI_AIX_CF,
1014 		MSG_OSABI_IRIX_CF,	MSG_OSABI_FREEBSD_CF,
1015 		MSG_OSABI_TRU64_CF,	MSG_OSABI_MODESTO_CF,
1016 		MSG_OSABI_OPENBSD_CF,	MSG_OSABI_OPENVMS_CF,
1017 		MSG_OSABI_NSK_CF,	MSG_OSABI_AROS_CF,
1018 		MSG_OSABI_FENIXOS_CF,	MSG_OSABI_CLOUDABI_CF,
1019 		MSG_OSABI_OPENVOS_CF
1020 	};
1021 	static const Msg osabi_6_18_nf[] = {
1022 		MSG_OSABI_SOLARIS_NF,	MSG_OSABI_AIX_NF,
1023 		MSG_OSABI_IRIX_NF,	MSG_OSABI_FREEBSD_NF,
1024 		MSG_OSABI_TRU64_NF,	MSG_OSABI_MODESTO_NF,
1025 		MSG_OSABI_OPENBSD_NF,	MSG_OSABI_OPENVMS_NF,
1026 		MSG_OSABI_NSK_NF,	MSG_OSABI_AROS_NF,
1027 		MSG_OSABI_FENIXOS_NF,	MSG_OSABI_CLOUDABI_NF,
1028 		MSG_OSABI_OPENVOS_NF
1029 	};
1030 	static const Msg osabi_6_18_dmp[] = {
1031 		MSG_OSABI_SOLARIS_DMP,	MSG_OSABI_AIX_DMP,
1032 		MSG_OSABI_IRIX_DMP,	MSG_OSABI_FREEBSD_DMP,
1033 		MSG_OSABI_TRU64_DMP,	MSG_OSABI_MODESTO_DMP,
1034 		MSG_OSABI_OPENBSD_DMP,	MSG_OSABI_OPENVMS_DMP,
1035 		MSG_OSABI_NSK_DMP,	MSG_OSABI_AROS_DMP,
1036 		MSG_OSABI_FENIXOS_DMP,	MSG_OSABI_CLOUDABI_DMP,
1037 		MSG_OSABI_OPENVOS_DMP
1038 	};
1039 	static const conv_ds_msg_t ds_osabi_6_18_cf = {
1040 	    CONV_DS_MSG_INIT(ELFOSABI_SOLARIS, osabi_6_18_cf) };
1041 	static const conv_ds_msg_t ds_osabi_6_18_nf = {
1042 	    CONV_DS_MSG_INIT(ELFOSABI_SOLARIS, osabi_6_18_nf) };
1043 	static const conv_ds_msg_t ds_osabi_6_18_dmp = {
1044 	    CONV_DS_MSG_INIT(ELFOSABI_SOLARIS, osabi_6_18_dmp) };
1045 
1046 
1047 	static const Val_desc osabi_misc_cf[] = {
1048 		{ ELFOSABI_ARM,			MSG_OSABI_ARM_CF },
1049 		{ ELFOSABI_STANDALONE,		MSG_OSABI_STANDALONE_CF },
1050 		{ 0 }
1051 	};
1052 	static const Val_desc osabi_misc_nf[] = {
1053 		{ ELFOSABI_ARM,			MSG_OSABI_ARM_NF },
1054 		{ ELFOSABI_STANDALONE,		MSG_OSABI_STANDALONE_NF },
1055 		{ 0 }
1056 	};
1057 	static const Val_desc osabi_misc_dmp[] = {
1058 		{ ELFOSABI_ARM,			MSG_OSABI_ARM_DMP },
1059 		{ ELFOSABI_STANDALONE,		MSG_OSABI_STANDALONE_DMP },
1060 		{ 0 }
1061 	};
1062 	static const conv_ds_vd_t ds_osabi_misc_cf = {
1063 	    CONV_DS_VD, ELFOSABI_ARM, ELFOSABI_STANDALONE, osabi_misc_cf };
1064 	static const conv_ds_vd_t ds_osabi_misc_nf = {
1065 	    CONV_DS_VD, ELFOSABI_ARM, ELFOSABI_STANDALONE, osabi_misc_nf };
1066 	static const conv_ds_vd_t ds_osabi_misc_dmp = {
1067 	    CONV_DS_VD, ELFOSABI_ARM, ELFOSABI_STANDALONE, osabi_misc_dmp };
1068 
1069 	/* Build NULL terminated return arrays for each string style */
1070 	static const conv_ds_t	*ds_cf[] = {
1071 		CONV_DS_ADDR(ds_osabi_0_3_cf), CONV_DS_ADDR(ds_osabi_6_18_cf),
1072 		CONV_DS_ADDR(ds_osabi_misc_cf), NULL };
1073 	static const conv_ds_t	*ds_nf[] = {
1074 		CONV_DS_ADDR(ds_osabi_0_3_nf), CONV_DS_ADDR(ds_osabi_6_18_nf),
1075 		CONV_DS_ADDR(ds_osabi_misc_nf), NULL };
1076 	static const conv_ds_t	*ds_dmp[] = {
1077 		CONV_DS_ADDR(ds_osabi_0_3_dmp), CONV_DS_ADDR(ds_osabi_6_18_dmp),
1078 		CONV_DS_ADDR(ds_osabi_misc_dmp), NULL };
1079 
1080 	/* Select the strings to use */
1081 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
1082 	case CONV_FMT_ALT_DUMP:
1083 		return (ds_dmp);
1084 	case CONV_FMT_ALT_NF:
1085 		return (ds_nf);
1086 	}
1087 
1088 	return (ds_cf);
1089 }
1090 
1091 /*
1092  * Make a string representation of the e_ident[EI_OSABI] field.
1093  */
1094 const char *
conv_ehdr_osabi(uchar_t osabi,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)1095 conv_ehdr_osabi(uchar_t osabi, Conv_fmt_flags_t fmt_flags,
1096     Conv_inv_buf_t *inv_buf)
1097 {
1098 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, osabi,
1099 	    ehdr_osabi_strings(fmt_flags), fmt_flags, inv_buf));
1100 }
1101 
1102 conv_iter_ret_t
conv_iter_ehdr_osabi(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)1103 conv_iter_ehdr_osabi(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
1104     void *uvalue)
1105 {
1106 	if (conv_iter_ds(ELFOSABI_NONE, EM_NONE, ehdr_osabi_strings(fmt_flags),
1107 	    func, uvalue) == CONV_ITER_DONE)
1108 		return (CONV_ITER_DONE);
1109 
1110 	/*
1111 	 * ELFOSABI_NONE might have been better named ELFOSABI_SYSV. For the
1112 	 * CF and NF sytles, we supply that name for 0 in addition to NONE.
1113 	 */
1114 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
1115 	case CONV_FMT_ALT_CF:
1116 		return ((* func)(MSG_ORIG(MSG_OSABI_SYSV_CF),
1117 		    ELFOSABI_NONE, uvalue));
1118 	case CONV_FMT_ALT_NF:
1119 		return ((* func)(MSG_ORIG(MSG_OSABI_SYSV_NF),
1120 		    ELFOSABI_NONE, uvalue));
1121 	}
1122 
1123 	return (CONV_ITER_CONT);
1124 }
1125 
1126 static const conv_ds_t **
ehdr_abivers_strings(conv_iter_osabi_t osabi,Conv_fmt_flags_t fmt_flags)1127 ehdr_abivers_strings(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags)
1128 {
1129 	static const Msg	abiversions_cf[] = {
1130 		MSG_EAV_SUNW_NONE_CF,	MSG_EAV_SUNW_CURRENT_CF
1131 	};
1132 	static const Msg	abiversions_nf[] = {
1133 		MSG_EAV_SUNW_NONE_NF,	MSG_EAV_SUNW_CURRENT_NF
1134 	};
1135 #if EAV_SUNW_NUM != 2
1136 error "EAV_SUNW_NUM has grown. Update abiversions[]"
1137 #endif
1138 	static const conv_ds_msg_t ds_abiversions_cf = {
1139 		CONV_DS_MSG_INIT(EV_NONE, abiversions_cf) };
1140 	static const conv_ds_msg_t ds_abiversions_nf = {
1141 		CONV_DS_MSG_INIT(EV_NONE, abiversions_nf) };
1142 
1143 	/* Build NULL terminated return arrays for each string style */
1144 	static const conv_ds_t	*ds_cf[] = {
1145 		CONV_DS_ADDR(ds_abiversions_cf), NULL };
1146 	static const conv_ds_t	*ds_nf[] = {
1147 		CONV_DS_ADDR(ds_abiversions_nf), NULL };
1148 
1149 	/* For non-Solaris OSABI, we don't have symbolic names */
1150 	static const conv_ds_t	*ds_none[] = { NULL };
1151 
1152 
1153 	/*
1154 	 * Select the strings to use. This is a rare case where
1155 	 * we don't treat ELFOSABI_NONE and ELFOSABI_SOLARIS
1156 	 * as the same thing. We should never create a Solaris
1157 	 * object tagged as ELFOSABI_NONE for which the abiversion
1158 	 * is non-zero.
1159 	 */
1160 	if ((osabi == ELFOSABI_SOLARIS) || (osabi == CONV_OSABI_ALL))
1161 		return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ?
1162 		    ds_nf : ds_cf);
1163 
1164 	return (ds_none);
1165 }
1166 
1167 const char *
conv_ehdr_abivers(uchar_t osabi,Word version,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)1168 conv_ehdr_abivers(uchar_t osabi, Word version, Conv_fmt_flags_t fmt_flags,
1169     Conv_inv_buf_t *inv_buf)
1170 {
1171 	return (conv_map_ds(osabi, EM_NONE, version,
1172 	    ehdr_abivers_strings(osabi, fmt_flags), fmt_flags, inv_buf));
1173 }
1174 
1175 conv_iter_ret_t
conv_iter_ehdr_abivers(conv_iter_osabi_t osabi,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)1176 conv_iter_ehdr_abivers(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags,
1177     conv_iter_cb_t func, void *uvalue)
1178 {
1179 	return (conv_iter_ds(osabi, EM_NONE,
1180 	    ehdr_abivers_strings(osabi, fmt_flags), func, uvalue));
1181 }
1182 
1183 /*
1184  * A generic means of returning additional information for a rejected file in
1185  * terms of a string. ELFOSABI_SOLARIS is assummed.
1186  */
1187 const char *
conv_reject_desc(Rej_desc * rej,Conv_reject_desc_buf_t * reject_desc_buf,Half mach)1188 conv_reject_desc(Rej_desc * rej, Conv_reject_desc_buf_t *reject_desc_buf,
1189     Half mach)
1190 {
1191 	ushort_t	type = rej->rej_type;
1192 	uint_t		info = rej->rej_info;
1193 
1194 	switch (type) {
1195 	case SGS_REJ_MACH:
1196 		return (conv_ehdr_mach((Half)info, 0,
1197 		    &reject_desc_buf->inv_buf));
1198 	case SGS_REJ_CLASS:
1199 		return (conv_ehdr_class((uchar_t)info, 0,
1200 		    &reject_desc_buf->inv_buf));
1201 	case SGS_REJ_DATA:
1202 		return (conv_ehdr_data((uchar_t)info, 0,
1203 		    &reject_desc_buf->inv_buf));
1204 	case SGS_REJ_TYPE:
1205 		return (conv_ehdr_type(ELFOSABI_SOLARIS, (Half)info, 0,
1206 		    &reject_desc_buf->inv_buf));
1207 	case SGS_REJ_BADFLAG:
1208 	case SGS_REJ_MISFLAG:
1209 	case SGS_REJ_HAL:
1210 	case SGS_REJ_US3:
1211 		return (conv_ehdr_flags(mach, (Word)info, 0,
1212 		    &reject_desc_buf->flags_buf));
1213 	case SGS_REJ_UNKFILE:
1214 	case SGS_REJ_ARCHIVE:
1215 	case SGS_REJ_KMOD:
1216 		return (NULL);
1217 	case SGS_REJ_STR:
1218 	case SGS_REJ_HWCAP_1:
1219 	case SGS_REJ_SFCAP_1:
1220 	case SGS_REJ_HWCAP_2:
1221 	case SGS_REJ_HWCAP_3:
1222 	case SGS_REJ_MACHCAP:
1223 	case SGS_REJ_PLATCAP:
1224 		if (rej->rej_str)
1225 			return ((const char *)rej->rej_str);
1226 		else
1227 			return (MSG_ORIG(MSG_STR_EMPTY));
1228 	default:
1229 		return (conv_invalid_val(&reject_desc_buf->inv_buf, info,
1230 		    CONV_FMT_DECIMAL));
1231 	}
1232 }
1233