xref: /illumos-gate/usr/src/cmd/sgs/libconv/common/symbols.c (revision 5aefb6555731130ca4fd295960123d71f2d21fe8)
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 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 /*
29  * String conversion routines for symbol attributes.
30  */
31 #include	<stdio.h>
32 #include	<sys/machelf.h>
33 #include	<sys/elf_SPARC.h>
34 #include	<sys/elf_amd64.h>
35 #include	"_conv.h"
36 #include	"symbols_msg.h"
37 
38 const char *
39 conv_sym_other(uchar_t other)
40 {
41 	static char		string[CONV_INV_STRSIZE];
42 	static const char	visibility[4] = {
43 		'D',	/* STV_DEFAULT */
44 		'I',	/* STV_INTERNAL */
45 		'H',	/* STV_HIDDEN */
46 		'P'	/* STV_PROTECTED */
47 	};
48 	uint_t		vis = ELF_ST_VISIBILITY(other);
49 	uint_t		ndx = 0;
50 
51 	string[ndx++] = visibility[vis];
52 
53 	/*
54 	 * If unkown bits are present in stother - throw out a '?'
55 	 */
56 	if (other & ~MSK_SYM_VISIBILITY)
57 		string[ndx++] = '?';
58 	string[ndx++] = '\0';
59 
60 	return (string);
61 }
62 
63 const char *
64 conv_sym_info_type(Half mach, uchar_t type)
65 {
66 	static char		string[CONV_INV_STRSIZE];
67 	static const Msg	types[] = {
68 		MSG_STT_NOTYPE,		MSG_STT_OBJECT,		MSG_STT_FUNC,
69 		MSG_STT_SECTION,	MSG_STT_FILE,		MSG_STT_COMMON,
70 		MSG_STT_TLS
71 	};
72 
73 	if (type < STT_NUM)
74 		return (MSG_ORIG(types[type]));
75 	else if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
76 	    (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER))
77 		return (MSG_ORIG(MSG_STT_REGISTER));
78 	else
79 		return (conv_invalid_val(string, CONV_INV_STRSIZE, type, 0));
80 }
81 
82 const char *
83 conv_sym_info_bind(uchar_t bind)
84 {
85 	static char		string[CONV_INV_STRSIZE];
86 	static const Msg	binds[] = {
87 		MSG_STB_LOCAL,		MSG_STB_GLOBAL,		MSG_STB_WEAK
88 	};
89 
90 	if (bind >= STB_NUM)
91 		return (conv_invalid_val(string, CONV_INV_STRSIZE, bind, 0));
92 	else
93 		return (MSG_ORIG(binds[bind]));
94 }
95 
96 const char *
97 conv_sym_shndx(Half shndx)
98 {
99 	static	char	string[CONV_INV_STRSIZE];
100 
101 	switch (shndx) {
102 	case SHN_UNDEF:
103 		return (MSG_ORIG(MSG_SHN_UNDEF));
104 	case SHN_SUNW_IGNORE:
105 		return (MSG_ORIG(MSG_SHN_SUNW_IGNORE));
106 	case SHN_ABS:
107 		return (MSG_ORIG(MSG_SHN_ABS));
108 	case SHN_COMMON:
109 		return (MSG_ORIG(MSG_SHN_COMMON));
110 	case SHN_AMD64_LCOMMON:
111 		return (MSG_ORIG(MSG_SHN_AMD64_LCOMMON));
112 	case SHN_AFTER:
113 		return (MSG_ORIG(MSG_SHN_AFTER));
114 	case SHN_BEFORE:
115 		return (MSG_ORIG(MSG_SHN_BEFORE));
116 	case SHN_XINDEX:
117 		return (MSG_ORIG(MSG_SHN_XINDEX));
118 	default:
119 		return (conv_invalid_val(string, CONV_INV_STRSIZE, shndx,
120 		    CONV_INV_DECIMAL));
121 	}
122 }
123 
124 const char *
125 conv_sym_value(Half mach, uchar_t type, Addr value)
126 {
127 	static char	string[CONV_INV_STRSIZE];
128 
129 	if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
130 	    (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER))
131 		return (conv_sym_SPARC_value(value));
132 
133 	(void) sprintf(string, MSG_ORIG(MSG_SYM_FMT_VAL), EC_ADDR(value));
134 	return (string);
135 }
136