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 /* 23*9085SAli.Bahrami@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * String conversion routines for symbol attributes. 290Sstevel@tonic-gate */ 300Sstevel@tonic-gate #include <stdio.h> 316206Sab196087 #include <_machelf.h> 320Sstevel@tonic-gate #include <sys/elf_SPARC.h> 33574Sseizo #include <sys/elf_amd64.h> 341618Srie #include "_conv.h" 351618Srie #include "symbols_msg.h" 360Sstevel@tonic-gate 370Sstevel@tonic-gate const char * 384734Sab196087 conv_sym_other(uchar_t other, Conv_inv_buf_t *inv_buf) 390Sstevel@tonic-gate { 405220Srie static const char visibility[7] = { 411618Srie 'D', /* STV_DEFAULT */ 421618Srie 'I', /* STV_INTERNAL */ 431618Srie 'H', /* STV_HIDDEN */ 445220Srie 'P', /* STV_PROTECTED */ 455220Srie 'X', /* STV_EXPORTED */ 465220Srie 'S', /* STV_SINGLETON */ 475220Srie 'E' /* STV_ELIMINATE */ 481618Srie }; 495220Srie uchar_t vis = ELF_ST_VISIBILITY(other); 501618Srie uint_t ndx = 0; 510Sstevel@tonic-gate 524734Sab196087 inv_buf->buf[ndx++] = visibility[vis]; 531618Srie 540Sstevel@tonic-gate /* 555088Sab196087 * If unknown bits are present in st_other - throw out a '?' 560Sstevel@tonic-gate */ 571618Srie if (other & ~MSK_SYM_VISIBILITY) 584734Sab196087 inv_buf->buf[ndx++] = '?'; 594734Sab196087 inv_buf->buf[ndx++] = '\0'; 600Sstevel@tonic-gate 614734Sab196087 return (inv_buf->buf); 620Sstevel@tonic-gate } 630Sstevel@tonic-gate 640Sstevel@tonic-gate const char * 655088Sab196087 conv_sym_other_vis(uchar_t value, Conv_fmt_flags_t fmt_flags, 665088Sab196087 Conv_inv_buf_t *inv_buf) 675088Sab196087 { 685088Sab196087 static const Msg vis[] = { 695088Sab196087 MSG_STV_DEFAULT, MSG_STV_INTERNAL, 705220Srie MSG_STV_HIDDEN, MSG_STV_PROTECTED, 715220Srie MSG_STV_EXPORTED, MSG_STV_SINGLETON, 725220Srie MSG_STV_ELIMINATE 735088Sab196087 }; 745088Sab196087 755088Sab196087 static const Msg vis_alt[] = { 765088Sab196087 MSG_STV_DEFAULT_ALT, MSG_STV_INTERNAL_ALT, 775220Srie MSG_STV_HIDDEN_ALT, MSG_STV_PROTECTED_ALT, 785220Srie MSG_STV_EXPORTED_ALT, MSG_STV_SINGLETON_ALT, 795220Srie MSG_STV_ELIMINATE_ALT 805088Sab196087 }; 815088Sab196087 825088Sab196087 if (value >= (sizeof (vis) / sizeof (vis[0]))) 835088Sab196087 return (conv_invalid_val(inv_buf, value, fmt_flags)); 845088Sab196087 855088Sab196087 /* If full ELF names are desired, use those strings */ 865088Sab196087 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME) 875088Sab196087 return (MSG_ORIG(vis_alt[value])); 885088Sab196087 895088Sab196087 /* Default strings */ 905088Sab196087 return (MSG_ORIG(vis[value])); 915088Sab196087 } 925088Sab196087 935088Sab196087 const char * 945088Sab196087 conv_sym_info_type(Half mach, uchar_t type, Conv_fmt_flags_t fmt_flags, 954734Sab196087 Conv_inv_buf_t *inv_buf) 960Sstevel@tonic-gate { 971618Srie static const Msg types[] = { 985088Sab196087 MSG_STT_NOTYPE, MSG_STT_OBJECT, 995088Sab196087 MSG_STT_FUNC, MSG_STT_SECTION, 1005088Sab196087 MSG_STT_FILE, MSG_STT_COMMON, 101*9085SAli.Bahrami@Sun.COM MSG_STT_TLS, MSG_STT_IFUNC 1021618Srie }; 1030Sstevel@tonic-gate 1045088Sab196087 static const Msg types_alt[] = { 1055088Sab196087 MSG_STT_NOTYPE_ALT, MSG_STT_OBJECT_ALT, 1065088Sab196087 MSG_STT_FUNC_ALT, MSG_STT_SECTION_ALT, 1075088Sab196087 MSG_STT_FILE_ALT, MSG_STT_COMMON_ALT, 108*9085SAli.Bahrami@Sun.COM MSG_STT_TLS_ALT, MSG_STT_IFUNC_ALT 1095088Sab196087 }; 1105088Sab196087 1111976Sab196087 if (type < STT_NUM) { 1125088Sab196087 /* If full ELF names are desired, use those strings */ 1135088Sab196087 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME) 1145088Sab196087 return (MSG_ORIG(types_alt[type])); 1155088Sab196087 1165088Sab196087 /* Default strings */ 1170Sstevel@tonic-gate return (MSG_ORIG(types[type])); 1181976Sab196087 } else if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) || 1191976Sab196087 (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER)) { 1205088Sab196087 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME) 1215088Sab196087 return (MSG_ORIG(MSG_STT_SPARC_REGISTER_ALT)); 1225088Sab196087 1235088Sab196087 return (MSG_ORIG(MSG_STT_SPARC_REGISTER)); 1241976Sab196087 } else { 1254734Sab196087 return (conv_invalid_val(inv_buf, type, fmt_flags)); 1261976Sab196087 } 1270Sstevel@tonic-gate } 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate const char * 1305088Sab196087 conv_sym_info_bind(uchar_t bind, Conv_fmt_flags_t fmt_flags, 1315088Sab196087 Conv_inv_buf_t *inv_buf) 1320Sstevel@tonic-gate { 1331618Srie static const Msg binds[] = { 1341618Srie MSG_STB_LOCAL, MSG_STB_GLOBAL, MSG_STB_WEAK 1351618Srie }; 1360Sstevel@tonic-gate 1375088Sab196087 static const Msg binds_alt[] = { 1385088Sab196087 MSG_STB_LOCAL_ALT, MSG_STB_GLOBAL_ALT, MSG_STB_WEAK_ALT 1395088Sab196087 }; 1405088Sab196087 1410Sstevel@tonic-gate if (bind >= STB_NUM) 1424734Sab196087 return (conv_invalid_val(inv_buf, bind, fmt_flags)); 1435088Sab196087 1445088Sab196087 /* If full ELF names are desired, use those strings */ 1455088Sab196087 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME) 1465088Sab196087 return (MSG_ORIG(binds_alt[bind])); 1475088Sab196087 1485088Sab196087 /* Default strings */ 1495088Sab196087 return (MSG_ORIG(binds[bind])); 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate const char * 1534734Sab196087 conv_sym_shndx(Half shndx, Conv_inv_buf_t *inv_buf) 1540Sstevel@tonic-gate { 1551618Srie switch (shndx) { 1561618Srie case SHN_UNDEF: 1570Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_UNDEF)); 1581618Srie case SHN_SUNW_IGNORE: 1590Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_SUNW_IGNORE)); 1601618Srie case SHN_ABS: 1610Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_ABS)); 1621618Srie case SHN_COMMON: 1630Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_COMMON)); 1641618Srie case SHN_AMD64_LCOMMON: 1651618Srie return (MSG_ORIG(MSG_SHN_AMD64_LCOMMON)); 1661618Srie case SHN_AFTER: 1670Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_AFTER)); 1681618Srie case SHN_BEFORE: 1690Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_BEFORE)); 1701618Srie case SHN_XINDEX: 1710Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_XINDEX)); 1721618Srie default: 1734734Sab196087 return (conv_invalid_val(inv_buf, shndx, CONV_FMT_DECIMAL)); 1741618Srie } 1750Sstevel@tonic-gate } 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate const char * 1784734Sab196087 conv_sym_value(Half mach, uchar_t type, Addr value, Conv_inv_buf_t *inv_buf) 1790Sstevel@tonic-gate { 1800Sstevel@tonic-gate if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) || 1810Sstevel@tonic-gate (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER)) 1824734Sab196087 return (conv_sym_SPARC_value(value, 0, inv_buf)); 1830Sstevel@tonic-gate 1844734Sab196087 (void) snprintf(inv_buf->buf, sizeof (inv_buf->buf), 1854734Sab196087 MSG_ORIG(MSG_SYM_FMT_VAL), EC_ADDR(value)); 1864734Sab196087 return (inv_buf->buf); 1870Sstevel@tonic-gate } 188