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