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] = { 681976Sab196087 MSG_SHT_SUNW_dof, MSG_SHT_SUNW_cap, 691976Sab196087 MSG_SHT_SUNW_SIGNATURE, MSG_SHT_SUNW_ANNOTATE, 701976Sab196087 MSG_SHT_SUNW_DEBUGSTR, MSG_SHT_SUNW_DEBUG, 711976Sab196087 MSG_SHT_SUNW_move, MSG_SHT_SUNW_COMDAT, 721976Sab196087 MSG_SHT_SUNW_syminfo, MSG_SHT_SUNW_verdef, 731976Sab196087 MSG_SHT_SUNW_verneed, MSG_SHT_SUNW_versym 741976Sab196087 }; 751976Sab196087 static const Msg usecs_alt[SHT_HISUNW - SHT_LOSUNW + 1] = { 761976Sab196087 MSG_SHT_SUNW_dof_ALT, MSG_SHT_SUNW_cap_ALT, 771976Sab196087 MSG_SHT_SUNW_SIGNATURE_ALT, MSG_SHT_SUNW_ANNOTATE_ALT, 781976Sab196087 MSG_SHT_SUNW_DEBUGSTR_ALT, MSG_SHT_SUNW_DEBUG_ALT, 791976Sab196087 MSG_SHT_SUNW_move_ALT, MSG_SHT_SUNW_COMDAT_ALT, 801976Sab196087 MSG_SHT_SUNW_syminfo_ALT, MSG_SHT_SUNW_verdef_ALT, 811976Sab196087 MSG_SHT_SUNW_verneed_ALT, MSG_SHT_SUNW_versym_ALT 820Sstevel@tonic-gate }; 830Sstevel@tonic-gate #if (SHT_LOSUNW != SHT_SUNW_dof) 840Sstevel@tonic-gate #error "SHT_LOSUNW has moved" 850Sstevel@tonic-gate #endif 860Sstevel@tonic-gate 871976Sab196087 880Sstevel@tonic-gate const char * 891976Sab196087 conv_sec_type(Half mach, Word sec, int fmt_flags) 900Sstevel@tonic-gate { 911618Srie static char string[CONV_INV_STRSIZE]; 920Sstevel@tonic-gate 931976Sab196087 if (sec < SHT_NUM) { 941976Sab196087 return (conv_map2str(string, sizeof (string), sec, fmt_flags, 951976Sab196087 ARRAY_NELTS(secs), secs, secs_alt, NULL)); 961976Sab196087 } else if ((sec >= SHT_LOSUNW) && (sec <= SHT_HISUNW)) { 971976Sab196087 return (conv_map2str(string, sizeof (string), sec - SHT_LOSUNW, 981976Sab196087 fmt_flags, ARRAY_NELTS(usecs), usecs, usecs_alt, NULL)); 991976Sab196087 } else if ((sec >= SHT_LOPROC) && (sec <= SHT_HIPROC)) { 1001976Sab196087 switch (mach) { 1011976Sab196087 case EM_SPARC: 1021976Sab196087 case EM_SPARC32PLUS: 1031976Sab196087 case EM_SPARCV9: 1041976Sab196087 if (sec == SHT_SPARC_GOTDATA) { 1051976Sab196087 return (fmt_flags & CONV_FMT_ALTDUMP) 1061976Sab196087 ? MSG_ORIG(MSG_SHT_SPARC_GOTDATA_ALT) 1071976Sab196087 : MSG_ORIG(MSG_SHT_SPARC_GOTDATA); 1081976Sab196087 } 1091976Sab196087 break; 1101976Sab196087 case EM_AMD64: 1111976Sab196087 if (sec == SHT_AMD64_UNWIND) { 1121976Sab196087 return (fmt_flags & CONV_FMT_ALTDUMP) 1131976Sab196087 ? MSG_ORIG(MSG_SHT_AMD64_UNWIND_ALT) 1141976Sab196087 : MSG_ORIG(MSG_SHT_AMD64_UNWIND); 1151976Sab196087 } 1161976Sab196087 } 1171976Sab196087 } 1181976Sab196087 1191976Sab196087 /* If we get here, it's an unknown type */ 1201976Sab196087 return (conv_invalid_val(string, CONV_INV_STRSIZE, sec, fmt_flags)); 1210Sstevel@tonic-gate } 1220Sstevel@tonic-gate 1232352Sab196087 #define FLAGSZ CONV_EXPN_FIELD_DEF_PREFIX_SIZE + \ 1242352Sab196087 MSG_SHF_WRITE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1252352Sab196087 MSG_SHF_ALLOC_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1262352Sab196087 MSG_SHF_EXECINSTR_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1272352Sab196087 MSG_SHF_MERGE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1282352Sab196087 MSG_SHF_STRINGS_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1292352Sab196087 MSG_SHF_INFO_LINK_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1302352Sab196087 MSG_SHF_LINK_ORDER_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1312352Sab196087 MSG_SHF_OS_NONCONFORMING_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1322352Sab196087 MSG_SHF_GROUP_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1332352Sab196087 MSG_SHF_TLS_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1342352Sab196087 MSG_SHF_EXCLUDE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1352352Sab196087 MSG_SHF_ORDERED_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1362352Sab196087 MSG_SHF_AMD64_LARGE_SIZE + CONV_EXPN_FIELD_DEF_SEP_SIZE + \ 1372352Sab196087 CONV_INV_STRSIZE + CONV_EXPN_FIELD_DEF_SUFFIX_SIZE 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate const char * 1401618Srie conv_sec_flags(Xword flags) 1410Sstevel@tonic-gate { 1421618Srie static char string[FLAGSZ]; 1431618Srie static Val_desc vda[] = { 1441618Srie { SHF_WRITE, MSG_ORIG(MSG_SHF_WRITE) }, 1451618Srie { SHF_ALLOC, MSG_ORIG(MSG_SHF_ALLOC) }, 1461618Srie { SHF_EXECINSTR, MSG_ORIG(MSG_SHF_EXECINSTR) }, 1471618Srie { SHF_MERGE, MSG_ORIG(MSG_SHF_MERGE) }, 1481618Srie { SHF_STRINGS, MSG_ORIG(MSG_SHF_STRINGS) }, 1491618Srie { SHF_INFO_LINK, MSG_ORIG(MSG_SHF_INFO_LINK) }, 1501618Srie { SHF_LINK_ORDER, MSG_ORIG(MSG_SHF_LINK_ORDER) }, 1511618Srie { SHF_OS_NONCONFORMING, MSG_ORIG(MSG_SHF_OS_NONCONFORMING) }, 1521618Srie { SHF_GROUP, MSG_ORIG(MSG_SHF_GROUP) }, 1531618Srie { SHF_TLS, MSG_ORIG(MSG_SHF_TLS) }, 1541618Srie { SHF_EXCLUDE, MSG_ORIG(MSG_SHF_EXCLUDE) }, 1551618Srie { SHF_ORDERED, MSG_ORIG(MSG_SHF_ORDERED) }, 1561618Srie { SHF_AMD64_LARGE, MSG_ORIG(MSG_SHF_AMD64_LARGE) }, 1571618Srie { 0, 0 } 1581618Srie }; 1592352Sab196087 static CONV_EXPN_FIELD_ARG conv_arg = { string, sizeof (string), vda }; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate if (flags == 0) 1620Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 1630Sstevel@tonic-gate 1642352Sab196087 conv_arg.oflags = conv_arg.rflags = flags; 1652352Sab196087 (void) conv_expn_field(&conv_arg); 1660Sstevel@tonic-gate 1671618Srie return ((const char *)string); 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate const char * 171*2647Srie conv_sec_linkinfo(Word info, Xword flags) 1720Sstevel@tonic-gate { 1731618Srie static char string[CONV_INV_STRSIZE]; 1740Sstevel@tonic-gate 175*2647Srie if (flags & ALL_SHF_ORDER) { 1760Sstevel@tonic-gate if (info == SHN_BEFORE) 1770Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_BEFORE)); 1780Sstevel@tonic-gate else if (info == SHN_AFTER) 1790Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_AFTER)); 1800Sstevel@tonic-gate } 1811618Srie (void) conv_invalid_val(string, CONV_INV_STRSIZE, info, 1); 1820Sstevel@tonic-gate return ((const char *)string); 1830Sstevel@tonic-gate } 184