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*6206Sab196087 * Copyright 2008 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*6206Sab196087 #include <_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 * 394734Sab196087 conv_sym_other(uchar_t other, Conv_inv_buf_t *inv_buf) 400Sstevel@tonic-gate { 415220Srie static const char visibility[7] = { 421618Srie 'D', /* STV_DEFAULT */ 431618Srie 'I', /* STV_INTERNAL */ 441618Srie 'H', /* STV_HIDDEN */ 455220Srie 'P', /* STV_PROTECTED */ 465220Srie 'X', /* STV_EXPORTED */ 475220Srie 'S', /* STV_SINGLETON */ 485220Srie 'E' /* STV_ELIMINATE */ 491618Srie }; 505220Srie uchar_t vis = ELF_ST_VISIBILITY(other); 511618Srie uint_t ndx = 0; 520Sstevel@tonic-gate 534734Sab196087 inv_buf->buf[ndx++] = visibility[vis]; 541618Srie 550Sstevel@tonic-gate /* 565088Sab196087 * If unknown bits are present in st_other - throw out a '?' 570Sstevel@tonic-gate */ 581618Srie if (other & ~MSK_SYM_VISIBILITY) 594734Sab196087 inv_buf->buf[ndx++] = '?'; 604734Sab196087 inv_buf->buf[ndx++] = '\0'; 610Sstevel@tonic-gate 624734Sab196087 return (inv_buf->buf); 630Sstevel@tonic-gate } 640Sstevel@tonic-gate 650Sstevel@tonic-gate const char * 665088Sab196087 conv_sym_other_vis(uchar_t value, Conv_fmt_flags_t fmt_flags, 675088Sab196087 Conv_inv_buf_t *inv_buf) 685088Sab196087 { 695088Sab196087 static const Msg vis[] = { 705088Sab196087 MSG_STV_DEFAULT, MSG_STV_INTERNAL, 715220Srie MSG_STV_HIDDEN, MSG_STV_PROTECTED, 725220Srie MSG_STV_EXPORTED, MSG_STV_SINGLETON, 735220Srie MSG_STV_ELIMINATE 745088Sab196087 }; 755088Sab196087 765088Sab196087 static const Msg vis_alt[] = { 775088Sab196087 MSG_STV_DEFAULT_ALT, MSG_STV_INTERNAL_ALT, 785220Srie MSG_STV_HIDDEN_ALT, MSG_STV_PROTECTED_ALT, 795220Srie MSG_STV_EXPORTED_ALT, MSG_STV_SINGLETON_ALT, 805220Srie MSG_STV_ELIMINATE_ALT 815088Sab196087 }; 825088Sab196087 835088Sab196087 if (value >= (sizeof (vis) / sizeof (vis[0]))) 845088Sab196087 return (conv_invalid_val(inv_buf, value, fmt_flags)); 855088Sab196087 865088Sab196087 /* If full ELF names are desired, use those strings */ 875088Sab196087 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME) 885088Sab196087 return (MSG_ORIG(vis_alt[value])); 895088Sab196087 905088Sab196087 /* Default strings */ 915088Sab196087 return (MSG_ORIG(vis[value])); 925088Sab196087 } 935088Sab196087 945088Sab196087 const char * 955088Sab196087 conv_sym_info_type(Half mach, uchar_t type, Conv_fmt_flags_t fmt_flags, 964734Sab196087 Conv_inv_buf_t *inv_buf) 970Sstevel@tonic-gate { 981618Srie static const Msg types[] = { 995088Sab196087 MSG_STT_NOTYPE, MSG_STT_OBJECT, 1005088Sab196087 MSG_STT_FUNC, MSG_STT_SECTION, 1015088Sab196087 MSG_STT_FILE, MSG_STT_COMMON, 1021618Srie MSG_STT_TLS 1031618Srie }; 1040Sstevel@tonic-gate 1055088Sab196087 static const Msg types_alt[] = { 1065088Sab196087 MSG_STT_NOTYPE_ALT, MSG_STT_OBJECT_ALT, 1075088Sab196087 MSG_STT_FUNC_ALT, MSG_STT_SECTION_ALT, 1085088Sab196087 MSG_STT_FILE_ALT, MSG_STT_COMMON_ALT, 1095088Sab196087 MSG_STT_TLS_ALT 1105088Sab196087 }; 1115088Sab196087 1121976Sab196087 if (type < STT_NUM) { 1135088Sab196087 /* If full ELF names are desired, use those strings */ 1145088Sab196087 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME) 1155088Sab196087 return (MSG_ORIG(types_alt[type])); 1165088Sab196087 1175088Sab196087 /* Default strings */ 1180Sstevel@tonic-gate return (MSG_ORIG(types[type])); 1191976Sab196087 } else if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) || 1201976Sab196087 (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER)) { 1215088Sab196087 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME) 1225088Sab196087 return (MSG_ORIG(MSG_STT_SPARC_REGISTER_ALT)); 1235088Sab196087 1245088Sab196087 return (MSG_ORIG(MSG_STT_SPARC_REGISTER)); 1251976Sab196087 } else { 1264734Sab196087 return (conv_invalid_val(inv_buf, type, fmt_flags)); 1271976Sab196087 } 1280Sstevel@tonic-gate } 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate const char * 1315088Sab196087 conv_sym_info_bind(uchar_t bind, Conv_fmt_flags_t fmt_flags, 1325088Sab196087 Conv_inv_buf_t *inv_buf) 1330Sstevel@tonic-gate { 1341618Srie static const Msg binds[] = { 1351618Srie MSG_STB_LOCAL, MSG_STB_GLOBAL, MSG_STB_WEAK 1361618Srie }; 1370Sstevel@tonic-gate 1385088Sab196087 static const Msg binds_alt[] = { 1395088Sab196087 MSG_STB_LOCAL_ALT, MSG_STB_GLOBAL_ALT, MSG_STB_WEAK_ALT 1405088Sab196087 }; 1415088Sab196087 1420Sstevel@tonic-gate if (bind >= STB_NUM) 1434734Sab196087 return (conv_invalid_val(inv_buf, bind, fmt_flags)); 1445088Sab196087 1455088Sab196087 /* If full ELF names are desired, use those strings */ 1465088Sab196087 if (CONV_TYPE_FMT_ALT(fmt_flags) == CONV_FMT_ALT_FULLNAME) 1475088Sab196087 return (MSG_ORIG(binds_alt[bind])); 1485088Sab196087 1495088Sab196087 /* Default strings */ 1505088Sab196087 return (MSG_ORIG(binds[bind])); 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate const char * 1544734Sab196087 conv_sym_shndx(Half shndx, Conv_inv_buf_t *inv_buf) 1550Sstevel@tonic-gate { 1561618Srie switch (shndx) { 1571618Srie case SHN_UNDEF: 1580Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_UNDEF)); 1591618Srie case SHN_SUNW_IGNORE: 1600Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_SUNW_IGNORE)); 1611618Srie case SHN_ABS: 1620Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_ABS)); 1631618Srie case SHN_COMMON: 1640Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_COMMON)); 1651618Srie case SHN_AMD64_LCOMMON: 1661618Srie return (MSG_ORIG(MSG_SHN_AMD64_LCOMMON)); 1671618Srie case SHN_AFTER: 1680Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_AFTER)); 1691618Srie case SHN_BEFORE: 1700Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_BEFORE)); 1711618Srie case SHN_XINDEX: 1720Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_XINDEX)); 1731618Srie default: 1744734Sab196087 return (conv_invalid_val(inv_buf, shndx, CONV_FMT_DECIMAL)); 1751618Srie } 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate const char * 1794734Sab196087 conv_sym_value(Half mach, uchar_t type, Addr value, Conv_inv_buf_t *inv_buf) 1800Sstevel@tonic-gate { 1810Sstevel@tonic-gate if (((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) || 1820Sstevel@tonic-gate (mach == EM_SPARCV9)) && (type == STT_SPARC_REGISTER)) 1834734Sab196087 return (conv_sym_SPARC_value(value, 0, inv_buf)); 1840Sstevel@tonic-gate 1854734Sab196087 (void) snprintf(inv_buf->buf, sizeof (inv_buf->buf), 1864734Sab196087 MSG_ORIG(MSG_SYM_FMT_VAL), EC_ADDR(value)); 1874734Sab196087 return (inv_buf->buf); 1880Sstevel@tonic-gate } 189