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 /* 231618Srie * 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> 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 * 391618Srie conv_sym_other(uchar_t other) 400Sstevel@tonic-gate { 411618Srie static char string[CONV_INV_STRSIZE]; 421618Srie static const char visibility[4] = { 431618Srie 'D', /* STV_DEFAULT */ 441618Srie 'I', /* STV_INTERNAL */ 451618Srie 'H', /* STV_HIDDEN */ 461618Srie 'P' /* STV_PROTECTED */ 471618Srie }; 481618Srie uint_t vis = ELF_ST_VISIBILITY(other); 491618Srie uint_t ndx = 0; 500Sstevel@tonic-gate 511618Srie string[ndx++] = visibility[vis]; 521618Srie 530Sstevel@tonic-gate /* 540Sstevel@tonic-gate * If unkown bits are present in stother - throw out a '?' 550Sstevel@tonic-gate */ 561618Srie 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*1976Sab196087 conv_sym_info_type(Half mach, uchar_t type, int fmt_flags) 650Sstevel@tonic-gate { 661618Srie static char string[CONV_INV_STRSIZE]; 671618Srie static const Msg types[] = { 681618Srie MSG_STT_NOTYPE, MSG_STT_OBJECT, MSG_STT_FUNC, 691618Srie MSG_STT_SECTION, MSG_STT_FILE, MSG_STT_COMMON, 701618Srie MSG_STT_TLS 711618Srie }; 720Sstevel@tonic-gate 73*1976Sab196087 if (type < STT_NUM) { 740Sstevel@tonic-gate return (MSG_ORIG(types[type])); 75*1976Sab196087 } else if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) || 76*1976Sab196087 (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER)) { 770Sstevel@tonic-gate return (MSG_ORIG(MSG_STT_REGISTER)); 78*1976Sab196087 } else { 79*1976Sab196087 return (conv_invalid_val(string, CONV_INV_STRSIZE, 80*1976Sab196087 type, fmt_flags)); 81*1976Sab196087 } 820Sstevel@tonic-gate } 830Sstevel@tonic-gate 840Sstevel@tonic-gate const char * 85*1976Sab196087 conv_sym_info_bind(uchar_t bind, int fmt_flags) 860Sstevel@tonic-gate { 871618Srie static char string[CONV_INV_STRSIZE]; 881618Srie static const Msg binds[] = { 891618Srie MSG_STB_LOCAL, MSG_STB_GLOBAL, MSG_STB_WEAK 901618Srie }; 910Sstevel@tonic-gate 920Sstevel@tonic-gate if (bind >= STB_NUM) 93*1976Sab196087 return (conv_invalid_val(string, CONV_INV_STRSIZE, 94*1976Sab196087 bind, fmt_flags)); 950Sstevel@tonic-gate else 960Sstevel@tonic-gate return (MSG_ORIG(binds[bind])); 970Sstevel@tonic-gate } 980Sstevel@tonic-gate 990Sstevel@tonic-gate const char * 1001618Srie conv_sym_shndx(Half shndx) 1010Sstevel@tonic-gate { 1021618Srie static char string[CONV_INV_STRSIZE]; 1030Sstevel@tonic-gate 1041618Srie switch (shndx) { 1051618Srie case SHN_UNDEF: 1060Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_UNDEF)); 1071618Srie case SHN_SUNW_IGNORE: 1080Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_SUNW_IGNORE)); 1091618Srie case SHN_ABS: 1100Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_ABS)); 1111618Srie case SHN_COMMON: 1120Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_COMMON)); 1131618Srie case SHN_AMD64_LCOMMON: 1141618Srie return (MSG_ORIG(MSG_SHN_AMD64_LCOMMON)); 1151618Srie case SHN_AFTER: 1160Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_AFTER)); 1171618Srie case SHN_BEFORE: 1180Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_BEFORE)); 1191618Srie case SHN_XINDEX: 1200Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_XINDEX)); 1211618Srie default: 1221618Srie return (conv_invalid_val(string, CONV_INV_STRSIZE, shndx, 123*1976Sab196087 CONV_FMT_DECIMAL)); 1241618Srie } 1250Sstevel@tonic-gate } 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate const char * 1281618Srie conv_sym_value(Half mach, uchar_t type, Addr value) 1290Sstevel@tonic-gate { 1301618Srie static char string[CONV_INV_STRSIZE]; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) || 1330Sstevel@tonic-gate (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER)) 134*1976Sab196087 return (conv_sym_SPARC_value(value, 0)); 1350Sstevel@tonic-gate 1361618Srie (void) sprintf(string, MSG_ORIG(MSG_SYM_FMT_VAL), EC_ADDR(value)); 1370Sstevel@tonic-gate return (string); 1380Sstevel@tonic-gate } 139