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 */ 21685Srie 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 section attributes. 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate #include <string.h> 320Sstevel@tonic-gate #include <sys/param.h> 330Sstevel@tonic-gate #include <sys/elf_SPARC.h> 340Sstevel@tonic-gate #include <sys/elf_amd64.h> 350Sstevel@tonic-gate #include <_conv.h> 360Sstevel@tonic-gate #include <sections_msg.h> 370Sstevel@tonic-gate 381976Sab196087 391976Sab196087 401976Sab196087 /* Instantiate a local copy of conv_map2str() from _conv.h */ 411976Sab196087 DEFINE_conv_map2str 421976Sab196087 431976Sab196087 441976Sab196087 450Sstevel@tonic-gate static const Msg secs[SHT_NUM] = { 460Sstevel@tonic-gate MSG_SHT_NULL, MSG_SHT_PROGBITS, MSG_SHT_SYMTAB, 470Sstevel@tonic-gate MSG_SHT_STRTAB, MSG_SHT_RELA, MSG_SHT_HASH, 480Sstevel@tonic-gate MSG_SHT_DYNAMIC, MSG_SHT_NOTE, MSG_SHT_NOBITS, 490Sstevel@tonic-gate MSG_SHT_REL, MSG_SHT_SHLIB, MSG_SHT_DYNSYM, 500Sstevel@tonic-gate MSG_SHT_UNKNOWN12, MSG_SHT_UNKNOWN13, MSG_SHT_INIT_ARRAY, 510Sstevel@tonic-gate MSG_SHT_FINI_ARRAY, MSG_SHT_PREINIT_ARRAY, MSG_SHT_GROUP, 520Sstevel@tonic-gate MSG_SHT_SYMTAB_SHNDX 530Sstevel@tonic-gate }; 541976Sab196087 static const Msg secs_alt[SHT_NUM] = { 551976Sab196087 MSG_SHT_NULL_ALT, MSG_SHT_PROGBITS_ALT, MSG_SHT_SYMTAB_ALT, 561976Sab196087 MSG_SHT_STRTAB_ALT, MSG_SHT_RELA_ALT, MSG_SHT_HASH_ALT, 571976Sab196087 MSG_SHT_DYNAMIC_ALT, MSG_SHT_NOTE_ALT, MSG_SHT_NOBITS_ALT, 581976Sab196087 MSG_SHT_REL_ALT, MSG_SHT_SHLIB_ALT, MSG_SHT_DYNSYM_ALT, 591976Sab196087 MSG_SHT_UNKNOWN12, MSG_SHT_UNKNOWN13, MSG_SHT_INIT_ARRAY_ALT, 601976Sab196087 MSG_SHT_FINI_ARRAY_ALT, MSG_SHT_PREINIT_ARRAY_ALT, MSG_SHT_GROUP_ALT, 611976Sab196087 MSG_SHT_SYMTAB_SHNDX_ALT 621976Sab196087 }; 630Sstevel@tonic-gate #if (SHT_NUM != (SHT_SYMTAB_SHNDX + 1)) 640Sstevel@tonic-gate #error "SHT_NUM has grown" 650Sstevel@tonic-gate #endif 660Sstevel@tonic-gate 670Sstevel@tonic-gate static const Msg usecs[SHT_HISUNW - SHT_LOSUNW + 1] = { 682766Sab196087 MSG_SHT_SUNW_LDYNSYM, MSG_SHT_SUNW_dof, 692766Sab196087 MSG_SHT_SUNW_cap, MSG_SHT_SUNW_SIGNATURE, 702766Sab196087 MSG_SHT_SUNW_ANNOTATE, MSG_SHT_SUNW_DEBUGSTR, 712766Sab196087 MSG_SHT_SUNW_DEBUG, MSG_SHT_SUNW_move, 722766Sab196087 MSG_SHT_SUNW_COMDAT, MSG_SHT_SUNW_syminfo, 732766Sab196087 MSG_SHT_SUNW_verdef, MSG_SHT_SUNW_verneed, 742766Sab196087 MSG_SHT_SUNW_versym 751976Sab196087 }; 761976Sab196087 static const Msg usecs_alt[SHT_HISUNW - SHT_LOSUNW + 1] = { 772766Sab196087 MSG_SHT_SUNW_LDYNSYM_ALT, MSG_SHT_SUNW_dof_ALT, 782766Sab196087 MSG_SHT_SUNW_cap_ALT, MSG_SHT_SUNW_SIGNATURE_ALT, 792766Sab196087 MSG_SHT_SUNW_ANNOTATE_ALT, MSG_SHT_SUNW_DEBUGSTR_ALT, 802766Sab196087 MSG_SHT_SUNW_DEBUG_ALT, MSG_SHT_SUNW_move_ALT, 812766Sab196087 MSG_SHT_SUNW_COMDAT_ALT, MSG_SHT_SUNW_syminfo_ALT, 822766Sab196087 MSG_SHT_SUNW_verdef_ALT, MSG_SHT_SUNW_verneed_ALT, 832766Sab196087 MSG_SHT_SUNW_versym_ALT 840Sstevel@tonic-gate }; 852766Sab196087 #if (SHT_LOSUNW != SHT_SUNW_LDYNSYM) 860Sstevel@tonic-gate #error "SHT_LOSUNW has moved" 870Sstevel@tonic-gate #endif 880Sstevel@tonic-gate 891976Sab196087 900Sstevel@tonic-gate const char * 911976Sab196087 conv_sec_type(Half mach, Word sec, int fmt_flags) 920Sstevel@tonic-gate { 93*2850Srie static Conv_inv_buf_t string; 940Sstevel@tonic-gate 951976Sab196087 if (sec < SHT_NUM) { 961976Sab196087 return (conv_map2str(string, sizeof (string), sec, fmt_flags, 971976Sab196087 ARRAY_NELTS(secs), secs, secs_alt, NULL)); 981976Sab196087 } else if ((sec >= SHT_LOSUNW) && (sec <= SHT_HISUNW)) { 991976Sab196087 return (conv_map2str(string, sizeof (string), sec - SHT_LOSUNW, 1001976Sab196087 fmt_flags, ARRAY_NELTS(usecs), usecs, usecs_alt, NULL)); 1011976Sab196087 } else if ((sec >= SHT_LOPROC) && (sec <= SHT_HIPROC)) { 1021976Sab196087 switch (mach) { 1031976Sab196087 case EM_SPARC: 1041976Sab196087 case EM_SPARC32PLUS: 1051976Sab196087 case EM_SPARCV9: 1061976Sab196087 if (sec == SHT_SPARC_GOTDATA) { 1071976Sab196087 return (fmt_flags & CONV_FMT_ALTDUMP) 1081976Sab196087 ? MSG_ORIG(MSG_SHT_SPARC_GOTDATA_ALT) 1091976Sab196087 : MSG_ORIG(MSG_SHT_SPARC_GOTDATA); 1101976Sab196087 } 1111976Sab196087 break; 1121976Sab196087 case EM_AMD64: 1131976Sab196087 if (sec == SHT_AMD64_UNWIND) { 1141976Sab196087 return (fmt_flags & CONV_FMT_ALTDUMP) 1151976Sab196087 ? MSG_ORIG(MSG_SHT_AMD64_UNWIND_ALT) 1161976Sab196087 : MSG_ORIG(MSG_SHT_AMD64_UNWIND); 1171976Sab196087 } 1181976Sab196087 } 1191976Sab196087 } 1201976Sab196087 1211976Sab196087 /* If we get here, it's an unknown type */ 1221976Sab196087 return (conv_invalid_val(string, CONV_INV_STRSIZE, sec, fmt_flags)); 1230Sstevel@tonic-gate } 1240Sstevel@tonic-gate 1252352Sab196087 #define FLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 1262352Sab196087 MSG_SHF_WRITE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1272352Sab196087 MSG_SHF_ALLOC_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1282352Sab196087 MSG_SHF_EXECINSTR_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1292352Sab196087 MSG_SHF_MERGE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1302352Sab196087 MSG_SHF_STRINGS_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1312352Sab196087 MSG_SHF_INFO_LINK_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1322352Sab196087 MSG_SHF_LINK_ORDER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1332352Sab196087 MSG_SHF_OS_NONCONFORMING_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1342352Sab196087 MSG_SHF_GROUP_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1352352Sab196087 MSG_SHF_TLS_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1362352Sab196087 MSG_SHF_EXCLUDE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1372352Sab196087 MSG_SHF_ORDERED_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1382352Sab196087 MSG_SHF_AMD64_LARGE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1392352Sab196087 CONV_INV_STRSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate const char * 1421618Srie conv_sec_flags(Xword flags) 1430Sstevel@tonic-gate { 1441618Srie static char string[FLAGSZ]; 1451618Srie static Val_desc vda[] = { 1461618Srie { SHF_WRITE, MSG_ORIG(MSG_SHF_WRITE) }, 1471618Srie { SHF_ALLOC, MSG_ORIG(MSG_SHF_ALLOC) }, 1481618Srie { SHF_EXECINSTR, MSG_ORIG(MSG_SHF_EXECINSTR) }, 1491618Srie { SHF_MERGE, MSG_ORIG(MSG_SHF_MERGE) }, 1501618Srie { SHF_STRINGS, MSG_ORIG(MSG_SHF_STRINGS) }, 1511618Srie { SHF_INFO_LINK, MSG_ORIG(MSG_SHF_INFO_LINK) }, 1521618Srie { SHF_LINK_ORDER, MSG_ORIG(MSG_SHF_LINK_ORDER) }, 1531618Srie { SHF_OS_NONCONFORMING, MSG_ORIG(MSG_SHF_OS_NONCONFORMING) }, 1541618Srie { SHF_GROUP, MSG_ORIG(MSG_SHF_GROUP) }, 1551618Srie { SHF_TLS, MSG_ORIG(MSG_SHF_TLS) }, 1561618Srie { SHF_EXCLUDE, MSG_ORIG(MSG_SHF_EXCLUDE) }, 1571618Srie { SHF_ORDERED, MSG_ORIG(MSG_SHF_ORDERED) }, 1581618Srie { SHF_AMD64_LARGE, MSG_ORIG(MSG_SHF_AMD64_LARGE) }, 1591618Srie { 0, 0 } 1601618Srie }; 1612352Sab196087 static CONV_EXPN_FIELD_ARG conv_arg = { string, sizeof (string), vda }; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate if (flags == 0) 1640Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 1650Sstevel@tonic-gate 1662352Sab196087 conv_arg.oflags = conv_arg.rflags = flags; 1672352Sab196087 (void) conv_expn_field(&conv_arg); 1680Sstevel@tonic-gate 1691618Srie return ((const char *)string); 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate 172*2850Srie /* 173*2850Srie * conv_sec_linkinfo() is one of the few conversion routines that can be called 174*2850Srie * twice for the same diagnostic (see liblddbg:Elf_Shdr()), hence the caller 175*2850Srie * has to supply different string buffers. 176*2850Srie */ 1770Sstevel@tonic-gate const char * 178*2850Srie conv_sec_linkinfo(Word info, Xword flags, Conv_inv_buf_t buffer) 1790Sstevel@tonic-gate { 1802647Srie if (flags & ALL_SHF_ORDER) { 1810Sstevel@tonic-gate if (info == SHN_BEFORE) 1820Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_BEFORE)); 1830Sstevel@tonic-gate else if (info == SHN_AFTER) 1840Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_AFTER)); 1850Sstevel@tonic-gate } 186*2850Srie (void) conv_invalid_val(buffer, CONV_INV_STRSIZE, info, 1); 187*2850Srie return ((const char *)buffer); 1880Sstevel@tonic-gate } 189