1 /* Return note type name.
2 Copyright (C) 2002, 2007, 2009, 2011, 2016, 2018 Red Hat, Inc.
3 This file is part of elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
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 <system.h>
35
36 #include <inttypes.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <libeblP.h>
40
41
42 const char *
ebl_object_note_type_name(Ebl * ebl,const char * name,uint32_t type,GElf_Word descsz,char * buf,size_t len)43 ebl_object_note_type_name (Ebl *ebl, const char *name, uint32_t type,
44 GElf_Word descsz,
45 char *buf, size_t len)
46 {
47 const char *res = ebl->object_note_type_name (name, type, buf, len);
48
49 if (res == NULL)
50 {
51 if (strcmp (name, "stapsdt") == 0)
52 {
53 snprintf (buf, len, "Version: %" PRIu32, type);
54 return buf;
55 }
56
57 #define ELF_NOTE_GOPKGLIST 1
58 #define ELF_NOTE_GOABIHASH 2
59 #define ELF_NOTE_GODEPS 3
60 #define ELF_NOTE_GOBUILDID 4
61
62 static const char *goknowntypes[] =
63 {
64 #define KNOWNSTYPE(name) [ELF_NOTE_GO##name] = #name
65 KNOWNSTYPE (PKGLIST),
66 KNOWNSTYPE (ABIHASH),
67 KNOWNSTYPE (DEPS),
68 KNOWNSTYPE (BUILDID),
69 #undef KNOWNSTYPE
70 };
71
72 if (strcmp (name, "Go") == 0)
73 {
74 if (type < sizeof (goknowntypes) / sizeof (goknowntypes[0])
75 && goknowntypes[type] != NULL)
76 return goknowntypes[type];
77 else
78 {
79 snprintf (buf, len, "%s: %" PRIu32, _("<unknown>"), type);
80 return buf;
81 }
82 }
83
84 if (startswith (name, ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX))
85 {
86 /* GNU Build Attribute notes (ab)use the owner name to store
87 most of their data. Don't decode everything here. Just
88 the type.*/
89 char *t = buf;
90 const char *gba = "GNU Build Attribute";
91 int w = snprintf (t, len, "%s ", gba);
92 t += w;
93 len -= w;
94 if (type == NT_GNU_BUILD_ATTRIBUTE_OPEN)
95 snprintf (t, len, "OPEN");
96 else if (type == NT_GNU_BUILD_ATTRIBUTE_FUNC)
97 snprintf (t, len, "FUNC");
98 else
99 snprintf (t, len, "%x", type);
100
101 return buf;
102 }
103
104 if (strcmp (name, "FDO") == 0 && type == NT_FDO_PACKAGING_METADATA)
105 return "FDO_PACKAGING_METADATA";
106
107 if (strcmp (name, "GNU") != 0)
108 {
109 /* NT_VERSION is special, all data is in the name. */
110 if (descsz == 0 && type == NT_VERSION)
111 return "VERSION";
112
113 snprintf (buf, len, "%s: %" PRIu32, _("<unknown>"), type);
114 return buf;
115 }
116
117 /* And finally all the "GNU" note types. */
118 static const char *knowntypes[] =
119 {
120 #define KNOWNSTYPE(name) [NT_##name] = #name
121 KNOWNSTYPE (GNU_ABI_TAG),
122 KNOWNSTYPE (GNU_HWCAP),
123 KNOWNSTYPE (GNU_BUILD_ID),
124 KNOWNSTYPE (GNU_GOLD_VERSION),
125 KNOWNSTYPE (GNU_PROPERTY_TYPE_0),
126 };
127
128 /* Handle standard names. */
129 if (type < sizeof (knowntypes) / sizeof (knowntypes[0])
130 && knowntypes[type] != NULL)
131 res = knowntypes[type];
132 else
133 {
134 snprintf (buf, len, "%s: %" PRIu32, _("<unknown>"), type);
135
136 res = buf;
137 }
138 }
139
140 return res;
141 }
142