blob: 5dc1ec6d32fa6228abbbc4e295e0fd33236c802d [file] [log] [blame]
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00001/* Return section type name.
Roland McGrath059c83e2008-02-21 06:19:39 +00002 Copyright (C) 2001, 2002, 2006, 2008 Red Hat, Inc.
Mark Wielaardde2ed972012-06-05 17:15:16 +02003 This file is part of elfutils.
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00004 Written by Ulrich Drepper <drepper@redhat.com>, 2001.
5
Mark Wielaardde2ed972012-06-05 17:15:16 +02006 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
Ulrich Drepperb08d5a82005-07-26 05:00:05 +00008
Mark Wielaardde2ed972012-06-05 17:15:16 +02009 * 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
Ulrich Drepper361df7d2006-04-04 21:38:57 +000022 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
Mark Wielaardde2ed972012-06-05 17:15:16 +020026 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/>. */
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000029
30#ifdef HAVE_CONFIG_H
31# include <config.h>
32#endif
33
34#include <stdio.h>
35#include <libeblP.h>
36
37
38const char *
Mark Wielaard1ccdfb62015-09-22 22:27:01 +020039ebl_section_type_name (Ebl *ebl, int section, char *buf, size_t len)
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000040{
41 const char *res = ebl->section_type_name (section, buf, len);
42
43 if (res == NULL)
44 {
45 static const char *knowntypes[] =
46 {
47#define KNOWNSTYPE(name) [SHT_##name] = #name
48 KNOWNSTYPE (NULL),
49 KNOWNSTYPE (PROGBITS),
50 KNOWNSTYPE (SYMTAB),
51 KNOWNSTYPE (STRTAB),
52 KNOWNSTYPE (RELA),
53 KNOWNSTYPE (HASH),
54 KNOWNSTYPE (DYNAMIC),
55 KNOWNSTYPE (NOTE),
56 KNOWNSTYPE (NOBITS),
57 KNOWNSTYPE (REL),
58 KNOWNSTYPE (SHLIB),
59 KNOWNSTYPE (DYNSYM),
60 KNOWNSTYPE (INIT_ARRAY),
61 KNOWNSTYPE (FINI_ARRAY),
62 KNOWNSTYPE (PREINIT_ARRAY),
63 KNOWNSTYPE (GROUP),
64 KNOWNSTYPE (SYMTAB_SHNDX)
65 };
66
67 /* Handle standard names. */
68 if ((size_t) section < sizeof (knowntypes) / sizeof (knowntypes[0])
69 && knowntypes[section] != NULL)
70 res = knowntypes[section];
71 /* The symbol versioning/Sun extensions. */
72 else if (section >= SHT_LOSUNW && section <= SHT_HISUNW)
73 {
74 static const char *sunwtypes[] =
75 {
76#undef KNOWNSTYPE
77#define KNOWNSTYPE(name) [SHT_##name - SHT_LOSUNW] = #name
78 KNOWNSTYPE (SUNW_move),
79 KNOWNSTYPE (SUNW_COMDAT),
80 KNOWNSTYPE (SUNW_syminfo),
81 KNOWNSTYPE (GNU_verdef),
82 KNOWNSTYPE (GNU_verneed),
83 KNOWNSTYPE (GNU_versym)
84 };
85 res = sunwtypes[section - SHT_LOSUNW];
86 }
87 else
Roland McGrath059c83e2008-02-21 06:19:39 +000088 /* A few GNU additions. */
89 switch (section)
90 {
91 case SHT_CHECKSUM:
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000092 res = "CHECKSUM";
Roland McGrath059c83e2008-02-21 06:19:39 +000093 break;
94 case SHT_GNU_LIBLIST:
Ulrich Drepperb08d5a82005-07-26 05:00:05 +000095 res = "GNU_LIBLIST";
Roland McGrath059c83e2008-02-21 06:19:39 +000096 break;
97 case SHT_GNU_HASH:
Ulrich Drepper28ed8952006-07-07 03:43:47 +000098 res = "GNU_HASH";
Roland McGrath059c83e2008-02-21 06:19:39 +000099 break;
100 case SHT_GNU_ATTRIBUTES:
101 res = "GNU_ATTRIBUTES";
102 break;
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000103
Roland McGrath059c83e2008-02-21 06:19:39 +0000104 default:
105 /* Handle OS-specific section names. */
106 if (section >= SHT_LOOS && section <= SHT_HIOS)
107 snprintf (buf, len, "SHT_LOOS+%x", section - SHT_LOOS);
108 /* Handle processor-specific section names. */
109 else if (section >= SHT_LOPROC && section <= SHT_HIPROC)
110 snprintf (buf, len, "SHT_LOPROC+%x", section - SHT_LOPROC);
111 else if ((unsigned int) section >= SHT_LOUSER
112 && (unsigned int) section <= SHT_HIUSER)
113 snprintf (buf, len, "SHT_LOUSER+%x", section - SHT_LOUSER);
114 else
115 snprintf (buf, len, "%s: %d", gettext ("<unknown>"), section);
116
117 res = buf;
118 break;
119 }
Ulrich Drepperb08d5a82005-07-26 05:00:05 +0000120 }
121
122 return res;
123}