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 
367c478bd9Sstevel@tonic-gate const char *
conv_sym_other(uchar_t other,Conv_inv_buf_t * inv_buf)37de777a60Sab conv_sym_other(uchar_t other, Conv_inv_buf_t *inv_buf)
387c478bd9Sstevel@tonic-gate {
3960758829Srie 	static const char	visibility[7] = {
405aefb655Srie 		'D',	/* STV_DEFAULT */
415aefb655Srie 		'I',	/* STV_INTERNAL */
425aefb655Srie 		'H',	/* STV_HIDDEN */
4360758829Srie 		'P',	/* STV_PROTECTED */
4460758829Srie 		'X',	/* STV_EXPORTED */
4560758829Srie 		'S',	/* STV_SINGLETON */
4660758829Srie 		'E'	/* STV_ELIMINATE */
475aefb655Srie 	};
4860758829Srie 	uchar_t		vis = ELF_ST_VISIBILITY(other);
495aefb655Srie 	uint_t		ndx = 0;
505aefb655Srie 
51de777a60Sab 	inv_buf->buf[ndx++] = visibility[vis];
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	/*
54d29b2c44Sab 	 * If unknown bits are present in st_other - throw out a '?'
557c478bd9Sstevel@tonic-gate 	 */
565aefb655Srie 	if (other & ~MSK_SYM_VISIBILITY)
57de777a60Sab 		inv_buf->buf[ndx++] = '?';
58de777a60Sab 	inv_buf->buf[ndx++] = '\0';
597c478bd9Sstevel@tonic-gate 
60de777a60Sab 	return (inv_buf->buf);
617c478bd9Sstevel@tonic-gate }
627c478bd9Sstevel@tonic-gate 
634f680cc6SAli Bahrami static const conv_ds_t **
conv_sym_other_vis_strings(Conv_fmt_flags_t fmt_flags)644f680cc6SAli Bahrami conv_sym_other_vis_strings(Conv_fmt_flags_t fmt_flags)
654f680cc6SAli Bahrami {
664f680cc6SAli Bahrami 	static const Msg	vis_def[] = {
674f680cc6SAli Bahrami 		MSG_STV_DEFAULT_DEF,	MSG_STV_INTERNAL_DEF,
684f680cc6SAli Bahrami 		MSG_STV_HIDDEN_DEF,	MSG_STV_PROTECTED_DEF,
694f680cc6SAli Bahrami 		MSG_STV_EXPORTED_DEF,	MSG_STV_SINGLETON_DEF,
704f680cc6SAli Bahrami 		MSG_STV_ELIMINATE_DEF
714f680cc6SAli Bahrami 	};
724f680cc6SAli Bahrami 	static const Msg	vis_cf[] = {
734f680cc6SAli Bahrami 		MSG_STV_DEFAULT_CF,	MSG_STV_INTERNAL_CF,
744f680cc6SAli Bahrami 		MSG_STV_HIDDEN_CF,	MSG_STV_PROTECTED_CF,
754f680cc6SAli Bahrami 		MSG_STV_EXPORTED_CF,	MSG_STV_SINGLETON_CF,
764f680cc6SAli Bahrami 		MSG_STV_ELIMINATE_CF
774f680cc6SAli Bahrami 	};
784f680cc6SAli Bahrami 	static const Msg	vis_nf[] = {
794f680cc6SAli Bahrami 		MSG_STV_DEFAULT_NF,	MSG_STV_INTERNAL_NF,
804f680cc6SAli Bahrami 		MSG_STV_HIDDEN_NF,	MSG_STV_PROTECTED_NF,
814f680cc6SAli Bahrami 		MSG_STV_EXPORTED_NF,	MSG_STV_SINGLETON_NF,
824f680cc6SAli Bahrami 		MSG_STV_ELIMINATE_NF
834f680cc6SAli Bahrami 	};
844f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_vis_def = {
854f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STV_DEFAULT, vis_def) };
864f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_vis_cf = {
874f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STV_DEFAULT, vis_cf) };
884f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_vis_nf = {
894f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STV_DEFAULT, vis_nf) };
904f680cc6SAli Bahrami 
914f680cc6SAli Bahrami 	/* Build NULL terminated return arrays for each string style */
9284f79254SToomas Soome 	static const conv_ds_t	*ds_def[] = {
934f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_vis_def), NULL };
9484f79254SToomas Soome 	static const conv_ds_t	*ds_cf[] = {
954f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_vis_cf), NULL };
9684f79254SToomas Soome 	static const conv_ds_t	*ds_nf[] = {
974f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_vis_nf), NULL };
984f680cc6SAli Bahrami 
994f680cc6SAli Bahrami 	/* Select the strings to use */
1004f680cc6SAli Bahrami 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
1014f680cc6SAli Bahrami 	case CONV_FMT_ALT_CF:
1024f680cc6SAli Bahrami 		return (ds_cf);
1034f680cc6SAli Bahrami 	case CONV_FMT_ALT_NF:
1044f680cc6SAli Bahrami 		return (ds_nf);
1054f680cc6SAli Bahrami 	}
1064f680cc6SAli Bahrami 
1074f680cc6SAli Bahrami 	return (ds_def);
1084f680cc6SAli Bahrami }
1094f680cc6SAli Bahrami 
1107c478bd9Sstevel@tonic-gate const char *
conv_sym_other_vis(uchar_t value,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)111d29b2c44Sab conv_sym_other_vis(uchar_t value, Conv_fmt_flags_t fmt_flags,
112d29b2c44Sab     Conv_inv_buf_t *inv_buf)
113d29b2c44Sab {
1144f680cc6SAli Bahrami 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, value,
1154f680cc6SAli Bahrami 	    conv_sym_other_vis_strings(fmt_flags), fmt_flags, inv_buf));
1164f680cc6SAli Bahrami }
1174f680cc6SAli Bahrami 
1184f680cc6SAli Bahrami conv_iter_ret_t
conv_iter_sym_other_vis(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)1194f680cc6SAli Bahrami conv_iter_sym_other_vis(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
1204f680cc6SAli Bahrami     void *uvalue)
1214f680cc6SAli Bahrami {
1224f680cc6SAli Bahrami 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
1234f680cc6SAli Bahrami 	    conv_sym_other_vis_strings(fmt_flags), func, uvalue));
1244f680cc6SAli Bahrami }
1254f680cc6SAli Bahrami 
1264f680cc6SAli Bahrami static const conv_ds_t **
conv_sym_info_type_strings(Half mach,Conv_fmt_flags_t fmt_flags)1274f680cc6SAli Bahrami conv_sym_info_type_strings(Half mach, Conv_fmt_flags_t fmt_flags)
1284f680cc6SAli Bahrami {
1294f680cc6SAli Bahrami 	/*
1304f680cc6SAli Bahrami 	 * This routine can return an array with 1 generic array, and
1314f680cc6SAli Bahrami 	 * a machine array, plus the NULL termination.
1324f680cc6SAli Bahrami 	 */
1334f680cc6SAli Bahrami #define	MAX_RET	3
134d29b2c44Sab 
1354f680cc6SAli Bahrami 	static const Msg	types_def[] = {
1364f680cc6SAli Bahrami 		MSG_STT_NOTYPE_DEF,	MSG_STT_OBJECT_DEF,
1374f680cc6SAli Bahrami 		MSG_STT_FUNC_DEF,	MSG_STT_SECTION_DEF,
1384f680cc6SAli Bahrami 		MSG_STT_FILE_DEF,	MSG_STT_COMMON_DEF,
1394f680cc6SAli Bahrami 		MSG_STT_TLS_DEF,	MSG_STT_IFUNC_DEF
1404f680cc6SAli Bahrami 	};
1414f680cc6SAli Bahrami 	static const Msg	types_cf[] = {
1424f680cc6SAli Bahrami 		MSG_STT_NOTYPE_CF,	MSG_STT_OBJECT_CF,
1434f680cc6SAli Bahrami 		MSG_STT_FUNC_CF,	MSG_STT_SECTION_CF,
1444f680cc6SAli Bahrami 		MSG_STT_FILE_CF,	MSG_STT_COMMON_CF,
1454f680cc6SAli Bahrami 		MSG_STT_TLS_CF,		MSG_STT_IFUNC_CF
146d29b2c44Sab 	};
147*8222814eSRichard Lowe 	static const Msg	types_cfnp[] = {
148*8222814eSRichard Lowe 		MSG_STT_NOTYPE_CFNP,	MSG_STT_OBJECT_CFNP,
149*8222814eSRichard Lowe 		MSG_STT_FUNC_CFNP,	MSG_STT_SECTION_CFNP,
150*8222814eSRichard Lowe 		MSG_STT_FILE_CFNP,	MSG_STT_COMMON_CFNP,
151*8222814eSRichard Lowe 		MSG_STT_TLS_CFNP,		MSG_STT_IFUNC_CFNP
152*8222814eSRichard Lowe 	};
1534f680cc6SAli Bahrami 	static const Msg	types_nf[] = {
1544f680cc6SAli Bahrami 		MSG_STT_NOTYPE_NF,	MSG_STT_OBJECT_NF,
1554f680cc6SAli Bahrami 		MSG_STT_FUNC_NF,	MSG_STT_SECTION_NF,
1564f680cc6SAli Bahrami 		MSG_STT_FILE_NF,	MSG_STT_COMMON_NF,
1574f680cc6SAli Bahrami 		MSG_STT_TLS_NF,		MSG_STT_IFUNC_NF
1584f680cc6SAli Bahrami 	};
1594f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_types_def = {
1604f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_NOTYPE, types_def) };
1614f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_types_cf = {
1624f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_NOTYPE, types_cf) };
163*8222814eSRichard Lowe 	static const conv_ds_msg_t ds_types_cfnp = {
164*8222814eSRichard Lowe 	    CONV_DS_MSG_INIT(STT_NOTYPE, types_cfnp) };
1654f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_types_nf = {
1664f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_NOTYPE, types_nf) };
1674f680cc6SAli Bahrami 
168d29b2c44Sab 
1694f680cc6SAli Bahrami 	static const Msg	sparc_def[] = { MSG_STT_SPARC_REGISTER_DEF };
1704f680cc6SAli Bahrami 	static const Msg	sparc_cf[] = { MSG_STT_SPARC_REGISTER_CF };
171*8222814eSRichard Lowe 	static const Msg	sparc_cfnp[] = { MSG_STT_SPARC_REGISTER_CFNP };
1724f680cc6SAli Bahrami 	static const Msg	sparc_nf[] = { MSG_STT_SPARC_REGISTER_NF };
1734f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_sparc_def = {
1744f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_SPARC_REGISTER, sparc_def) };
1754f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_sparc_cf = {
1764f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_SPARC_REGISTER, sparc_cf) };
177*8222814eSRichard Lowe 	static const conv_ds_msg_t ds_sparc_cfnp = {
178*8222814eSRichard Lowe 	    CONV_DS_MSG_INIT(STT_SPARC_REGISTER, sparc_cfnp) };
1794f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_sparc_nf = {
1804f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STT_SPARC_REGISTER, sparc_nf) };
181d29b2c44Sab 
182d29b2c44Sab 
1834f680cc6SAli Bahrami 	static const conv_ds_t	*retarr[MAX_RET];
1844f680cc6SAli Bahrami 
1854f680cc6SAli Bahrami 	int	retndx = 0;
1864f680cc6SAli Bahrami 	int	is_sparc;
1874f680cc6SAli Bahrami 
1884f680cc6SAli Bahrami 	is_sparc = (mach == EM_SPARC) || (mach == EM_SPARCV9) ||
1894f680cc6SAli Bahrami 	    (mach == EM_SPARC32PLUS) || (mach == CONV_MACH_ALL);
1904f680cc6SAli Bahrami 
1914f680cc6SAli Bahrami 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
1924f680cc6SAli Bahrami 	case CONV_FMT_ALT_CF:
1934f680cc6SAli Bahrami 		retarr[retndx++] = CONV_DS_ADDR(ds_types_cf);
1944f680cc6SAli Bahrami 		if (is_sparc)
1954f680cc6SAli Bahrami 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_cf);
1964f680cc6SAli Bahrami 		break;
197*8222814eSRichard Lowe 	case CONV_FMT_ALT_CFNP:
198*8222814eSRichard Lowe 		retarr[retndx++] = CONV_DS_ADDR(ds_types_cfnp);
199*8222814eSRichard Lowe 		if (is_sparc)
200*8222814eSRichard Lowe 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_cfnp);
201*8222814eSRichard Lowe 		break;
2024f680cc6SAli Bahrami 	case CONV_FMT_ALT_NF:
2034f680cc6SAli Bahrami 		retarr[retndx++] = CONV_DS_ADDR(ds_types_nf);
2044f680cc6SAli Bahrami 		if (is_sparc)
2054f680cc6SAli Bahrami 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_nf);
2064f680cc6SAli Bahrami 		break;
2074f680cc6SAli Bahrami 	default:
2084f680cc6SAli Bahrami 		retarr[retndx++] = CONV_DS_ADDR(ds_types_def);
2094f680cc6SAli Bahrami 		if (is_sparc)
2104f680cc6SAli Bahrami 			retarr[retndx++] = CONV_DS_ADDR(ds_sparc_def);
2114f680cc6SAli Bahrami 		break;
2124f680cc6SAli Bahrami 	}
2134f680cc6SAli Bahrami 
2144f680cc6SAli Bahrami 	retarr[retndx++] = NULL;
2154f680cc6SAli Bahrami 	assert(retndx <= MAX_RET);
2164f680cc6SAli Bahrami 	return (retarr);
217d29b2c44Sab }
218d29b2c44Sab 
219d29b2c44Sab const char *
conv_sym_info_type(Half mach,uchar_t type,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)220d29b2c44Sab conv_sym_info_type(Half mach, uchar_t type, Conv_fmt_flags_t fmt_flags,
221de777a60Sab     Conv_inv_buf_t *inv_buf)
2227c478bd9Sstevel@tonic-gate {
2234f680cc6SAli Bahrami 	return (conv_map_ds(ELFOSABI_NONE, mach, type,
2244f680cc6SAli Bahrami 	    conv_sym_info_type_strings(mach, fmt_flags), fmt_flags, inv_buf));
2254f680cc6SAli Bahrami }
2267c478bd9Sstevel@tonic-gate 
2274f680cc6SAli 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)2284f680cc6SAli Bahrami conv_iter_sym_info_type(Half mach, Conv_fmt_flags_t fmt_flags,
2294f680cc6SAli Bahrami     conv_iter_cb_t func, void *uvalue)
2304f680cc6SAli Bahrami {
2314f680cc6SAli Bahrami 	return (conv_iter_ds(ELFOSABI_NONE, mach,
2324f680cc6SAli Bahrami 	    conv_sym_info_type_strings(mach, fmt_flags), func, uvalue));
2334f680cc6SAli Bahrami }
2344f680cc6SAli Bahrami 
2354f680cc6SAli Bahrami static const conv_ds_t **
conv_sym_info_bind_strings(Conv_fmt_flags_t fmt_flags)2364f680cc6SAli Bahrami conv_sym_info_bind_strings(Conv_fmt_flags_t fmt_flags)
2374f680cc6SAli Bahrami {
2384f680cc6SAli Bahrami 	static const Msg	binds_def[] = {
2394f680cc6SAli Bahrami 		MSG_STB_LOCAL_DEF,	MSG_STB_GLOBAL_DEF,
2404f680cc6SAli Bahrami 		MSG_STB_WEAK_DEF
241d29b2c44Sab 	};
2424f680cc6SAli Bahrami 	static const Msg	binds_cf[] = {
2434f680cc6SAli Bahrami 		MSG_STB_LOCAL_CF,	MSG_STB_GLOBAL_CF,
2444f680cc6SAli Bahrami 		MSG_STB_WEAK_CF
2454f680cc6SAli Bahrami 	};
246*8222814eSRichard Lowe 	static const Msg	binds_cfnp[] = {
247*8222814eSRichard Lowe 		MSG_STB_LOCAL_CFNP,	MSG_STB_GLOBAL_CFNP,
248*8222814eSRichard Lowe 		MSG_STB_WEAK_CFNP
249*8222814eSRichard Lowe 	};
2504f680cc6SAli Bahrami 	static const Msg	binds_nf[] = {
2514f680cc6SAli Bahrami 		MSG_STB_LOCAL_NF,	MSG_STB_GLOBAL_NF,
2524f680cc6SAli Bahrami 		MSG_STB_WEAK_NF
2534f680cc6SAli Bahrami 	};
2544f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_binds_def = {
2554f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STB_LOCAL, binds_def) };
2564f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_binds_cf = {
2574f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STB_LOCAL, binds_cf) };
258*8222814eSRichard Lowe 	static const conv_ds_msg_t ds_binds_cfnp = {
259*8222814eSRichard Lowe 	    CONV_DS_MSG_INIT(STB_LOCAL, binds_cfnp) };
2604f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_binds_nf = {
2614f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(STB_LOCAL, binds_nf) };
2624f680cc6SAli Bahrami 
2634f680cc6SAli Bahrami 
2644f680cc6SAli Bahrami 	/* Build NULL terminated return arrays for each string style */
26584f79254SToomas Soome 	static const conv_ds_t	*ds_def[] = {
2664f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_binds_def), NULL };
26784f79254SToomas Soome 	static const conv_ds_t	*ds_cf[] = {
2684f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_binds_cf), NULL };
269*8222814eSRichard Lowe 	static const conv_ds_t	*ds_cfnp[] = {
270*8222814eSRichard Lowe 		CONV_DS_ADDR(ds_binds_cfnp), NULL };
27184f79254SToomas Soome 	static const conv_ds_t	*ds_nf[] = {
2724f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_binds_nf), NULL };
2734f680cc6SAli Bahrami 
274d29b2c44Sab 
2754f680cc6SAli Bahrami 	/* Select the strings to use */
2764f680cc6SAli Bahrami 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
2774f680cc6SAli Bahrami 	case CONV_FMT_ALT_CF:
2784f680cc6SAli Bahrami 		return (ds_cf);
279*8222814eSRichard Lowe 	case CONV_FMT_ALT_CFNP:
280*8222814eSRichard Lowe 		return (ds_cfnp);
2814f680cc6SAli Bahrami 	case CONV_FMT_ALT_NF:
2824f680cc6SAli Bahrami 		return (ds_nf);
283c13de8f6Sab 	}
2844f680cc6SAli Bahrami 
2854f680cc6SAli Bahrami 	return (ds_def);
2867c478bd9Sstevel@tonic-gate }
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate const char *
conv_sym_info_bind(uchar_t bind,Conv_fmt_flags_t fmt_flags,Conv_inv_buf_t * inv_buf)289d29b2c44Sab conv_sym_info_bind(uchar_t bind, Conv_fmt_flags_t fmt_flags,
290d29b2c44Sab     Conv_inv_buf_t *inv_buf)
2917c478bd9Sstevel@tonic-gate {
2924f680cc6SAli Bahrami 	return (conv_map_ds(ELFOSABI_NONE, EM_NONE, bind,
2934f680cc6SAli Bahrami 	    conv_sym_info_bind_strings(fmt_flags), fmt_flags, inv_buf));
2944f680cc6SAli Bahrami }
2957c478bd9Sstevel@tonic-gate 
2964f680cc6SAli Bahrami conv_iter_ret_t
conv_iter_sym_info_bind(Conv_fmt_flags_t fmt_flags,conv_iter_cb_t func,void * uvalue)2974f680cc6SAli Bahrami conv_iter_sym_info_bind(Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func,
2984f680cc6SAli Bahrami     void *uvalue)
2994f680cc6SAli Bahrami {
3004f680cc6SAli Bahrami 	return (conv_iter_ds(ELFOSABI_NONE, EM_NONE,
3014f680cc6SAli Bahrami 	    conv_sym_info_bind_strings(fmt_flags), func, uvalue));
3024f680cc6SAli Bahrami }
3034f680cc6SAli Bahrami 
3044f680cc6SAli Bahrami static const conv_ds_t **
conv_sym_shndx_strings(Conv_fmt_flags_t fmt_flags)3054f680cc6SAli Bahrami conv_sym_shndx_strings(Conv_fmt_flags_t fmt_flags)
3064f680cc6SAli Bahrami {
3074f680cc6SAli Bahrami #define	ALL	ELFOSABI_NONE, EM_NONE
3084f680cc6SAli Bahrami #define	SOL	ELFOSABI_SOLARIS, EM_NONE
3094f680cc6SAli Bahrami #define	AMD	ELFOSABI_NONE, EM_AMD64
3104f680cc6SAli Bahrami 
3114f680cc6SAli Bahrami 	/*
3124f680cc6SAli Bahrami 	 * There aren't many of these values, and they are sparse,
3134f680cc6SAli Bahrami 	 * so rather than separate them into different ranges, I use
3144f680cc6SAli Bahrami 	 * a single Val_desc2 array for all of them.
3154f680cc6SAli Bahrami 	 */
3164f680cc6SAli Bahrami 	static const Val_desc2 shn_def[] = {
3174f680cc6SAli Bahrami 		{ SHN_UNDEF,		ALL,	MSG_SHN_UNDEF_CFNP },
3184f680cc6SAli Bahrami 		{ SHN_BEFORE,		ALL,	MSG_SHN_BEFORE_CFNP },
3194f680cc6SAli Bahrami 		{ SHN_AFTER,		ALL,	MSG_SHN_AFTER_CFNP },
3204f680cc6SAli Bahrami 		{ SHN_AMD64_LCOMMON,	AMD,	MSG_SHN_AMD64_LCOMMON_DEF },
3214f680cc6SAli Bahrami 		{ SHN_SUNW_IGNORE,	SOL,	MSG_SHN_SUNW_IGNORE_DEF },
3224f680cc6SAli Bahrami 		{ SHN_ABS,		ALL,	MSG_SHN_ABS_CFNP },
3234f680cc6SAli Bahrami 		{ SHN_COMMON,		ALL,	MSG_SHN_COMMON_CFNP },
3244f680cc6SAli Bahrami 		{ SHN_XINDEX,		ALL,	MSG_SHN_XINDEX_CFNP },
3254f680cc6SAli Bahrami 		{ 0 }
3264f680cc6SAli Bahrami 	};
3274f680cc6SAli Bahrami 	static const Val_desc2 shn_cf[] = {
3284f680cc6SAli Bahrami 		{ SHN_UNDEF,		ALL,	MSG_SHN_UNDEF_CF },
3294f680cc6SAli Bahrami 		{ SHN_BEFORE,		ALL,	MSG_SHN_BEFORE_CF },
3304f680cc6SAli Bahrami 		{ SHN_AFTER,		ALL,	MSG_SHN_AFTER_CF },
3314f680cc6SAli Bahrami 		{ SHN_AMD64_LCOMMON,	AMD,	MSG_SHN_AMD64_LCOMMON_CF },
3324f680cc6SAli Bahrami 		{ SHN_SUNW_IGNORE,	SOL,	MSG_SHN_SUNW_IGNORE_CF },
3334f680cc6SAli Bahrami 		{ SHN_ABS,		ALL,	MSG_SHN_ABS_CF },
3344f680cc6SAli Bahrami 		{ SHN_COMMON,		ALL,	MSG_SHN_COMMON_CF },
3354f680cc6SAli Bahrami 		{ SHN_XINDEX,		ALL,	MSG_SHN_XINDEX_CF },
3364f680cc6SAli Bahrami 		{ 0 }
3374f680cc6SAli Bahrami 	};
3384f680cc6SAli Bahrami 	static const Val_desc2 shn_cfnp[] = {
3394f680cc6SAli Bahrami 		{ SHN_UNDEF,		ALL,	MSG_SHN_UNDEF_CFNP },
3404f680cc6SAli Bahrami 		{ SHN_BEFORE,		ALL,	MSG_SHN_BEFORE_CFNP },
3414f680cc6SAli Bahrami 		{ SHN_AFTER,		ALL,	MSG_SHN_AFTER_CFNP },
3424f680cc6SAli Bahrami 		{ SHN_AMD64_LCOMMON,	AMD,	MSG_SHN_AMD64_LCOMMON_CFNP },
3434f680cc6SAli Bahrami 		{ SHN_SUNW_IGNORE,	SOL,	MSG_SHN_SUNW_IGNORE_CFNP },
3444f680cc6SAli Bahrami 		{ SHN_ABS,		ALL,	MSG_SHN_ABS_CFNP },
3454f680cc6SAli Bahrami 		{ SHN_COMMON,		ALL,	MSG_SHN_COMMON_CFNP },
3464f680cc6SAli Bahrami 		{ SHN_XINDEX,		ALL,	MSG_SHN_XINDEX_CFNP },
3474f680cc6SAli Bahrami 		{ 0 }
348d29b2c44Sab 	};
3494f680cc6SAli Bahrami 	static const Val_desc2 shn_nf[] = {
3504f680cc6SAli Bahrami 		{ SHN_UNDEF,		ALL,	MSG_SHN_UNDEF_NF },
3514f680cc6SAli Bahrami 		{ SHN_BEFORE,		ALL,	MSG_SHN_BEFORE_NF },
3524f680cc6SAli Bahrami 		{ SHN_AFTER,		ALL,	MSG_SHN_AFTER_NF },
3534f680cc6SAli Bahrami 		{ SHN_AMD64_LCOMMON,	AMD,	MSG_SHN_AMD64_LCOMMON_NF },
3544f680cc6SAli Bahrami 		{ SHN_SUNW_IGNORE,	SOL,	MSG_SHN_SUNW_IGNORE_NF },
3554f680cc6SAli Bahrami 		{ SHN_ABS,		ALL,	MSG_SHN_ABS_NF },
3564f680cc6SAli Bahrami 		{ SHN_COMMON,		ALL,	MSG_SHN_COMMON_NF },
3574f680cc6SAli Bahrami 		{ SHN_XINDEX,		ALL,	MSG_SHN_XINDEX_NF },
3584f680cc6SAli Bahrami 		{ 0 }
3594f680cc6SAli Bahrami 	};
3604f680cc6SAli Bahrami 	static const conv_ds_vd2_t ds_shn_def = {
3614f680cc6SAli Bahrami 	    CONV_DS_VD2, SHN_UNDEF, SHN_XINDEX, shn_def };
3624f680cc6SAli Bahrami 	static const conv_ds_vd2_t ds_shn_cf = {
3634f680cc6SAli Bahrami 	    CONV_DS_VD2, SHN_UNDEF, SHN_XINDEX, shn_cf };
3644f680cc6SAli Bahrami 	static const conv_ds_vd2_t ds_shn_cfnp = {
3654f680cc6SAli Bahrami 	    CONV_DS_VD2, SHN_UNDEF, SHN_XINDEX, shn_cfnp };
3664f680cc6SAli Bahrami 	static const conv_ds_vd2_t ds_shn_nf = {
3674f680cc6SAli Bahrami 	    CONV_DS_VD2, SHN_UNDEF, SHN_XINDEX, shn_nf };
3684f680cc6SAli Bahrami 
3694f680cc6SAli Bahrami 	/* Build NULL terminated return arrays for each string style */
37084f79254SToomas Soome 	static const conv_ds_t	*ds_def[] = {
3714f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_shn_def), NULL };
37284f79254SToomas Soome 	static const conv_ds_t	*ds_cf[] = {
3734f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_shn_cf), NULL };
37484f79254SToomas Soome 	static const conv_ds_t	*ds_cfnp[] = {
3754f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_shn_cfnp), NULL };
37684f79254SToomas Soome 	static const conv_ds_t	*ds_nf[] = {
3774f680cc6SAli Bahrami 		CONV_DS_ADDR(ds_shn_nf), NULL };
378d29b2c44Sab 
3794f680cc6SAli Bahrami 	/* Select the strings to use */
3804f680cc6SAli Bahrami 	switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
3814f680cc6SAli Bahrami 	case CONV_FMT_ALT_CF:
3824f680cc6SAli Bahrami 		return (ds_cf);
3834f680cc6SAli Bahrami 	case CONV_FMT_ALT_CFNP:
3844f680cc6SAli Bahrami 		return (ds_cfnp);
3854f680cc6SAli Bahrami 	case CONV_FMT_ALT_NF:
3864f680cc6SAli Bahrami 		return (ds_nf);
3874f680cc6SAli Bahrami 	}
388d29b2c44Sab 
3894f680cc6SAli Bahrami 	return (ds_def);
390d29b2c44Sab 
3914f680cc6SAli Bahrami #undef ALL
3924f680cc6SAli Bahrami #undef SOL
3934f680cc6SAli Bahrami #undef AMD
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@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)3974f680cc6SAli Bahrami conv_sym_shndx(uchar_t osabi, Half mach, Half shndx, Conv_fmt_flags_t fmt_flags,
3984f680cc6SAli Bahrami     Conv_inv_buf_t *inv_buf)
3997c478bd9Sstevel@tonic-gate {
4004f680cc6SAli Bahrami 	return (conv_map_ds(osabi, mach, shndx,
4014f680cc6SAli Bahrami 	    conv_sym_shndx_strings(fmt_flags), fmt_flags, inv_buf));
4027c478bd9Sstevel@tonic-gate }
4037c478bd9Sstevel@tonic-gate 
4044f680cc6SAli 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)4054f680cc6SAli Bahrami conv_iter_sym_shndx(conv_iter_osabi_t osabi, Half mach,
4064f680cc6SAli Bahrami     Conv_fmt_flags_t fmt_flags, conv_iter_cb_t func, void *uvalue)
4077c478bd9Sstevel@tonic-gate {
4084f680cc6SAli Bahrami 	static const Msg amd64_alias_cf[] = { MSG_SHN_X86_64_LCOMMON_CF };
4094f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_msg_amd64_alias_cf = {
4104f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(SHN_X86_64_LCOMMON, amd64_alias_cf) };
4114f680cc6SAli Bahrami 	static const conv_ds_t	*ds_amd64_alias_cf[] = {
4124f680cc6SAli Bahrami 	    CONV_DS_ADDR(ds_msg_amd64_alias_cf), NULL };
4137c478bd9Sstevel@tonic-gate 
4144f680cc6SAli Bahrami 	static const Msg amd64_alias_cfnp[] = { MSG_SHN_X86_64_LCOMMON_CFNP };
4154f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_msg_amd64_alias_cfnp = {
4164f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(SHN_X86_64_LCOMMON, amd64_alias_cfnp) };
4174f680cc6SAli Bahrami 	static const conv_ds_t	*ds_amd64_alias_cfnp[] = {
4184f680cc6SAli Bahrami 	    CONV_DS_ADDR(ds_msg_amd64_alias_cfnp), NULL };
4194f680cc6SAli Bahrami 
4204f680cc6SAli Bahrami 	static const Msg amd64_alias_nf[] = { MSG_SHN_X86_64_LCOMMON_NF };
4214f680cc6SAli Bahrami 	static const conv_ds_msg_t ds_msg_amd64_alias_nf = {
4224f680cc6SAli Bahrami 	    CONV_DS_MSG_INIT(SHN_X86_64_LCOMMON, amd64_alias_nf) };
4234f680cc6SAli Bahrami 	static const conv_ds_t	*ds_amd64_alias_nf[] = {
4244f680cc6SAli Bahrami 	    CONV_DS_ADDR(ds_msg_amd64_alias_nf), NULL };
4254f680cc6SAli Bahrami 
4264f680cc6SAli Bahrami 
4274f680cc6SAli Bahrami 	if (conv_iter_ds(osabi, mach, conv_sym_shndx_strings(fmt_flags),
4284f680cc6SAli Bahrami 	    func, uvalue) == CONV_ITER_DONE)
4294f680cc6SAli Bahrami 		return (CONV_ITER_DONE);
4304f680cc6SAli Bahrami 
4314f680cc6SAli Bahrami 	/*
4324f680cc6SAli Bahrami 	 * SHN_AMD64_LCOMMON is also known as SHN_X86_64_LCOMMON
4334f680cc6SAli Bahrami 	 */
4344f680cc6SAli Bahrami 	if (mach == EM_AMD64) {
4354f680cc6SAli Bahrami 		const conv_ds_t	**ds;
4364f680cc6SAli Bahrami 
4374f680cc6SAli Bahrami 		switch (CONV_TYPE_FMT_ALT(fmt_flags)) {
4384f680cc6SAli Bahrami 		case CONV_FMT_ALT_CF:
4394f680cc6SAli Bahrami 			ds = ds_amd64_alias_cf;
4404f680cc6SAli Bahrami 			break;
4414f680cc6SAli Bahrami 		case CONV_FMT_ALT_NF:
4424f680cc6SAli Bahrami 			ds = ds_amd64_alias_nf;
4434f680cc6SAli Bahrami 			break;
4444f680cc6SAli Bahrami 		default:
4454f680cc6SAli Bahrami 			ds = ds_amd64_alias_cfnp;
4464f680cc6SAli Bahrami 			break;
4474f680cc6SAli Bahrami 		}
4484f680cc6SAli Bahrami 		return (conv_iter_ds(ELFOSABI_NONE, mach, ds, func, uvalue));
4494f680cc6SAli Bahrami 	}
4504f680cc6SAli Bahrami 
4514f680cc6SAli Bahrami 	return (CONV_ITER_CONT);
4527c478bd9Sstevel@tonic-gate }
453