1 /* Print contents of object file note.
2 Copyright (C) 2002, 2007, 2009, 2011, 2015, 2016 Red Hat, Inc.
3 This file is part of elfutils.
4 Written by Ulrich Drepper <drepper@redhat.com>, 2002.
6 This file is free software; you can redistribute it and/or modify
7 it under the terms of either
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
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
19 or both in parallel, as here.
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.
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/>. */
42 ebl_object_note (Ebl *ebl, const char *name, uint32_t type,
43 uint32_t descsz, const char *desc)
45 if (! ebl->object_note (name, type, descsz, desc))
47 /* The machine specific function did not know this type. */
49 if (strcmp ("stapsdt", name) == 0)
53 printf (gettext ("unknown SDT version %u\n"), type);
57 /* Descriptor starts with three addresses, pc, base ref and
58 semaphore. Then three zero terminated strings provider,
59 name and arguments. */
67 size_t addrs_size = gelf_fsize (ebl->elf, ELF_T_ADDR, 3, EV_CURRENT);
68 if (descsz < addrs_size + 3)
71 printf (gettext ("invalid SDT probe descriptor\n"));
77 .d_type = ELF_T_ADDR, .d_version = EV_CURRENT,
78 .d_buf = (void *) desc, .d_size = addrs_size
83 .d_type = ELF_T_ADDR, .d_version = EV_CURRENT,
84 .d_buf = &addrs, .d_size = addrs_size
87 if (gelf_xlatetom (ebl->elf, &dst, &src,
88 elf_getident (ebl->elf, NULL)[EI_DATA]) == NULL)
90 printf ("%s\n", elf_errmsg (-1));
94 const char *provider = desc + addrs_size;
95 const char *pname = memchr (provider, '\0', desc + descsz - provider);
100 const char *args = memchr (pname, '\0', desc + descsz - pname);
102 memchr (++args, '\0', desc + descsz - pname) != desc + descsz - 1)
108 if (gelf_getclass (ebl->elf) == ELFCLASS32)
121 printf (gettext (" PC: "));
122 printf ("%#" PRIx64 ",", pc);
123 printf (gettext (" Base: "));
124 printf ("%#" PRIx64 ",", base);
125 printf (gettext (" Semaphore: "));
126 printf ("%#" PRIx64 "\n", sem);
127 printf (gettext (" Provider: "));
128 printf ("%s,", provider);
129 printf (gettext (" Name: "));
130 printf ("%s,", pname);
131 printf (gettext (" Args: "));
132 printf ("'%s'\n", args);
138 case NT_GNU_BUILD_ID:
139 if (strcmp (name, "GNU") == 0 && descsz > 0)
141 printf (gettext (" Build ID: "));
143 for (i = 0; i < descsz - 1; ++i)
144 printf ("%02" PRIx8, (uint8_t) desc[i]);
145 printf ("%02" PRIx8 "\n", (uint8_t) desc[i]);
149 case NT_GNU_GOLD_VERSION:
150 if (strcmp (name, "GNU") == 0 && descsz > 0)
151 /* A non-null terminated version string. */
152 printf (gettext (" Linker version: %.*s\n"),
157 if (strcmp (name, "GNU") == 0 && descsz >= 8 && descsz % 4 == 0)
161 .d_version = EV_CURRENT,
162 .d_type = ELF_T_WORD,
164 .d_buf = (void *) desc
166 /* Normally NT_GNU_ABI_TAG is just 4 words (16 bytes). If it
167 is much (4*) larger dynamically allocate memory to convert. */
168 #define FIXED_TAG_BYTES 16
169 uint32_t sbuf[FIXED_TAG_BYTES];
171 if (unlikely (descsz / 4 > FIXED_TAG_BYTES))
173 buf = malloc (descsz);
174 if (unlikely (buf == NULL))
181 .d_version = EV_CURRENT,
182 .d_type = ELF_T_WORD,
187 if (elf32_xlatetom (&out, &in, ebl->data) != NULL)
192 case ELF_NOTE_OS_LINUX:
196 case ELF_NOTE_OS_GNU:
200 case ELF_NOTE_OS_SOLARIS2:
204 case ELF_NOTE_OS_FREEBSD:
213 printf (gettext (" OS: %s, ABI: "), os);
214 for (size_t cnt = 1; cnt < descsz / 4; ++cnt)
217 putchar_unlocked ('.');
218 printf ("%" PRIu32, buf[cnt]);
220 putchar_unlocked ('\n');
222 if (descsz / 4 > FIXED_TAG_BYTES)