xref: /illumos-gate/usr/src/cmd/sgs/libconv/common/sections.c (revision 581cede61ac9c14d8d4ea452562a567189eead78)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * String conversion routines for section attributes.
29  */
30 #include	<string.h>
31 #include	<sys/param.h>
32 #include	<sys/elf_SPARC.h>
33 #include	<sys/elf_amd64.h>
34 #include	<_conv.h>
35 #include	<sections_msg.h>
36 
37 
38 static const conv_ds_t **
39 sec_type_strings(conv_iter_osabi_t osabi, Half mach, Conv_fmt_flags_t fmt_flags)
40 {
41 	/*
42 	 * This routine can return an array with 1 generic array, up to
43 	 * three osabi arrays, two machine arrays, plus the NULL termination.
44 	 */
45 #define	MAX_RET	7
46 
47 	static const Msg secs_def[SHT_NUM] = {
48 		MSG_SHT_NULL,			MSG_SHT_PROGBITS,
49 		MSG_SHT_SYMTAB,			MSG_SHT_STRTAB,
50 		MSG_SHT_RELA,			MSG_SHT_HASH,
51 		MSG_SHT_DYNAMIC,		MSG_SHT_NOTE,
52 		MSG_SHT_NOBITS,			MSG_SHT_REL,
53 		MSG_SHT_SHLIB,			MSG_SHT_DYNSYM,
54 		MSG_SHT_UNKNOWN12,		MSG_SHT_UNKNOWN13,
55 		MSG_SHT_INIT_ARRAY,		MSG_SHT_FINI_ARRAY,
56 		MSG_SHT_PREINIT_ARRAY,		MSG_SHT_GROUP,
57 		MSG_SHT_SYMTAB_SHNDX
58 	};
59 	static const Msg secs_dmp[SHT_NUM] = {
60 		MSG_SHT_NULL_DMP,		MSG_SHT_PROGBITS_DMP,
61 		MSG_SHT_SYMTAB_DMP,		MSG_SHT_STRTAB_DMP,
62 		MSG_SHT_RELA_DMP,		MSG_SHT_HASH_DMP,
63 		MSG_SHT_DYNAMIC_DMP,		MSG_SHT_NOTE_DMP,
64 		MSG_SHT_NOBITS_DMP,		MSG_SHT_REL_DMP,
65 		MSG_SHT_SHLIB_DMP,		MSG_SHT_DYNSYM_DMP,
66 		MSG_SHT_UNKNOWN12_DMP,		MSG_SHT_UNKNOWN13_DMP,
67 		MSG_SHT_INIT_ARRAY_DMP,		MSG_SHT_FINI_ARRAY_DMP,
68 		MSG_SHT_PREINIT_ARRAY_DMP,	MSG_SHT_GROUP_DMP,
69 		MSG_SHT_SYMTAB_SHNDX_DMP
70 	};
71 	static const Msg secs_cf[SHT_NUM] = {
72 		MSG_SHT_NULL_CF,		MSG_SHT_PROGBITS_CF,
73 		MSG_SHT_SYMTAB_CF,		MSG_SHT_STRTAB_CF,
74 		MSG_SHT_RELA_CF,		MSG_SHT_HASH_CF,
75 		MSG_SHT_DYNAMIC_CF,		MSG_SHT_NOTE_CF,
76 		MSG_SHT_NOBITS_CF,		MSG_SHT_REL_CF,
77 		MSG_SHT_SHLIB_CF,		MSG_SHT_DYNSYM_CF,
78 		MSG_SHT_UNKNOWN12_CF,		MSG_SHT_UNKNOWN13_CF,
79 		MSG_SHT_INIT_ARRAY_CF,		MSG_SHT_FINI_ARRAY_CF,
80 		MSG_SHT_PREINIT_ARRAY_CF,	MSG_SHT_GROUP_CF,
81 		MSG_SHT_SYMTAB_SHNDX_CF
82 	};
83 	static const Msg secs_nf[SHT_NUM] = {
84 		MSG_SHT_NULL_NF,		MSG_SHT_PROGBITS_NF,
85 		MSG_SHT_SYMTAB_NF,		MSG_SHT_STRTAB_NF,
86 		MSG_SHT_RELA_NF,		MSG_SHT_HASH_NF,
87 		MSG_SHT_DYNAMIC_NF,		MSG_SHT_NOTE_NF,
88 		MSG_SHT_NOBITS_NF,		MSG_SHT_REL_NF,
89 		MSG_SHT_SHLIB_NF,		MSG_SHT_DYNSYM_NF,
90 		MSG_SHT_UNKNOWN12_NF,		MSG_SHT_UNKNOWN13_NF,
91 		MSG_SHT_INIT_ARRAY_NF,		MSG_SHT_FINI_ARRAY_NF,
92 		MSG_SHT_PREINIT_ARRAY_NF,	MSG_SHT_GROUP_NF,
93 		MSG_SHT_SYMTAB_SHNDX_NF
94 	};
95 #if	(SHT_NUM != (SHT_SYMTAB_SHNDX + 1))
96 #error	"SHT_NUM has grown"
97 #endif
98 	static const conv_ds_msg_t ds_secs_def = {
99 	    CONV_DS_MSG_INIT(SHT_NULL, secs_def) };
100 	static const conv_ds_msg_t ds_secs_dmp = {
101 	    CONV_DS_MSG_INIT(SHT_NULL, secs_dmp) };
102 	static const conv_ds_msg_t ds_secs_cf = {
103 	    CONV_DS_MSG_INIT(SHT_NULL, secs_cf) };
104 	static const conv_ds_msg_t ds_secs_nf = {
105 	    CONV_DS_MSG_INIT(SHT_NULL, secs_nf) };
106 
107 
108 	static const Msg usecs_def[SHT_HISUNW - SHT_LOSUNW + 1] = {
109 		MSG_SHT_SUNW_SYMSORT,		MSG_SHT_SUNW_TLSSORT,
110 		MSG_SHT_SUNW_LDYNSYM,		MSG_SHT_SUNW_DOF,
111 		MSG_SHT_SUNW_CAP,		MSG_SHT_SUNW_SIGNATURE,
112 		MSG_SHT_SUNW_ANNOTATE,		MSG_SHT_SUNW_DEBUGSTR,
113 		MSG_SHT_SUNW_DEBUG,		MSG_SHT_SUNW_MOVE,
114 		MSG_SHT_SUNW_COMDAT,		MSG_SHT_SUNW_SYMINFO,
115 		MSG_SHT_SUNW_VERDEF,		MSG_SHT_SUNW_VERNEED,
116 		MSG_SHT_SUNW_VERSYM
117 	};
118 	static const Msg usecs_dmp[SHT_HISUNW - SHT_LOSUNW + 1] = {
119 		MSG_SHT_SUNW_SYMSORT_DMP,	MSG_SHT_SUNW_TLSSORT_DMP,
120 		MSG_SHT_SUNW_LDYNSYM_DMP,	MSG_SHT_SUNW_DOF_DMP,
121 		MSG_SHT_SUNW_CAP_DMP,		MSG_SHT_SUNW_SIGNATURE_DMP,
122 		MSG_SHT_SUNW_ANNOTATE_DMP,	MSG_SHT_SUNW_DEBUGSTR_DMP,
123 		MSG_SHT_SUNW_DEBUG_DMP,		MSG_SHT_SUNW_MOVE_DMP,
124 		MSG_SHT_SUNW_COMDAT_DMP,	MSG_SHT_SUNW_SYMINFO_DMP,
125 		MSG_SHT_SUNW_VERDEF_DMP,	MSG_SHT_SUNW_VERNEED_DMP,
126 		MSG_SHT_SUNW_VERSYM_DMP
127 	};
128 	static const Msg usecs_cf[SHT_HISUNW - SHT_LOSUNW + 1] = {
129 		MSG_SHT_SUNW_SYMSORT_CF,	MSG_SHT_SUNW_TLSSORT_CF,
130 		MSG_SHT_SUNW_LDYNSYM_CF,	MSG_SHT_SUNW_DOF_CF,
131 		MSG_SHT_SUNW_CAP_CF,		MSG_SHT_SUNW_SIGNATURE_CF,
132 		MSG_SHT_SUNW_ANNOTATE_CF,	MSG_SHT_SUNW_DEBUGSTR_CF,
133 		MSG_SHT_SUNW_DEBUG_CF,		MSG_SHT_SUNW_MOVE_CF,
134 		MSG_SHT_SUNW_COMDAT_CF,		MSG_SHT_SUNW_SYMINFO_CF,
135 		MSG_SHT_SUNW_VERDEF_CF,		MSG_SHT_SUNW_VERNEED_CF,
136 		MSG_SHT_SUNW_VERSYM_CF
137 	};
138 	static const Msg usecs_nf[SHT_HISUNW - SHT_LOSUNW + 1] = {
139 		MSG_SHT_SUNW_SYMSORT_NF,	MSG_SHT_SUNW_TLSSORT_NF,
140 		MSG_SHT_SUNW_LDYNSYM_NF,	MSG_SHT_SUNW_DOF_NF,
141 		MSG_SHT_SUNW_CAP_NF,		MSG_SHT_SUNW_SIGNATURE_NF,
142 		MSG_SHT_SUNW_ANNOTATE_NF,	MSG_SHT_SUNW_DEBUGSTR_NF,
143 		MSG_SHT_SUNW_DEBUG_NF,		MSG_SHT_SUNW_MOVE_NF,
144 		MSG_SHT_SUNW_COMDAT_NF,		MSG_SHT_SUNW_SYMINFO_NF,
145 		MSG_SHT_SUNW_VERDEF_NF,		MSG_SHT_SUNW_VERNEED_NF,
146 		MSG_SHT_SUNW_VERSYM_NF
147 	};
148 #if	(SHT_LOSUNW != SHT_SUNW_symsort)
149 #error	"SHT_LOSUNW has moved"
150 #endif
151 	static const conv_ds_msg_t ds_usecs_def = {
152 	    CONV_DS_MSG_INIT(SHT_SUNW_symsort, usecs_def) };
153 	static const conv_ds_msg_t ds_usecs_dmp = {
154 	    CONV_DS_MSG_INIT(SHT_SUNW_symsort, usecs_dmp) };
155 	static const conv_ds_msg_t ds_usecs_cf = {
156 	    CONV_DS_MSG_INIT(SHT_SUNW_symsort, usecs_cf) };
157 	static const conv_ds_msg_t ds_usecs_nf = {
158 	    CONV_DS_MSG_INIT(SHT_SUNW_symsort, usecs_nf) };
159 
160 
161 	/* The Linux osabi range has two separate sequences */
162 	static const Msg usecs_gnu1_def[] = {
163 		MSG_SHT_GNU_ATTRIBUTES,		MSG_SHT_GNU_HASH,
164 		MSG_SHT_GNU_LIBLIST,		MSG_SHT_CHECKSUM,
165 	};
166 	static const Msg usecs_gnu1_dmp[] = {
167 		MSG_SHT_GNU_ATTRIBUTES_DMP,	MSG_SHT_GNU_HASH_DMP,
168 		MSG_SHT_GNU_LIBLIST_DMP,	MSG_SHT_CHECKSUM_DMP,
169 	};
170 	static const Msg usecs_gnu1_cf[] = {
171 		MSG_SHT_GNU_ATTRIBUTES_CF,	MSG_SHT_GNU_HASH_CF,
172 		MSG_SHT_GNU_LIBLIST_CF,	MSG_SHT_CHECKSUM_CF,
173 	};
174 	static const Msg usecs_gnu1_nf[] = {
175 		MSG_SHT_GNU_ATTRIBUTES_NF,	MSG_SHT_GNU_HASH_NF,
176 		MSG_SHT_GNU_LIBLIST_NF,	MSG_SHT_CHECKSUM_NF,
177 	};
178 	static const conv_ds_msg_t ds_usecs_gnu1_def = {
179 	    CONV_DS_MSG_INIT(SHT_GNU_ATTRIBUTES, usecs_gnu1_def) };
180 	static const conv_ds_msg_t ds_usecs_gnu1_dmp = {
181 	    CONV_DS_MSG_INIT(SHT_GNU_ATTRIBUTES, usecs_gnu1_dmp) };
182 	static const conv_ds_msg_t ds_usecs_gnu1_cf = {
183 	    CONV_DS_MSG_INIT(SHT_GNU_ATTRIBUTES, usecs_gnu1_cf) };
184 	static const conv_ds_msg_t ds_usecs_gnu1_nf = {
185 	    CONV_DS_MSG_INIT(SHT_GNU_ATTRIBUTES, usecs_gnu1_nf) };
186 
187 
188 	static const Msg usecs_gnu2_def[] = {
189 		MSG_SHT_GNU_VERDEF,		MSG_SHT_GNU_VERNEED,
190 		MSG_SHT_GNU_VERSYM
191 	};
192 	static const Msg usecs_gnu2_dmp[] = {
193 		MSG_SHT_GNU_VERDEF_DMP,		MSG_SHT_GNU_VERNEED_DMP,
194 		MSG_SHT_GNU_VERSYM_DMP
195 	};
196 	static const Msg usecs_gnu2_cf[] = {
197 		MSG_SHT_GNU_VERDEF_CF,		MSG_SHT_GNU_VERNEED_CF,
198 		MSG_SHT_GNU_VERSYM_CF
199 	};
200 	static const Msg usecs_gnu2_nf[] = {
201 		MSG_SHT_GNU_VERDEF_NF,		MSG_SHT_GNU_VERNEED_NF,
202 		MSG_SHT_GNU_VERSYM_NF
203 	};
204 	static const conv_ds_msg_t ds_usecs_gnu2_def = {
205 	    CONV_DS_MSG_INIT(SHT_GNU_verdef, usecs_gnu2_def) };
206 	static const conv_ds_msg_t ds_usecs_gnu2_dmp = {
207 	    CONV_DS_MSG_INIT(SHT_GNU_verdef, usecs_gnu2_dmp) };
208 	static const conv_ds_msg_t ds_usecs_gnu2_cf = {
209 	    CONV_DS_MSG_INIT(SHT_GNU_verdef, usecs_gnu2_cf) };
210 	static const conv_ds_msg_t ds_usecs_gnu2_nf = {
211 	    CONV_DS_MSG_INIT(SHT_GNU_verdef, usecs_gnu2_nf) };
212 
213 
214 	/* sparc processor range */
215 	static const Msg sparc_def[] = { MSG_SHT_SPARC_GOTDATA };
216 	static const Msg sparc_dmp[] = { MSG_SHT_SPARC_GOTDATA_DMP };
217 	static const Msg sparc_cf[] = { MSG_SHT_SPARC_GOTDATA_CF };
218 	static const Msg sparc_nf[] = { MSG_SHT_SPARC_GOTDATA_NF };
219 	static const conv_ds_msg_t ds_sparc_def = {
220 	    CONV_DS_MSG_INIT(SHT_SPARC_GOTDATA, sparc_def) };
221 	static const conv_ds_msg_t ds_sparc_dmp = {
222 	    CONV_DS_MSG_INIT(SHT_SPARC_GOTDATA, sparc_dmp) };
223 	static const conv_ds_msg_t ds_sparc_cf = {
224 	    CONV_DS_MSG_INIT(SHT_SPARC_GOTDATA, sparc_cf) };
225 	static const conv_ds_msg_t ds_sparc_nf = {
226 	    CONV_DS_MSG_INIT(SHT_SPARC_GOTDATA, sparc_nf) };
227 
228 	/* amd64 processor range */
229 	static const Msg amd64_def[] = { MSG_SHT_AMD64_UNWIND };
230 	static const Msg amd64_dmp[] = { MSG_SHT_AMD64_UNWIND_DMP };
231 	static const Msg amd64_cf[] = { MSG_SHT_AMD64_UNWIND_CF };
232 	static const Msg amd64_nf[] = { MSG_SHT_AMD64_UNWIND_NF };
233 	static const conv_ds_msg_t ds_amd64_def = {
234 	    CONV_DS_MSG_INIT(SHT_AMD64_UNWIND, amd64_def) };
235 	static const conv_ds_msg_t ds_amd64_dmp = {
236 	    CONV_DS_MSG_INIT(SHT_AMD64_UNWIND, amd64_dmp) };
237 	static const conv_ds_msg_t ds_amd64_cf = {
238 	    CONV_DS_MSG_INIT(SHT_AMD64_UNWIND, amd64_cf) };
239 	static const conv_ds_msg_t ds_amd64_nf = {
240 	    CONV_DS_MSG_INIT(SHT_AMD64_UNWIND, amd64_nf) };
241 
242 
243 	static const conv_ds_t	*retarr[MAX_RET];
244 	int			retndx = 0;
245 
246 	/* Select the strings to use, based on string style and OSABI */
247 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
248 	case CONV_FMT_ALT_DUMP:
249 		retarr[retndx++] = CONV_DS_ADDR(ds_secs_dmp);
250 		break;
251 	case CONV_FMT_ALT_CF:
252 		retarr[retndx++] = CONV_DS_ADDR(ds_secs_cf);
253 		break;
254 	case CONV_FMT_ALT_NF:
255 		retarr[retndx++] = CONV_DS_ADDR(ds_secs_nf);
256 		break;
257 	default:
258 		retarr[retndx++] = CONV_DS_ADDR(ds_secs_def);
259 		break;
260 	}
261 
262 	if ((osabi == ELFOSABI_NONE) || (osabi == ELFOSABI_SOLARIS) ||
263 	    (osabi == CONV_OSABI_ALL)) {
264 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
265 		case CONV_FMT_ALT_DUMP:
266 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_dmp);
267 			break;
268 		case CONV_FMT_ALT_CF:
269 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_cf);
270 			break;
271 		case CONV_FMT_ALT_NF:
272 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_nf);
273 			break;
274 		default:
275 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_def);
276 			break;
277 		}
278 	}
279 
280 	if ((osabi == ELFOSABI_LINUX) || (osabi == CONV_OSABI_ALL)) {
281 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
282 		case CONV_FMT_ALT_DUMP:
283 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_gnu1_dmp);
284 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_gnu2_dmp);
285 			break;
286 		case CONV_FMT_ALT_CF:
287 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_gnu1_cf);
288 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_gnu2_cf);
289 			break;
290 		case CONV_FMT_ALT_NF:
291 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_gnu1_nf);
292 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_gnu2_nf);
293 			break;
294 		default:
295 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_gnu1_def);
296 			retarr[retndx++] = CONV_DS_ADDR(ds_usecs_gnu2_def);
297 			break;
298 		}
299 	}
300 
301 	if ((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
302 	    (mach == EM_SPARCV9) || (mach == CONV_MACH_ALL)) {
303 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
304 		case CONV_FMT_ALT_DUMP:
305 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_dmp);
306 			break;
307 		case CONV_FMT_ALT_CF:
308 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_cf);
309 			break;
310 		case CONV_FMT_ALT_NF:
311 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_nf);
312 			break;
313 		default:
314 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_def);
315 			break;
316 		}
317 	}
318 
319 	if ((mach == EM_AMD64) || (mach == CONV_MACH_ALL)) {
320 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
321 		case CONV_FMT_ALT_DUMP:
322 			retarr[retndx++] = CONV_DS_ADDR(ds_amd64_dmp);
323 			break;
324 		case CONV_FMT_ALT_CF:
325 			retarr[retndx++] = CONV_DS_ADDR(ds_amd64_cf);
326 			break;
327 		case CONV_FMT_ALT_NF:
328 			retarr[retndx++] = CONV_DS_ADDR(ds_amd64_nf);
329 			break;
330 		default:
331 			retarr[retndx++] = CONV_DS_ADDR(ds_amd64_def);
332 			break;
333 		}
334 	}
335 
336 	retarr[retndx++] = NULL;
337 	assert(retndx <= MAX_RET);
338 	return (retarr);
339 
340 #undef MAX_RET
341 }
342 
343 const char *
344 conv_sec_type(uchar_t osabi, Half mach, Word sec, Conv_fmt_flags_t fmt_flags,
345     Conv_inv_buf_t *inv_buf)
346 {
347 	return (conv_map_ds(osabi, mach, sec,
348 	    sec_type_strings(osabi, mach, fmt_flags), fmt_flags, inv_buf));
349 }
350 
351 conv_iter_ret_t
352 conv_iter_sec_type(conv_iter_osabi_t osabi, Half mach,
353     Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, void *uvalue)
354 {
355 	return (conv_iter_ds(osabi, mach,
356 	    sec_type_strings(osabi, mach, fmt_flags), func, uvalue));
357 }
358 
359 
360 /*
361  * Special iteration routine that returns strings for all symbol table
362  * sections.
363  */
364 conv_iter_ret_t
365 conv_iter_sec_symtab(conv_iter_osabi_t osabi, Conv_fmt_flags_t fmt_flags,
366     conv_iter_cb_t func, void *uvalue)
367 {
368 	static const Val_desc2 symtab_cf[] = {
369 		{ SHT_SYMTAB,	0, 0,	MSG_SHT_SYMTAB_CF },
370 		{ SHT_DYNSYM,	0, 0,	MSG_SHT_DYNSYM_CF },
371 		{ SHT_SUNW_LDYNSYM, ELFOSABI_SOLARIS, 0,
372 					MSG_SHT_SUNW_LDYNSYM_CF },
373 
374 		{ 0 }
375 	};
376 	static const Val_desc2 symtab_nf[] = {
377 		{ SHT_SYMTAB,	0, 0,	MSG_SHT_SYMTAB_NF },
378 		{ SHT_DYNSYM,	0, 0,	MSG_SHT_DYNSYM_NF },
379 		{ SHT_SUNW_LDYNSYM, ELFOSABI_SOLARIS, 0,
380 					MSG_SHT_SUNW_LDYNSYM_NF },
381 
382 		{ 0 }
383 	};
384 
385 	const Val_desc2 *vdp;
386 
387 	vdp = (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ?
388 	    symtab_nf : symtab_cf;
389 
390 	return (conv_iter_vd2(osabi, EM_NONE, vdp, func, uvalue));
391 }
392 
393 
394 const Val_desc2 *
395 conv_sec_flags_strings(Conv_fmt_flags_t fmt_flags)
396 {
397 #define	FLAGSZ	CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \
398 	MSG_SHF_WRITE_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
399 	MSG_SHF_ALLOC_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
400 	MSG_SHF_EXECINSTR_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
401 	MSG_SHF_MERGE_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
402 	MSG_SHF_STRINGS_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
403 	MSG_SHF_INFO_LINK_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
404 	MSG_SHF_LINK_ORDER_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
405 	MSG_SHF_OS_NONCONFORMING_CF_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \
406 	MSG_SHF_GROUP_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
407 	MSG_SHF_TLS_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
408 	MSG_SHF_EXCLUDE_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
409 	MSG_SHF_ORDERED_CF_SIZE		+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
410 	MSG_SHF_AMD64_LARGE_CF_SIZE	+ CONV_EXPN_FIELD_DEF_SEP_SIZE + \
411 	CONV_INV_BUFSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE
412 
413 	/*
414 	 * Ensure that Conv_sec_flags_buf_t is large enough:
415 	 *
416 	 * FLAGSZ is the real minimum size of the buffer required by
417 	 * conv_sec_flags(). However, Conv_sec_flags_buf_t uses
418 	 * CONV_SEC_FLAGS_BUFSIZE to set the buffer size. We do things this
419 	 * way because the definition of FLAGSZ uses information that is not
420 	 * available in the environment of other programs that include the
421 	 * conv.h header file.
422 	 */
423 #if (CONV_SEC_FLAGS_BUFSIZE != FLAGSZ) && !defined(__lint)
424 #define	REPORT_BUFSIZE FLAGSZ
425 #include "report_bufsize.h"
426 #error "CONV_SEC_FLAGS_BUFSIZE does not match FLAGSZ"
427 #endif
428 
429 #define	ALL	ELFOSABI_NONE, EM_NONE
430 #define	SOL	ELFOSABI_SOLARIS, EM_NONE
431 #define	AMD	ELFOSABI_NONE, EM_AMD64
432 
433 	static const Val_desc2 vda_cf[] = {
434 		{ SHF_WRITE,		ALL,	MSG_SHF_WRITE_CF },
435 		{ SHF_ALLOC,		ALL,	MSG_SHF_ALLOC_CF },
436 		{ SHF_EXECINSTR,	ALL,	MSG_SHF_EXECINSTR_CF },
437 		{ SHF_MERGE,		ALL,	MSG_SHF_MERGE_CF },
438 		{ SHF_STRINGS,		ALL,	MSG_SHF_STRINGS_CF },
439 		{ SHF_INFO_LINK,	ALL,	MSG_SHF_INFO_LINK_CF },
440 		{ SHF_LINK_ORDER,	ALL,	MSG_SHF_LINK_ORDER_CF },
441 		{ SHF_OS_NONCONFORMING,	ALL,	MSG_SHF_OS_NONCONFORMING_CF },
442 		{ SHF_GROUP,		ALL,	MSG_SHF_GROUP_CF },
443 		{ SHF_TLS,		ALL,	MSG_SHF_TLS_CF },
444 		{ SHF_EXCLUDE,		SOL,	MSG_SHF_EXCLUDE_CF },
445 		{ SHF_ORDERED,		SOL,	MSG_SHF_ORDERED_CF },
446 		{ SHF_AMD64_LARGE,	AMD,	MSG_SHF_AMD64_LARGE_CF },
447 		{ 0,			0 }
448 	};
449 	static const Val_desc2 vda_nf[] = {
450 		{ SHF_WRITE,		ALL,	MSG_SHF_WRITE_NF },
451 		{ SHF_ALLOC,		ALL,	MSG_SHF_ALLOC_NF },
452 		{ SHF_EXECINSTR,	ALL,	MSG_SHF_EXECINSTR_NF },
453 		{ SHF_MERGE,		ALL,	MSG_SHF_MERGE_NF },
454 		{ SHF_STRINGS,		ALL,	MSG_SHF_STRINGS_NF },
455 		{ SHF_INFO_LINK,	ALL,	MSG_SHF_INFO_LINK_NF },
456 		{ SHF_LINK_ORDER,	ALL,	MSG_SHF_LINK_ORDER_NF },
457 		{ SHF_OS_NONCONFORMING,	ALL,	MSG_SHF_OS_NONCONFORMING_NF },
458 		{ SHF_GROUP,		ALL,	MSG_SHF_GROUP_NF },
459 		{ SHF_TLS,		ALL,	MSG_SHF_TLS_NF },
460 		{ SHF_EXCLUDE,		SOL,	MSG_SHF_EXCLUDE_NF },
461 		{ SHF_ORDERED,		SOL,	MSG_SHF_ORDERED_NF },
462 		{ SHF_AMD64_LARGE,	AMD,	MSG_SHF_AMD64_LARGE_NF },
463 		{ 0,			0 }
464 	};
465 
466 	return ((CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ?
467 	    vda_nf : vda_cf);
468 
469 #undef ALL
470 #undef SOL
471 #undef AMD
472 }
473 
474 conv_iter_ret_t
475 conv_iter_sec_flags(conv_iter_osabi_t osabi, Half mach,
476     Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, void *uvalue)
477 {
478 	static const Msg amd64_alias_cf[] = { MSG_SHF_X86_64_LARGE_CF };
479 	static const conv_ds_msg_t ds_msg_amd64_alias_cf = {
480 	    CONV_DS_MSG_INIT(SHF_X86_64_LARGE, amd64_alias_cf) };
481 	static const conv_ds_t	*ds_amd64_alias_cf[] = {
482 	    CONV_DS_ADDR(ds_msg_amd64_alias_cf), NULL };
483 
484 	static const Msg amd64_alias_nf[] = { MSG_SHF_X86_64_LARGE_NF };
485 	static const conv_ds_msg_t ds_msg_amd64_alias_nf = {
486 	    CONV_DS_MSG_INIT(SHF_X86_64_LARGE, amd64_alias_nf) };
487 	static const conv_ds_t	*ds_amd64_alias_nf[] = {
488 	    CONV_DS_ADDR(ds_msg_amd64_alias_nf), NULL };
489 
490 
491 	if (conv_iter_vd2(osabi, mach, conv_sec_flags_strings(fmt_flags),
492 	    func, uvalue) == CONV_ITER_DONE)
493 		return (CONV_ITER_DONE);
494 
495 	/* SHF_AMD64_LARGE is also known as SHF_X86_64_LARGE */
496 	if (mach == EM_AMD64) {
497 		const conv_ds_t **ds;
498 
499 		ds = (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_NF) ?
500 		    ds_amd64_alias_nf : ds_amd64_alias_cf;
501 
502 		return (conv_iter_ds(ELFOSABI_NONE, mach, ds, func, uvalue));
503 	}
504 
505 	return (CONV_ITER_CONT);
506 }
507