xref: /onnv-gate/usr/src/cmd/sgs/libconv/common/symbols.c (revision 1618:8c9a4f31d225)
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
5*1618Srie  * Common Development and Distribution License (the "License").
6*1618Srie  * 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  */
21*1618Srie 
220Sstevel@tonic-gate /*
23*1618Srie  * Copyright 2006 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>
32*1618Srie #include	<sys/machelf.h>
330Sstevel@tonic-gate #include	<sys/elf_SPARC.h>
34574Sseizo #include	<sys/elf_amd64.h>
35*1618Srie #include	"_conv.h"
36*1618Srie #include	"symbols_msg.h"
370Sstevel@tonic-gate 
380Sstevel@tonic-gate const char *
39*1618Srie conv_sym_other(uchar_t other)
400Sstevel@tonic-gate {
41*1618Srie 	static char		string[CONV_INV_STRSIZE];
42*1618Srie 	static const char	visibility[4] = {
43*1618Srie 		'D',	/* STV_DEFAULT */
44*1618Srie 		'I',	/* STV_INTERNAL */
45*1618Srie 		'H',	/* STV_HIDDEN */
46*1618Srie 		'P'	/* STV_PROTECTED */
47*1618Srie 	};
48*1618Srie 	uint_t		vis = ELF_ST_VISIBILITY(other);
49*1618Srie 	uint_t		ndx = 0;
500Sstevel@tonic-gate 
51*1618Srie 	string[ndx++] = visibility[vis];
52*1618Srie 
530Sstevel@tonic-gate 	/*
540Sstevel@tonic-gate 	 * If unkown bits are present in stother - throw out a '?'
550Sstevel@tonic-gate 	 */
56*1618Srie 	if (other & ~MSK_SYM_VISIBILITY)
570Sstevel@tonic-gate 		string[ndx++] = '?';
580Sstevel@tonic-gate 	string[ndx++] = '\0';
590Sstevel@tonic-gate 
600Sstevel@tonic-gate 	return (string);
610Sstevel@tonic-gate }
620Sstevel@tonic-gate 
630Sstevel@tonic-gate const char *
64*1618Srie conv_sym_info_type(Half mach, uchar_t type)
650Sstevel@tonic-gate {
66*1618Srie 	static char		string[CONV_INV_STRSIZE];
67*1618Srie 	static const Msg	types[] = {
68*1618Srie 		MSG_STT_NOTYPE,		MSG_STT_OBJECT,		MSG_STT_FUNC,
69*1618Srie 		MSG_STT_SECTION,	MSG_STT_FILE,		MSG_STT_COMMON,
70*1618Srie 		MSG_STT_TLS
71*1618Srie 	};
720Sstevel@tonic-gate 
730Sstevel@tonic-gate 	if (type < STT_NUM)
740Sstevel@tonic-gate 		return (MSG_ORIG(types[type]));
750Sstevel@tonic-gate 	else if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
760Sstevel@tonic-gate 	    (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER))
770Sstevel@tonic-gate 		return (MSG_ORIG(MSG_STT_REGISTER));
780Sstevel@tonic-gate 	else
79*1618Srie 		return (conv_invalid_val(string, CONV_INV_STRSIZE, type, 0));
800Sstevel@tonic-gate }
810Sstevel@tonic-gate 
820Sstevel@tonic-gate const char *
83*1618Srie conv_sym_info_bind(uchar_t bind)
840Sstevel@tonic-gate {
85*1618Srie 	static char		string[CONV_INV_STRSIZE];
86*1618Srie 	static const Msg	binds[] = {
87*1618Srie 		MSG_STB_LOCAL,		MSG_STB_GLOBAL,		MSG_STB_WEAK
88*1618Srie 	};
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	if (bind >= STB_NUM)
91*1618Srie 		return (conv_invalid_val(string, CONV_INV_STRSIZE, bind, 0));
920Sstevel@tonic-gate 	else
930Sstevel@tonic-gate 		return (MSG_ORIG(binds[bind]));
940Sstevel@tonic-gate }
950Sstevel@tonic-gate 
960Sstevel@tonic-gate const char *
97*1618Srie conv_sym_shndx(Half shndx)
980Sstevel@tonic-gate {
99*1618Srie 	static	char	string[CONV_INV_STRSIZE];
1000Sstevel@tonic-gate 
101*1618Srie 	switch (shndx) {
102*1618Srie 	case SHN_UNDEF:
1030Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_UNDEF));
104*1618Srie 	case SHN_SUNW_IGNORE:
1050Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_SUNW_IGNORE));
106*1618Srie 	case SHN_ABS:
1070Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_ABS));
108*1618Srie 	case SHN_COMMON:
1090Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_COMMON));
110*1618Srie 	case SHN_AMD64_LCOMMON:
111*1618Srie 		return (MSG_ORIG(MSG_SHN_AMD64_LCOMMON));
112*1618Srie 	case SHN_AFTER:
1130Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_AFTER));
114*1618Srie 	case SHN_BEFORE:
1150Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_BEFORE));
116*1618Srie 	case SHN_XINDEX:
1170Sstevel@tonic-gate 		return (MSG_ORIG(MSG_SHN_XINDEX));
118*1618Srie 	default:
119*1618Srie 		return (conv_invalid_val(string, CONV_INV_STRSIZE, shndx,
120*1618Srie 		    CONV_INV_DECIMAL));
121*1618Srie 	}
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate const char *
125*1618Srie conv_sym_value(Half mach, uchar_t type, Addr value)
1260Sstevel@tonic-gate {
127*1618Srie 	static char	string[CONV_INV_STRSIZE];
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate 	if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) ||
1300Sstevel@tonic-gate 	    (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER))
131*1618Srie 		return (conv_sym_SPARC_value(value));
1320Sstevel@tonic-gate 
133*1618Srie 	(void) sprintf(string, MSG_ORIG(MSG_SYM_FMT_VAL), EC_ADDR(value));
1340Sstevel@tonic-gate 	return (string);
1350Sstevel@tonic-gate }
136