xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/symbols.c (revision 5088:26c540f30cd3)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51618Srie  * Common Development and Distribution License (the "License").
61618Srie  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
211618Srie 
220Sstevel@tonic-gate /*
233875Sab196087  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * String conversion routines for symbol attributes.
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate #include	<stdio.h>
321618Srie #include	<sys/machelf.h>
330Sstevel@tonic-gate #include	<sys/elf_SPARC.h>
34574Sseizo #include	<sys/elf_amd64.h>
351618Srie #include	"_conv.h"
361618Srie #include	"symbols_msg.h"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate const char *
394734Sab196087 conv_sym_other(uchar_t other, Conv_inv_buf_t *inv_buf)
400Sstevel@tonic-gate {
411618Srie 	static const char	visibility[4] = {
421618Srie 		'D',	/* STV_DEFAULT */
431618Srie 		'I',	/* STV_INTERNAL */
441618Srie 		'H',	/* STV_HIDDEN */
451618Srie 		'P'	/* STV_PROTECTED */
461618Srie 	};
471618Srie 	uint_t		vis = ELF_ST_VISIBILITY(other);
481618Srie 	uint_t		ndx = 0;
490Sstevel@tonic-gate 
504734Sab196087 	inv_buf->buf[ndx++] = visibility[vis];
511618Srie 
520Sstevel@tonic-gate 	/*
53*5088Sab196087 	 * If unknown bits are present in st_other - throw out a '?'
540Sstevel@tonic-gate 	 */
551618Srie 	if (other & ~MSK_SYM_VISIBILITY)
564734Sab196087 		inv_buf->buf[ndx++] = '?';
574734Sab196087 	inv_buf->buf[ndx++] = '\0';
580Sstevel@tonic-gate 
594734Sab196087 	return (inv_buf->buf);
600Sstevel@tonic-gate }
610Sstevel@tonic-gate 
620Sstevel@tonic-gate const char *
63*5088Sab196087 conv_sym_other_vis(uchar_t value, Conv_fmt_flags_t fmt_flags,
64*5088Sab196087     Conv_inv_buf_t *inv_buf)
65*5088Sab196087 {
66*5088Sab196087 	static const Msg	vis[] = {
67*5088Sab196087 		MSG_STV_DEFAULT,	MSG_STV_INTERNAL,
68*5088Sab196087 		MSG_STV_HIDDEN,		MSG_STV_PROTECTED
69*5088Sab196087 	};
70*5088Sab196087 
71*5088Sab196087 	static const Msg	vis_alt[] = {
72*5088Sab196087 		MSG_STV_DEFAULT_ALT,	MSG_STV_INTERNAL_ALT,
73*5088Sab196087 		MSG_STV_HIDDEN_ALT,	MSG_STV_PROTECTED_ALT
74*5088Sab196087 	};
75*5088Sab196087 
76*5088Sab196087 	if (value >= (sizeof (vis) / sizeof (vis[0])))
77*5088Sab196087 		return (conv_invalid_val(inv_buf, value, fmt_flags));
78*5088Sab196087 
79*5088Sab196087 	/* If full ELF names are desired, use those strings */
80*5088Sab196087 	if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME)
81*5088Sab196087 		return (MSG_ORIG(vis_alt[value]));
82*5088Sab196087 
83*5088Sab196087 	/* Default strings */
84*5088Sab196087 	return (MSG_ORIG(vis[value]));
85*5088Sab196087 }
86*5088Sab196087 
87*5088Sab196087 const char *
88*5088Sab196087 conv_sym_info_type(Half mach, uchar_t type, Conv_fmt_flags_t fmt_flags,
894734Sab196087     Conv_inv_buf_t *inv_buf)
900Sstevel@tonic-gate {
911618Srie 	static const Msg	types[] = {
92*5088Sab196087 		MSG_STT_NOTYPE,		MSG_STT_OBJECT,
93*5088Sab196087 		MSG_STT_FUNC,		MSG_STT_SECTION,
94*5088Sab196087 		MSG_STT_FILE,		MSG_STT_COMMON,
951618Srie 		MSG_STT_TLS
961618Srie 	};
970Sstevel@tonic-gate 
98*5088Sab196087 	static const Msg	types_alt[] = {
99*5088Sab196087 		MSG_STT_NOTYPE_ALT,	MSG_STT_OBJECT_ALT,
100*5088Sab196087 		MSG_STT_FUNC_ALT,	MSG_STT_SECTION_ALT,
101*5088Sab196087 		MSG_STT_FILE_ALT,	MSG_STT_COMMON_ALT,
102*5088Sab196087 		MSG_STT_TLS_ALT
103*5088Sab196087 	};
104*5088Sab196087 
1051976Sab196087 	if (type < STT_NUM) {
106*5088Sab196087 		/* If full ELF names are desired, use those strings */
107*5088Sab196087 		if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME)
108*5088Sab196087 			return (MSG_ORIG(types_alt[type]));
109*5088Sab196087 
110*5088Sab196087 		/* Default strings */
1110Sstevel@tonic-gate 		return (MSG_ORIG(types[type]));
1121976Sab196087 	} else if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
1131976Sab196087 	    (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER)) {
114*5088Sab196087 		if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME)
115*5088Sab196087 			return (MSG_ORIG(MSG_STT_SPARC_REGISTER_ALT));
116*5088Sab196087 
117*5088Sab196087 		return (MSG_ORIG(MSG_STT_SPARC_REGISTER));
1181976Sab196087 	} else {
1194734Sab196087 		return (conv_invalid_val(inv_buf, type, fmt_flags));
1201976Sab196087 	}
1210Sstevel@tonic-gate }
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate const char *
124*5088Sab196087 conv_sym_info_bind(uchar_t bind, Conv_fmt_flags_t fmt_flags,
125*5088Sab196087     Conv_inv_buf_t *inv_buf)
1260Sstevel@tonic-gate {
1271618Srie 	static const Msg	binds[] = {
1281618Srie 		MSG_STB_LOCAL,		MSG_STB_GLOBAL,		MSG_STB_WEAK
1291618Srie 	};
1300Sstevel@tonic-gate 
131*5088Sab196087 	static const Msg	binds_alt[] = {
132*5088Sab196087 		MSG_STB_LOCAL_ALT,	MSG_STB_GLOBAL_ALT,	MSG_STB_WEAK_ALT
133*5088Sab196087 	};
134*5088Sab196087 
1350Sstevel@tonic-gate 	if (bind >= STB_NUM)
1364734Sab196087 		return (conv_invalid_val(inv_buf, bind, fmt_flags));
137*5088Sab196087 
138*5088Sab196087 	/* If full ELF names are desired, use those strings */
139*5088Sab196087 	if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME)
140*5088Sab196087 		return (MSG_ORIG(binds_alt[bind]));
141*5088Sab196087 
142*5088Sab196087 	/* Default strings */
143*5088Sab196087 	return (MSG_ORIG(binds[bind]));
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate const char *
1474734Sab196087 conv_sym_shndx(Half shndx, Conv_inv_buf_t *inv_buf)
1480Sstevel@tonic-gate {
1491618Srie 	switch (shndx) {
1501618Srie 	case SHN_UNDEF:
1510Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_UNDEF));
1521618Srie 	case SHN_SUNW_IGNORE:
1530Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_SUNW_IGNORE));
1541618Srie 	case SHN_ABS:
1550Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_ABS));
1561618Srie 	case SHN_COMMON:
1570Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_COMMON));
1581618Srie 	case SHN_AMD64_LCOMMON:
1591618Srie 		return (MSG_ORIG(MSG_SHN_AMD64_LCOMMON));
1601618Srie 	case SHN_AFTER:
1610Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_AFTER));
1621618Srie 	case SHN_BEFORE:
1630Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_BEFORE));
1641618Srie 	case SHN_XINDEX:
1650Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_XINDEX));
1661618Srie 	default:
1674734Sab196087 		return (conv_invalid_val(inv_buf, shndx, CONV_FMT_DECIMAL));
1681618Srie 	}
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate const char *
1724734Sab196087 conv_sym_value(Half mach, uchar_t type, Addr value, Conv_inv_buf_t *inv_buf)
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate 	if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
1750Sstevel@tonic-gate 	    (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER))
1764734Sab196087 		return (conv_sym_SPARC_value(value, 0, inv_buf));
1770Sstevel@tonic-gate 
1784734Sab196087 	(void) snprintf(inv_buf->buf, sizeof (inv_buf->buf),
1794734Sab196087 	    MSG_ORIG(MSG_SYM_FMT_VAL), EC_ADDR(value));
1804734Sab196087 	return (inv_buf->buf);
1810Sstevel@tonic-gate }
182