xref: /titanic_50/usr/src/cmd/sgs/libconv/common/symbols.c (revision dfb96a4f56fb431b915bc67e5d9d5c8d4f4f6679)
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 2007 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 Conv_inv_buf_t	string;
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, int fmt_flags)
65 {
66 	static Conv_inv_buf_t	string;
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,
80 			type, fmt_flags));
81 	}
82 }
83 
84 const char *
85 conv_sym_info_bind(uchar_t bind, int fmt_flags)
86 {
87 	static Conv_inv_buf_t	string;
88 	static const Msg	binds[] = {
89 		MSG_STB_LOCAL,		MSG_STB_GLOBAL,		MSG_STB_WEAK
90 	};
91 
92 	if (bind >= STB_NUM)
93 		return (conv_invalid_val(string, CONV_INV_STRSIZE,
94 			bind, fmt_flags));
95 	else
96 		return (MSG_ORIG(binds[bind]));
97 }
98 
99 const char *
100 conv_sym_shndx(Half shndx)
101 {
102 	static Conv_inv_buf_t	string;
103 
104 	switch (shndx) {
105 	case SHN_UNDEF:
106 		return (MSG_ORIG(MSG_SHN_UNDEF));
107 	case SHN_SUNW_IGNORE:
108 		return (MSG_ORIG(MSG_SHN_SUNW_IGNORE));
109 	case SHN_ABS:
110 		return (MSG_ORIG(MSG_SHN_ABS));
111 	case SHN_COMMON:
112 		return (MSG_ORIG(MSG_SHN_COMMON));
113 	case SHN_AMD64_LCOMMON:
114 		return (MSG_ORIG(MSG_SHN_AMD64_LCOMMON));
115 	case SHN_AFTER:
116 		return (MSG_ORIG(MSG_SHN_AFTER));
117 	case SHN_BEFORE:
118 		return (MSG_ORIG(MSG_SHN_BEFORE));
119 	case SHN_XINDEX:
120 		return (MSG_ORIG(MSG_SHN_XINDEX));
121 	default:
122 		return (conv_invalid_val(string, CONV_INV_STRSIZE, shndx,
123 		    CONV_FMT_DECIMAL));
124 	}
125 }
126 
127 const char *
128 conv_sym_value(Half mach, uchar_t type, Addr value)
129 {
130 	static Conv_inv_buf_t	string;
131 
132 	if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
133 	    (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER))
134 		return (conv_sym_SPARC_value(value, 0));
135 
136 	(void) snprintf(string, sizeof (string), MSG_ORIG(MSG_SYM_FMT_VAL),
137 	    EC_ADDR(value));
138 	return (string);
139 }
140