1 /* Return section type name. 2 Copyright (C) 2001, 2002, 2006, 2008 Red Hat, Inc. 3 This file is part of elfutils. 4 Written by Ulrich Drepper <drepper (at) redhat.com>, 2001. 5 6 This file is free software; you can redistribute it and/or modify 7 it under the terms of either 8 9 * the GNU Lesser General Public License as published by the Free 10 Software Foundation; either version 3 of the License, or (at 11 your option) any later version 12 13 or 14 15 * the GNU General Public License as published by the Free 16 Software Foundation; either version 2 of the License, or (at 17 your option) any later version 18 19 or both in parallel, as here. 20 21 elfutils is distributed in the hope that it will be useful, but 22 WITHOUT ANY WARRANTY; without even the implied warranty of 23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 24 General Public License for more details. 25 26 You should have received copies of the GNU General Public License and 27 the GNU Lesser General Public License along with this program. If 28 not, see <http://www.gnu.org/licenses/>. */ 29 30 #ifdef HAVE_CONFIG_H 31 # include <config.h> 32 #endif 33 34 #include <stdio.h> 35 #include <libeblP.h> 36 37 38 const char * 39 ebl_section_type_name (ebl, section, buf, len) 40 Ebl *ebl; 41 int section; 42 char *buf; 43 size_t len; 44 { 45 const char *res = ebl->section_type_name (section, buf, len); 46 47 if (res == NULL) 48 { 49 static const char *knowntypes[] = 50 { 51 #define KNOWNSTYPE(name) [SHT_##name] = #name 52 KNOWNSTYPE (NULL), 53 KNOWNSTYPE (PROGBITS), 54 KNOWNSTYPE (SYMTAB), 55 KNOWNSTYPE (STRTAB), 56 KNOWNSTYPE (RELA), 57 KNOWNSTYPE (HASH), 58 KNOWNSTYPE (DYNAMIC), 59 KNOWNSTYPE (NOTE), 60 KNOWNSTYPE (NOBITS), 61 KNOWNSTYPE (REL), 62 KNOWNSTYPE (SHLIB), 63 KNOWNSTYPE (DYNSYM), 64 KNOWNSTYPE (INIT_ARRAY), 65 KNOWNSTYPE (FINI_ARRAY), 66 KNOWNSTYPE (PREINIT_ARRAY), 67 KNOWNSTYPE (GROUP), 68 KNOWNSTYPE (SYMTAB_SHNDX) 69 }; 70 71 /* Handle standard names. */ 72 if ((size_t) section < sizeof (knowntypes) / sizeof (knowntypes[0]) 73 && knowntypes[section] != NULL) 74 res = knowntypes[section]; 75 /* The symbol versioning/Sun extensions. */ 76 else if (section >= SHT_LOSUNW && section <= SHT_HISUNW) 77 { 78 static const char *sunwtypes[] = 79 { 80 #undef KNOWNSTYPE 81 #define KNOWNSTYPE(name) [SHT_##name - SHT_LOSUNW] = #name 82 KNOWNSTYPE (SUNW_move), 83 KNOWNSTYPE (SUNW_COMDAT), 84 KNOWNSTYPE (SUNW_syminfo), 85 KNOWNSTYPE (GNU_verdef), 86 KNOWNSTYPE (GNU_verneed), 87 KNOWNSTYPE (GNU_versym) 88 }; 89 res = sunwtypes[section - SHT_LOSUNW]; 90 } 91 else 92 /* A few GNU additions. */ 93 switch (section) 94 { 95 case SHT_CHECKSUM: 96 res = "CHECKSUM"; 97 break; 98 case SHT_GNU_LIBLIST: 99 res = "GNU_LIBLIST"; 100 break; 101 case SHT_GNU_HASH: 102 res = "GNU_HASH"; 103 break; 104 case SHT_GNU_ATTRIBUTES: 105 res = "GNU_ATTRIBUTES"; 106 break; 107 108 default: 109 /* Handle OS-specific section names. */ 110 if (section >= SHT_LOOS && section <= SHT_HIOS) 111 snprintf (buf, len, "SHT_LOOS+%x", section - SHT_LOOS); 112 /* Handle processor-specific section names. */ 113 else if (section >= SHT_LOPROC && section <= SHT_HIPROC) 114 snprintf (buf, len, "SHT_LOPROC+%x", section - SHT_LOPROC); 115 else if ((unsigned int) section >= SHT_LOUSER 116 && (unsigned int) section <= SHT_HIUSER) 117 snprintf (buf, len, "SHT_LOUSER+%x", section - SHT_LOUSER); 118 else 119 snprintf (buf, len, "%s: %d", gettext ("<unknown>"), section); 120 121 res = buf; 122 break; 123 } 124 } 125 126 return res; 127 } 128