1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gate /* 29*0Sstevel@tonic-gate * String conversion routines for section attributes. 30*0Sstevel@tonic-gate */ 31*0Sstevel@tonic-gate #include <string.h> 32*0Sstevel@tonic-gate #include <sys/param.h> 33*0Sstevel@tonic-gate #include <sys/elf_SPARC.h> 34*0Sstevel@tonic-gate #include <sys/elf_amd64.h> 35*0Sstevel@tonic-gate #include <_conv.h> 36*0Sstevel@tonic-gate #include <sections_msg.h> 37*0Sstevel@tonic-gate 38*0Sstevel@tonic-gate static const Msg secs[SHT_NUM] = { 39*0Sstevel@tonic-gate MSG_SHT_NULL, MSG_SHT_PROGBITS, MSG_SHT_SYMTAB, 40*0Sstevel@tonic-gate MSG_SHT_STRTAB, MSG_SHT_RELA, MSG_SHT_HASH, 41*0Sstevel@tonic-gate MSG_SHT_DYNAMIC, MSG_SHT_NOTE, MSG_SHT_NOBITS, 42*0Sstevel@tonic-gate MSG_SHT_REL, MSG_SHT_SHLIB, MSG_SHT_DYNSYM, 43*0Sstevel@tonic-gate MSG_SHT_UNKNOWN12, MSG_SHT_UNKNOWN13, MSG_SHT_INIT_ARRAY, 44*0Sstevel@tonic-gate MSG_SHT_FINI_ARRAY, MSG_SHT_PREINIT_ARRAY, MSG_SHT_GROUP, 45*0Sstevel@tonic-gate MSG_SHT_SYMTAB_SHNDX 46*0Sstevel@tonic-gate }; 47*0Sstevel@tonic-gate #if (SHT_NUM != (SHT_SYMTAB_SHNDX + 1)) 48*0Sstevel@tonic-gate #error "SHT_NUM has grown" 49*0Sstevel@tonic-gate #endif 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate static const Msg usecs[SHT_HISUNW - SHT_LOSUNW + 1] = { 52*0Sstevel@tonic-gate MSG_SHT_SUNW_dof, MSG_SHT_SUNW_cap, MSG_SHT_SUNW_SIGNATURE, 53*0Sstevel@tonic-gate MSG_SHT_SUNW_ANNOTATE, MSG_SHT_SUNW_DEBUGSTR, MSG_SHT_SUNW_DEBUG, 54*0Sstevel@tonic-gate MSG_SHT_SUNW_move, MSG_SHT_SUNW_COMDAT, MSG_SHT_SUNW_syminfo, 55*0Sstevel@tonic-gate MSG_SHT_SUNW_verdef, MSG_SHT_SUNW_verneed, MSG_SHT_SUNW_versym 56*0Sstevel@tonic-gate }; 57*0Sstevel@tonic-gate #if (SHT_LOSUNW != SHT_SUNW_dof) 58*0Sstevel@tonic-gate #error "SHT_LOSUNW has moved" 59*0Sstevel@tonic-gate #endif 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gate const char * 62*0Sstevel@tonic-gate /* ARGSUSED 1 */ 63*0Sstevel@tonic-gate conv_sectyp_str(ushort_t mach, uint_t sec) 64*0Sstevel@tonic-gate { 65*0Sstevel@tonic-gate static char string[STRSIZE] = { '\0' }; 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate if (sec < SHT_NUM) 68*0Sstevel@tonic-gate return (MSG_ORIG(secs[sec])); 69*0Sstevel@tonic-gate else if ((sec >= SHT_LOSUNW) && (sec <= SHT_HISUNW)) 70*0Sstevel@tonic-gate return (MSG_ORIG(usecs[sec - SHT_LOSUNW])); 71*0Sstevel@tonic-gate else if ((sec >= SHT_LOPROC) && (sec <= SHT_HIPROC)) { 72*0Sstevel@tonic-gate if ((sec == (uint_t)SHT_SPARC_GOTDATA) && 73*0Sstevel@tonic-gate ((mach == EM_SPARC) || (mach == EM_SPARC32PLUS) || 74*0Sstevel@tonic-gate (mach == EM_SPARCV9))) 75*0Sstevel@tonic-gate return (MSG_ORIG(MSG_SHT_SPARC_GOTDATA)); 76*0Sstevel@tonic-gate else if ((sec == (uint_t)SHT_AMD64_UNWIND) && 77*0Sstevel@tonic-gate (mach == EM_AMD64)) 78*0Sstevel@tonic-gate return (MSG_ORIG(MSG_SHT_AMD64_UNWIND)); 79*0Sstevel@tonic-gate else 80*0Sstevel@tonic-gate return (conv_invalid_str(string, STRSIZE, sec, 0)); 81*0Sstevel@tonic-gate } else 82*0Sstevel@tonic-gate return (conv_invalid_str(string, STRSIZE, sec, 0)); 83*0Sstevel@tonic-gate } 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate #define FLAGSZ MSG_GBL_OSQBRKT_SIZE + \ 86*0Sstevel@tonic-gate MSG_SHF_WRITE_SIZE + \ 87*0Sstevel@tonic-gate MSG_SHF_ALLOC_SIZE + \ 88*0Sstevel@tonic-gate MSG_SHF_EXECINSTR_SIZE + \ 89*0Sstevel@tonic-gate MSG_SHF_MERGE_SIZE + \ 90*0Sstevel@tonic-gate MSG_SHF_STRINGS_SIZE + \ 91*0Sstevel@tonic-gate MSG_SHF_INFO_LINK_SIZE + \ 92*0Sstevel@tonic-gate MSG_SHF_LINK_ORDER_SIZE + \ 93*0Sstevel@tonic-gate MSG_SHF_OS_NONCONFORMING_SIZE + \ 94*0Sstevel@tonic-gate MSG_SHF_GROUP_SIZE + \ 95*0Sstevel@tonic-gate MSG_SHF_TLS_SIZE + \ 96*0Sstevel@tonic-gate MSG_SHF_EXCLUDE_SIZE + \ 97*0Sstevel@tonic-gate MSG_SHF_ORDERED_SIZE + \ 98*0Sstevel@tonic-gate MSG_GBL_CSQBRKT_SIZE 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate const char * 101*0Sstevel@tonic-gate /* ARGSUSED 1 */ 102*0Sstevel@tonic-gate conv_secflg_str(ushort_t mach, uint_t flags) 103*0Sstevel@tonic-gate { 104*0Sstevel@tonic-gate static char string[FLAGSZ] = { '\0' }; 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate if (flags == 0) 107*0Sstevel@tonic-gate return (MSG_ORIG(MSG_GBL_ZERO)); 108*0Sstevel@tonic-gate else { 109*0Sstevel@tonic-gate uint_t flags_handled = 0; 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate (void) strcpy(string, MSG_ORIG(MSG_GBL_OSQBRKT)); 112*0Sstevel@tonic-gate if (flags & SHF_WRITE) { 113*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_WRITE)); 114*0Sstevel@tonic-gate flags_handled |= SHF_WRITE; 115*0Sstevel@tonic-gate } 116*0Sstevel@tonic-gate if (flags & SHF_ALLOC) { 117*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_ALLOC)); 118*0Sstevel@tonic-gate flags_handled |= SHF_ALLOC; 119*0Sstevel@tonic-gate } 120*0Sstevel@tonic-gate if (flags & SHF_EXECINSTR) { 121*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_EXECINSTR)); 122*0Sstevel@tonic-gate flags_handled |= SHF_EXECINSTR; 123*0Sstevel@tonic-gate } 124*0Sstevel@tonic-gate if (flags & SHF_MERGE) { 125*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_MERGE)); 126*0Sstevel@tonic-gate flags_handled |= SHF_MERGE; 127*0Sstevel@tonic-gate } 128*0Sstevel@tonic-gate if (flags & SHF_STRINGS) { 129*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_STRINGS)); 130*0Sstevel@tonic-gate flags_handled |= SHF_STRINGS; 131*0Sstevel@tonic-gate } 132*0Sstevel@tonic-gate if (flags & SHF_INFO_LINK) { 133*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_INFO_LINK)); 134*0Sstevel@tonic-gate flags_handled |= SHF_INFO_LINK; 135*0Sstevel@tonic-gate } 136*0Sstevel@tonic-gate if (flags & SHF_LINK_ORDER) { 137*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_LINK_ORDER)); 138*0Sstevel@tonic-gate flags_handled |= SHF_LINK_ORDER; 139*0Sstevel@tonic-gate } 140*0Sstevel@tonic-gate if (flags & SHF_OS_NONCONFORMING) { 141*0Sstevel@tonic-gate (void) strcat(string, 142*0Sstevel@tonic-gate MSG_ORIG(MSG_SHF_OS_NONCONFORMING)); 143*0Sstevel@tonic-gate flags_handled |= SHF_OS_NONCONFORMING; 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate if (flags & SHF_GROUP) { 146*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_GROUP)); 147*0Sstevel@tonic-gate flags_handled |= SHF_GROUP; 148*0Sstevel@tonic-gate } 149*0Sstevel@tonic-gate if (flags & SHF_TLS) { 150*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_TLS)); 151*0Sstevel@tonic-gate flags_handled |= SHF_TLS; 152*0Sstevel@tonic-gate } 153*0Sstevel@tonic-gate if (flags & SHF_EXCLUDE) { 154*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_EXCLUDE)); 155*0Sstevel@tonic-gate flags_handled |= SHF_EXCLUDE; 156*0Sstevel@tonic-gate } 157*0Sstevel@tonic-gate if (flags & SHF_ORDERED) { 158*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_SHF_ORDERED)); 159*0Sstevel@tonic-gate flags_handled |= SHF_ORDERED; 160*0Sstevel@tonic-gate } 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate /* 163*0Sstevel@tonic-gate * Are there any flags that haven't been handled. 164*0Sstevel@tonic-gate */ 165*0Sstevel@tonic-gate if ((flags & flags_handled) != flags) { 166*0Sstevel@tonic-gate char *str; 167*0Sstevel@tonic-gate size_t len; 168*0Sstevel@tonic-gate 169*0Sstevel@tonic-gate len = strlen(string); 170*0Sstevel@tonic-gate str = string + len; 171*0Sstevel@tonic-gate (void) conv_invalid_str(str, FLAGSZ - len, 172*0Sstevel@tonic-gate (flags & (~flags_handled)), 0); 173*0Sstevel@tonic-gate } 174*0Sstevel@tonic-gate (void) strcat(string, MSG_ORIG(MSG_GBL_CSQBRKT)); 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate return ((const char *)string); 177*0Sstevel@tonic-gate } 178*0Sstevel@tonic-gate } 179*0Sstevel@tonic-gate 180*0Sstevel@tonic-gate /* 181*0Sstevel@tonic-gate * Need to be able to hold a 32bit signed integer. 182*0Sstevel@tonic-gate */ 183*0Sstevel@tonic-gate #define INFOSZ 128 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate const char * 186*0Sstevel@tonic-gate conv_secinfo_str(uint_t info, uint_t flags) 187*0Sstevel@tonic-gate { 188*0Sstevel@tonic-gate static char string[INFOSZ] = { '\0' }; 189*0Sstevel@tonic-gate 190*0Sstevel@tonic-gate if (flags & SHF_ORDERED) { 191*0Sstevel@tonic-gate if (info == SHN_BEFORE) 192*0Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_BEFORE)); 193*0Sstevel@tonic-gate else if (info == SHN_AFTER) 194*0Sstevel@tonic-gate return (MSG_ORIG(MSG_SHN_AFTER)); 195*0Sstevel@tonic-gate } 196*0Sstevel@tonic-gate (void) conv_invalid_str(string, INFOSZ, info, 1); 197*0Sstevel@tonic-gate return ((const char *)string); 198*0Sstevel@tonic-gate } 199