xref: /titanic_50/usr/src/cmd/sgs/libconv/common/symbols.c (revision 4f680cc668fa6cf678c531083400ade9a9c7934c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
237e16fca0SAli Bahrami  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * String conversion routines for symbol attributes.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate #include	<stdio.h>
317c478bd9Sstevel@tonic-gate #include	<sys/elf_SPARC.h>
3254d82594Sseizo #include	<sys/elf_amd64.h>
335aefb655Srie #include	"_conv.h"
345aefb655Srie #include	"symbols_msg.h"
357c478bd9Sstevel@tonic-gate 
365aefb655Srie const char *
conv_sym_other(uchar_t other,Conv_inv_buf_t * inv_buf)37de777a60Sab196087 conv_sym_other(uchar_t other, Conv_inv_buf_t *inv_buf)
385aefb655Srie {
3960758829Srie 	static const char	visibility[7] = {
407c478bd9Sstevel@tonic-gate 		'D',	/* STV_DEFAULT */
417c478bd9Sstevel@tonic-gate 		'I',	/* STV_INTERNAL */
427c478bd9Sstevel@tonic-gate 		'H',	/* STV_HIDDEN */
4360758829Srie 		'P',	/* STV_PROTECTED */
4460758829Srie 		'X',	/* STV_EXPORTED */
4560758829Srie 		'S',	/* STV_SINGLETON */
4660758829Srie 		'E'	/* STV_ELIMINATE */
477c478bd9Sstevel@tonic-gate 	};
4860758829Srie 	uchar_t		vis = ELF_ST_VISIBILITY(other);
497c478bd9Sstevel@tonic-gate 	uint_t		ndx = 0;
507c478bd9Sstevel@tonic-gate 
51de777a60Sab196087 	inv_buf->buf[ndx++] = visibility[vis];
525aefb655Srie 
537c478bd9Sstevel@tonic-gate 	/*
54d29b2c44Sab196087 	 * If unknown bits are present in st_other - throw out a '?'
557c478bd9Sstevel@tonic-gate 	 */
565aefb655Srie 	if (other & ~MSK_SYM_VISIBILITY)
57de777a60Sab196087 		inv_buf->buf[ndx++] = '?';
58de777a60Sab196087 	inv_buf->buf[ndx++] = '\0';
597c478bd9Sstevel@tonic-gate 
60de777a60Sab196087 	return (inv_buf->buf);
617c478bd9Sstevel@tonic-gate }
627c478bd9Sstevel@tonic-gate 
63*4f680cc6SAli Bahrami static const conv_ds_t **
conv_sym_other_vis_strings(Conv_fmt_flags_t fmt_flags)64*4f680cc6SAli Bahrami conv_sym_other_vis_strings(Conv_fmt_flags_t fmt_flags)
65*4f680cc6SAli Bahrami {
66*4f680cc6SAli Bahrami 	static const Msg	vis_def[] = {
67*4f680cc6SAli Bahrami 		MSG_STV_DEFAULT_DEF,	MSG_STV_INTERNAL_DEF,
68*4f680cc6SAli Bahrami 		MSG_STV_HIDDEN_DEF,	MSG_STV_PROTECTED_DEF,
69*4f680cc6SAli Bahrami 		MSG_STV_EXPORTED_DEF,	MSG_STV_SINGLETON_DEF,
70*4f680cc6SAli Bahrami 		MSG_STV_ELIMINATE_DEF
71*4f680cc6SAli Bahrami 	};
72*4f680cc6SAli Bahrami 	static const Msg	vis_cf[] = {
73*4f680cc6SAli Bahrami 		MSG_STV_DEFAULT_CF,	MSG_STV_INTERNAL_CF,
74*4f680cc6SAli Bahrami 		MSG_STV_HIDDEN_CF,	MSG_STV_PROTECTED_CF,
75*4f680cc6SAli Bahrami 		MSG_STV_EXPORTED_CF,	MSG_STV_SINGLETON_CF,
76*4f680cc6SAli Bahrami 		MSG_STV_ELIMINATE_CF
77*4f680cc6SAli Bahrami 	};
78*4f680cc6SAli Bahrami 	static const Msg	vis_nf[] = {
79*4f680cc6SAli Bahrami 		MSG_STV_DEFAULT_NF,	MSG_STV_INTERNAL_NF,
80*4f680cc6SAli Bahrami 		MSG_STV_HIDDEN_NF,	MSG_STV_PROTECTED_NF,
81*4f680cc6SAli Bahrami 		MSG_STV_EXPORTED_NF,	MSG_STV_SINGLETON_NF,
82*4f680cc6SAli Bahrami 		MSG_STV_ELIMINATE_NF
83*4f680cc6SAli Bahrami 	};
84*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_vis_def = {
85*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STV_DEFAULT, vis_def) };
86*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_vis_cf = {
87*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STV_DEFAULT, vis_cf) };
88*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_vis_nf = {
89*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STV_DEFAULT, vis_nf) };
90*4f680cc6SAli Bahrami 
91*4f680cc6SAli Bahrami 	/* Build NULL terminated return arrays for each string style */
92*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_def[] = {
93*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_vis_def), NULL };
94*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_cf[] = {
95*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_vis_cf), NULL };
96*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_nf[] = {
97*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_vis_nf), NULL };
98*4f680cc6SAli Bahrami 
99*4f680cc6SAli Bahrami 	/* Select the strings to use */
100*4f680cc6SAli Bahrami 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
101*4f680cc6SAli Bahrami 	case CONV_FMT_ALT_CF:
102*4f680cc6SAli Bahrami 		return (ds_cf);
103*4f680cc6SAli Bahrami 	case CONV_FMT_ALT_NF:
104*4f680cc6SAli Bahrami 		return (ds_nf);
105*4f680cc6SAli Bahrami 	}
106*4f680cc6SAli Bahrami 
107*4f680cc6SAli Bahrami 	return (ds_def);
108*4f680cc6SAli Bahrami }
109*4f680cc6SAli Bahrami 
1105aefb655Srie const char *
conv_sym_other_vis(uchar_t value,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)111d29b2c44Sab196087 conv_sym_other_vis(uchar_t value, Conv_fmt_flags_t fmt_flags,
112d29b2c44Sab196087     Conv_inv_buf_t *inv_buf)
113d29b2c44Sab196087 {
114*4f680cc6SAli Bahrami 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, value,
115*4f680cc6SAli Bahrami 	    conv_sym_other_vis_strings(fmt_flags), fmt_flags, inv_buf));
116*4f680cc6SAli Bahrami }
117*4f680cc6SAli Bahrami 
118*4f680cc6SAli Bahrami conv_iter_ret_t
conv_iter_sym_other_vis(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)119*4f680cc6SAli Bahrami conv_iter_sym_other_vis(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
120*4f680cc6SAli Bahrami     void *uvalue)
121*4f680cc6SAli Bahrami {
122*4f680cc6SAli Bahrami 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
123*4f680cc6SAli Bahrami 	    conv_sym_other_vis_strings(fmt_flags), func, uvalue));
124*4f680cc6SAli Bahrami }
125*4f680cc6SAli Bahrami 
126*4f680cc6SAli Bahrami static const conv_ds_t **
conv_sym_info_type_strings(Half mach,Conv_fmt_flags_t fmt_flags)127*4f680cc6SAli Bahrami conv_sym_info_type_strings(Half mach, Conv_fmt_flags_t fmt_flags)
128*4f680cc6SAli Bahrami {
129*4f680cc6SAli Bahrami 	/*
130*4f680cc6SAli Bahrami 	 * This routine can return an array with 1 generic array, and
131*4f680cc6SAli Bahrami 	 * a machine array, plus the NULL termination.
132*4f680cc6SAli Bahrami 	 */
133*4f680cc6SAli Bahrami #define	MAX_RET	3
134*4f680cc6SAli Bahrami 
135*4f680cc6SAli Bahrami 	static const Msg	types_def[] = {
136*4f680cc6SAli Bahrami 		MSG_STT_NOTYPE_DEF,	MSG_STT_OBJECT_DEF,
137*4f680cc6SAli Bahrami 		MSG_STT_FUNC_DEF,	MSG_STT_SECTION_DEF,
138*4f680cc6SAli Bahrami 		MSG_STT_FILE_DEF,	MSG_STT_COMMON_DEF,
139*4f680cc6SAli Bahrami 		MSG_STT_TLS_DEF,	MSG_STT_IFUNC_DEF
140d29b2c44Sab196087 	};
141*4f680cc6SAli Bahrami 	static const Msg	types_cf[] = {
142*4f680cc6SAli Bahrami 		MSG_STT_NOTYPE_CF,	MSG_STT_OBJECT_CF,
143*4f680cc6SAli Bahrami 		MSG_STT_FUNC_CF,	MSG_STT_SECTION_CF,
144*4f680cc6SAli Bahrami 		MSG_STT_FILE_CF,	MSG_STT_COMMON_CF,
145*4f680cc6SAli Bahrami 		MSG_STT_TLS_CF,		MSG_STT_IFUNC_CF
146d29b2c44Sab196087 	};
147*4f680cc6SAli Bahrami 	static const Msg	types_nf[] = {
148*4f680cc6SAli Bahrami 		MSG_STT_NOTYPE_NF,	MSG_STT_OBJECT_NF,
149*4f680cc6SAli Bahrami 		MSG_STT_FUNC_NF,	MSG_STT_SECTION_NF,
150*4f680cc6SAli Bahrami 		MSG_STT_FILE_NF,	MSG_STT_COMMON_NF,
151*4f680cc6SAli Bahrami 		MSG_STT_TLS_NF,		MSG_STT_IFUNC_NF
152*4f680cc6SAli Bahrami 	};
153*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_types_def = {
154*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_NOTYPE, types_def) };
155*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_types_cf = {
156*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_NOTYPE, types_cf) };
157*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_types_nf = {
158*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_NOTYPE, types_nf) };
159d29b2c44Sab196087 
160d29b2c44Sab196087 
161*4f680cc6SAli Bahrami 	static const Msg	sparc_def[] = { MSG_STT_SPARC_REGISTER_DEF };
162*4f680cc6SAli Bahrami 	static const Msg	sparc_cf[] = { MSG_STT_SPARC_REGISTER_CF };
163*4f680cc6SAli Bahrami 	static const Msg	sparc_nf[] = { MSG_STT_SPARC_REGISTER_NF };
164*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_sparc_def = {
165*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_SPARC_REGISTER, sparc_def) };
166*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_sparc_cf = {
167*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_SPARC_REGISTER, sparc_cf) };
168*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_sparc_nf = {
169*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_SPARC_REGISTER, sparc_nf) };
170d29b2c44Sab196087 
171*4f680cc6SAli Bahrami 
172*4f680cc6SAli Bahrami 	static const conv_ds_t	*retarr[MAX_RET];
173*4f680cc6SAli Bahrami 
174*4f680cc6SAli Bahrami 	int	retndx = 0;
175*4f680cc6SAli Bahrami 	int	is_sparc;
176*4f680cc6SAli Bahrami 
177*4f680cc6SAli Bahrami 	is_sparc = (mach == EM_SPARC) || (mach == EM_SPARCV9) ||
178*4f680cc6SAli Bahrami 	    (mach == EM_SPARC32PLUS) || (mach == CONV_MACH_ALL);
179*4f680cc6SAli Bahrami 
180*4f680cc6SAli Bahrami 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
181*4f680cc6SAli Bahrami 	case CONV_FMT_ALT_CF:
182*4f680cc6SAli Bahrami 		retarr[retndx++] = CONV_DS_ADDR(ds_types_cf);
183*4f680cc6SAli Bahrami 		if (is_sparc)
184*4f680cc6SAli Bahrami 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_cf);
185*4f680cc6SAli Bahrami 		break;
186*4f680cc6SAli Bahrami 	case CONV_FMT_ALT_NF:
187*4f680cc6SAli Bahrami 		retarr[retndx++] = CONV_DS_ADDR(ds_types_nf);
188*4f680cc6SAli Bahrami 		if (is_sparc)
189*4f680cc6SAli Bahrami 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_nf);
190*4f680cc6SAli Bahrami 		break;
191*4f680cc6SAli Bahrami 	default:
192*4f680cc6SAli Bahrami 		retarr[retndx++] = CONV_DS_ADDR(ds_types_def);
193*4f680cc6SAli Bahrami 		if (is_sparc)
194*4f680cc6SAli Bahrami 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_def);
195*4f680cc6SAli Bahrami 		break;
196*4f680cc6SAli Bahrami 	}
197*4f680cc6SAli Bahrami 
198*4f680cc6SAli Bahrami 	retarr[retndx++] = NULL;
199*4f680cc6SAli Bahrami 	assert(retndx <= MAX_RET);
200*4f680cc6SAli Bahrami 	return (retarr);
201d29b2c44Sab196087 }
202d29b2c44Sab196087 
203d29b2c44Sab196087 const char *
conv_sym_info_type(Half mach,uchar_t type,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)204d29b2c44Sab196087 conv_sym_info_type(Half mach, uchar_t type, Conv_fmt_flags_t fmt_flags,
205de777a60Sab196087     Conv_inv_buf_t *inv_buf)
2065aefb655Srie {
207*4f680cc6SAli Bahrami 	return (conv_map_ds(ELFOSABI_NONE, mach, type,
208*4f680cc6SAli Bahrami 	    conv_sym_info_type_strings(mach, fmt_flags), fmt_flags, inv_buf));
209c13de8f6Sab196087 }
210*4f680cc6SAli Bahrami 
211*4f680cc6SAli Bahrami conv_iter_ret_t
conv_iter_sym_info_type(Half mach,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)212*4f680cc6SAli Bahrami conv_iter_sym_info_type(Half mach, Conv_fmt_flags_t fmt_flags,
213*4f680cc6SAli Bahrami     conv_iter_cb_t func, void *uvalue)
214*4f680cc6SAli Bahrami {
215*4f680cc6SAli Bahrami 	return (conv_iter_ds(ELFOSABI_NONE, mach,
216*4f680cc6SAli Bahrami 	    conv_sym_info_type_strings(mach, fmt_flags), func, uvalue));
217*4f680cc6SAli Bahrami }
218*4f680cc6SAli Bahrami 
219*4f680cc6SAli Bahrami static const conv_ds_t **
conv_sym_info_bind_strings(Conv_fmt_flags_t fmt_flags)220*4f680cc6SAli Bahrami conv_sym_info_bind_strings(Conv_fmt_flags_t fmt_flags)
221*4f680cc6SAli Bahrami {
222*4f680cc6SAli Bahrami 	static const Msg	binds_def[] = {
223*4f680cc6SAli Bahrami 		MSG_STB_LOCAL_DEF,	MSG_STB_GLOBAL_DEF,
224*4f680cc6SAli Bahrami 		MSG_STB_WEAK_DEF
225*4f680cc6SAli Bahrami 	};
226*4f680cc6SAli Bahrami 	static const Msg	binds_cf[] = {
227*4f680cc6SAli Bahrami 		MSG_STB_LOCAL_CF,	MSG_STB_GLOBAL_CF,
228*4f680cc6SAli Bahrami 		MSG_STB_WEAK_CF
229*4f680cc6SAli Bahrami 	};
230*4f680cc6SAli Bahrami 	static const Msg	binds_nf[] = {
231*4f680cc6SAli Bahrami 		MSG_STB_LOCAL_NF,	MSG_STB_GLOBAL_NF,
232*4f680cc6SAli Bahrami 		MSG_STB_WEAK_NF
233*4f680cc6SAli Bahrami 	};
234*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_binds_def = {
235*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STB_LOCAL, binds_def) };
236*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_binds_cf = {
237*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STB_LOCAL, binds_cf) };
238*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_binds_nf = {
239*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STB_LOCAL, binds_nf) };
240*4f680cc6SAli Bahrami 
241*4f680cc6SAli Bahrami 
242*4f680cc6SAli Bahrami 	/* Build NULL terminated return arrays for each string style */
243*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_def[] = {
244*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_binds_def), NULL };
245*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_cf[] = {
246*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_binds_cf), NULL };
247*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_nf[] = {
248*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_binds_nf), NULL };
249*4f680cc6SAli Bahrami 
250*4f680cc6SAli Bahrami 
251*4f680cc6SAli Bahrami 	/* Select the strings to use */
252*4f680cc6SAli Bahrami 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
253*4f680cc6SAli Bahrami 	case CONV_FMT_ALT_CF:
254*4f680cc6SAli Bahrami 		return (ds_cf);
255*4f680cc6SAli Bahrami 	case CONV_FMT_ALT_NF:
256*4f680cc6SAli Bahrami 		return (ds_nf);
257*4f680cc6SAli Bahrami 	}
258*4f680cc6SAli Bahrami 
259*4f680cc6SAli Bahrami 	return (ds_def);
2607c478bd9Sstevel@tonic-gate }
2617c478bd9Sstevel@tonic-gate 
2625aefb655Srie const char *
conv_sym_info_bind(uchar_t bind,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)263d29b2c44Sab196087 conv_sym_info_bind(uchar_t bind, Conv_fmt_flags_t fmt_flags,
264d29b2c44Sab196087     Conv_inv_buf_t *inv_buf)
2655aefb655Srie {
266*4f680cc6SAli Bahrami 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, bind,
267*4f680cc6SAli Bahrami 	    conv_sym_info_bind_strings(fmt_flags), fmt_flags, inv_buf));
268*4f680cc6SAli Bahrami }
269*4f680cc6SAli Bahrami 
270*4f680cc6SAli Bahrami conv_iter_ret_t
conv_iter_sym_info_bind(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)271*4f680cc6SAli Bahrami conv_iter_sym_info_bind(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
272*4f680cc6SAli Bahrami     void *uvalue)
273*4f680cc6SAli Bahrami {
274*4f680cc6SAli Bahrami 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
275*4f680cc6SAli Bahrami 	    conv_sym_info_bind_strings(fmt_flags), func, uvalue));
276*4f680cc6SAli Bahrami }
277*4f680cc6SAli Bahrami 
278*4f680cc6SAli Bahrami static const conv_ds_t **
conv_sym_shndx_strings(Conv_fmt_flags_t fmt_flags)279*4f680cc6SAli Bahrami conv_sym_shndx_strings(Conv_fmt_flags_t fmt_flags)
280*4f680cc6SAli Bahrami {
281*4f680cc6SAli Bahrami #define	ALL	ELFOSABI_NONE, EM_NONE
282*4f680cc6SAli Bahrami #define	SOL	ELFOSABI_SOLARIS, EM_NONE
283*4f680cc6SAli Bahrami #define	AMD	ELFOSABI_NONE, EM_AMD64
284*4f680cc6SAli Bahrami 
285*4f680cc6SAli Bahrami 	/*
286*4f680cc6SAli Bahrami 	 * There aren't many of these values, and they are sparse,
287*4f680cc6SAli Bahrami 	 * so rather than separate them into different ranges, I use
288*4f680cc6SAli Bahrami 	 * a single Val_desc2 array for all of them.
289*4f680cc6SAli Bahrami 	 */
290*4f680cc6SAli Bahrami 	static const Val_desc2 shn_def[] = {
291*4f680cc6SAli Bahrami 		{ SHN_UNDEF,		ALL,	MSG_SHN_UNDEF_CFNP },
292*4f680cc6SAli Bahrami 		{ SHN_BEFORE,		ALL,	MSG_SHN_BEFORE_CFNP },
293*4f680cc6SAli Bahrami 		{ SHN_AFTER,		ALL,	MSG_SHN_AFTER_CFNP },
294*4f680cc6SAli Bahrami 		{ SHN_AMD64_LCOMMON,	AMD,	MSG_SHN_AMD64_LCOMMON_DEF },
295*4f680cc6SAli Bahrami 		{ SHN_SUNW_IGNORE,	SOL,	MSG_SHN_SUNW_IGNORE_DEF },
296*4f680cc6SAli Bahrami 		{ SHN_ABS,		ALL,	MSG_SHN_ABS_CFNP },
297*4f680cc6SAli Bahrami 		{ SHN_COMMON,		ALL,	MSG_SHN_COMMON_CFNP },
298*4f680cc6SAli Bahrami 		{ SHN_XINDEX,		ALL,	MSG_SHN_XINDEX_CFNP },
299*4f680cc6SAli Bahrami 		{ 0 }
3007c478bd9Sstevel@tonic-gate 	};
301*4f680cc6SAli Bahrami 	static const Val_desc2 shn_cf[] = {
302*4f680cc6SAli Bahrami 		{ SHN_UNDEF,		ALL,	MSG_SHN_UNDEF_CF },
303*4f680cc6SAli Bahrami 		{ SHN_BEFORE,		ALL,	MSG_SHN_BEFORE_CF },
304*4f680cc6SAli Bahrami 		{ SHN_AFTER,		ALL,	MSG_SHN_AFTER_CF },
305*4f680cc6SAli Bahrami 		{ SHN_AMD64_LCOMMON,	AMD,	MSG_SHN_AMD64_LCOMMON_CF },
306*4f680cc6SAli Bahrami 		{ SHN_SUNW_IGNORE,	SOL,	MSG_SHN_SUNW_IGNORE_CF },
307*4f680cc6SAli Bahrami 		{ SHN_ABS,		ALL,	MSG_SHN_ABS_CF },
308*4f680cc6SAli Bahrami 		{ SHN_COMMON,		ALL,	MSG_SHN_COMMON_CF },
309*4f680cc6SAli Bahrami 		{ SHN_XINDEX,		ALL,	MSG_SHN_XINDEX_CF },
310*4f680cc6SAli Bahrami 		{ 0 }
311d29b2c44Sab196087 	};
312*4f680cc6SAli Bahrami 	static const Val_desc2 shn_cfnp[] = {
313*4f680cc6SAli Bahrami 		{ SHN_UNDEF,		ALL,	MSG_SHN_UNDEF_CFNP },
314*4f680cc6SAli Bahrami 		{ SHN_BEFORE,		ALL,	MSG_SHN_BEFORE_CFNP },
315*4f680cc6SAli Bahrami 		{ SHN_AFTER,		ALL,	MSG_SHN_AFTER_CFNP },
316*4f680cc6SAli Bahrami 		{ SHN_AMD64_LCOMMON,	AMD,	MSG_SHN_AMD64_LCOMMON_CFNP },
317*4f680cc6SAli Bahrami 		{ SHN_SUNW_IGNORE,	SOL,	MSG_SHN_SUNW_IGNORE_CFNP },
318*4f680cc6SAli Bahrami 		{ SHN_ABS,		ALL,	MSG_SHN_ABS_CFNP },
319*4f680cc6SAli Bahrami 		{ SHN_COMMON,		ALL,	MSG_SHN_COMMON_CFNP },
320*4f680cc6SAli Bahrami 		{ SHN_XINDEX,		ALL,	MSG_SHN_XINDEX_CFNP },
321*4f680cc6SAli Bahrami 		{ 0 }
322*4f680cc6SAli Bahrami 	};
323*4f680cc6SAli Bahrami 	static const Val_desc2 shn_nf[] = {
324*4f680cc6SAli Bahrami 		{ SHN_UNDEF,		ALL,	MSG_SHN_UNDEF_NF },
325*4f680cc6SAli Bahrami 		{ SHN_BEFORE,		ALL,	MSG_SHN_BEFORE_NF },
326*4f680cc6SAli Bahrami 		{ SHN_AFTER,		ALL,	MSG_SHN_AFTER_NF },
327*4f680cc6SAli Bahrami 		{ SHN_AMD64_LCOMMON,	AMD,	MSG_SHN_AMD64_LCOMMON_NF },
328*4f680cc6SAli Bahrami 		{ SHN_SUNW_IGNORE,	SOL,	MSG_SHN_SUNW_IGNORE_NF },
329*4f680cc6SAli Bahrami 		{ SHN_ABS,		ALL,	MSG_SHN_ABS_NF },
330*4f680cc6SAli Bahrami 		{ SHN_COMMON,		ALL,	MSG_SHN_COMMON_NF },
331*4f680cc6SAli Bahrami 		{ SHN_XINDEX,		ALL,	MSG_SHN_XINDEX_NF },
332*4f680cc6SAli Bahrami 		{ 0 }
333*4f680cc6SAli Bahrami 	};
334*4f680cc6SAli Bahrami 	static const conv_ds_vd2_t ds_shn_def = {
335*4f680cc6SAli Bahrami 	    CONV_DS_VD2, SHN_UNDEF, SHN_XINDEX, shn_def };
336*4f680cc6SAli Bahrami 	static const conv_ds_vd2_t ds_shn_cf = {
337*4f680cc6SAli Bahrami 	    CONV_DS_VD2, SHN_UNDEF, SHN_XINDEX, shn_cf };
338*4f680cc6SAli Bahrami 	static const conv_ds_vd2_t ds_shn_cfnp = {
339*4f680cc6SAli Bahrami 	    CONV_DS_VD2, SHN_UNDEF, SHN_XINDEX, shn_cfnp };
340*4f680cc6SAli Bahrami 	static const conv_ds_vd2_t ds_shn_nf = {
341*4f680cc6SAli Bahrami 	    CONV_DS_VD2, SHN_UNDEF, SHN_XINDEX, shn_nf };
342d29b2c44Sab196087 
343*4f680cc6SAli Bahrami 	/* Build NULL terminated return arrays for each string style */
344*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_def[] = {
345*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_shn_def), NULL };
346*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_cf[] = {
347*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_shn_cf), NULL };
348*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_cfnp[] = {
349*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_shn_cfnp), NULL };
350*4f680cc6SAli Bahrami 	static const const conv_ds_t	*ds_nf[] = {
351*4f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_shn_nf), NULL };
352d29b2c44Sab196087 
353*4f680cc6SAli Bahrami 	/* Select the strings to use */
354*4f680cc6SAli Bahrami 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
355*4f680cc6SAli Bahrami 	case CONV_FMT_ALT_CF:
356*4f680cc6SAli Bahrami 		return (ds_cf);
357*4f680cc6SAli Bahrami 	case CONV_FMT_ALT_CFNP:
358*4f680cc6SAli Bahrami 		return (ds_cfnp);
359*4f680cc6SAli Bahrami 	case CONV_FMT_ALT_NF:
360*4f680cc6SAli Bahrami 		return (ds_nf);
361*4f680cc6SAli Bahrami 	}
362d29b2c44Sab196087 
363*4f680cc6SAli Bahrami 	return (ds_def);
364*4f680cc6SAli Bahrami 
365*4f680cc6SAli Bahrami #undef ALL
366*4f680cc6SAli Bahrami #undef SOL
367*4f680cc6SAli Bahrami #undef AMD
3687c478bd9Sstevel@tonic-gate }
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate const char *
conv_sym_shndx(uchar_t osabi,Half mach,Half shndx,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)371*4f680cc6SAli Bahrami conv_sym_shndx(uchar_t osabi, Half mach, Half shndx, Conv_fmt_flags_t fmt_flags,
372*4f680cc6SAli Bahrami     Conv_inv_buf_t *inv_buf)
3737c478bd9Sstevel@tonic-gate {
374*4f680cc6SAli Bahrami 	return (conv_map_ds(osabi, mach, shndx,
375*4f680cc6SAli Bahrami 	    conv_sym_shndx_strings(fmt_flags), fmt_flags, inv_buf));
376*4f680cc6SAli Bahrami }
377*4f680cc6SAli Bahrami 
378*4f680cc6SAli Bahrami conv_iter_ret_t
conv_iter_sym_shndx(conv_iter_osabi_t osabi,Half mach,Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)379*4f680cc6SAli Bahrami conv_iter_sym_shndx(conv_iter_osabi_t osabi, Half mach,
380*4f680cc6SAli Bahrami     Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, void *uvalue)
381*4f680cc6SAli Bahrami {
382*4f680cc6SAli Bahrami 	static const Msg amd64_alias_cf[] = { MSG_SHN_X86_64_LCOMMON_CF };
383*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_msg_amd64_alias_cf = {
384*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(SHN_X86_64_LCOMMON, amd64_alias_cf) };
385*4f680cc6SAli Bahrami 	static const conv_ds_t	*ds_amd64_alias_cf[] = {
386*4f680cc6SAli Bahrami 	    CONV_DS_ADDR(ds_msg_amd64_alias_cf), NULL };
387*4f680cc6SAli Bahrami 
388*4f680cc6SAli Bahrami 	static const Msg amd64_alias_cfnp[] = { MSG_SHN_X86_64_LCOMMON_CFNP };
389*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_msg_amd64_alias_cfnp = {
390*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(SHN_X86_64_LCOMMON, amd64_alias_cfnp) };
391*4f680cc6SAli Bahrami 	static const conv_ds_t	*ds_amd64_alias_cfnp[] = {
392*4f680cc6SAli Bahrami 	    CONV_DS_ADDR(ds_msg_amd64_alias_cfnp), NULL };
393*4f680cc6SAli Bahrami 
394*4f680cc6SAli Bahrami 	static const Msg amd64_alias_nf[] = { MSG_SHN_X86_64_LCOMMON_NF };
395*4f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_msg_amd64_alias_nf = {
396*4f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(SHN_X86_64_LCOMMON, amd64_alias_nf) };
397*4f680cc6SAli Bahrami 	static const conv_ds_t	*ds_amd64_alias_nf[] = {
398*4f680cc6SAli Bahrami 	    CONV_DS_ADDR(ds_msg_amd64_alias_nf), NULL };
399*4f680cc6SAli Bahrami 
400*4f680cc6SAli Bahrami 
401*4f680cc6SAli Bahrami 	if (conv_iter_ds(osabi, mach, conv_sym_shndx_strings(fmt_flags),
402*4f680cc6SAli Bahrami 	    func, uvalue) == CONV_ITER_DONE)
403*4f680cc6SAli Bahrami 		return (CONV_ITER_DONE);
404*4f680cc6SAli Bahrami 
405*4f680cc6SAli Bahrami 	/*
406*4f680cc6SAli Bahrami 	 * SHN_AMD64_LCOMMON is also known as SHN_X86_64_LCOMMON
407*4f680cc6SAli Bahrami 	 */
408*4f680cc6SAli Bahrami 	if (mach == EM_AMD64) {
409*4f680cc6SAli Bahrami 		const conv_ds_t	**ds;
410*4f680cc6SAli Bahrami 
411*4f680cc6SAli Bahrami 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
412*4f680cc6SAli Bahrami 		case CONV_FMT_ALT_CF:
413*4f680cc6SAli Bahrami 			ds = ds_amd64_alias_cf;
414*4f680cc6SAli Bahrami 			break;
415*4f680cc6SAli Bahrami 		case CONV_FMT_ALT_NF:
416*4f680cc6SAli Bahrami 			ds = ds_amd64_alias_nf;
417*4f680cc6SAli Bahrami 			break;
4185aefb655Srie 		default:
419*4f680cc6SAli Bahrami 			ds = ds_amd64_alias_cfnp;
420*4f680cc6SAli Bahrami 			break;
4215aefb655Srie 		}
422*4f680cc6SAli Bahrami 		return (conv_iter_ds(ELFOSABI_NONE, mach, ds, func, uvalue));
4237c478bd9Sstevel@tonic-gate 	}
4247c478bd9Sstevel@tonic-gate 
425*4f680cc6SAli Bahrami 	return (CONV_ITER_CONT);
4267c478bd9Sstevel@tonic-gate }
427