diff options
author | Khem Raj <raj.khem@gmail.com> | 2023-12-10 12:25:46 -0800 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-12-13 11:34:27 +0000 |
commit | 52ec79a6d305c6053acb3b9a761d1645ee5d502f (patch) | |
tree | 8ff5e0eabb9a5071a05e58b4facafbbe36418b19 /meta/recipes-devtools | |
parent | b8bbd1ca93115f2b1ceef63ff46bc66320c7e281 (diff) | |
download | poky-52ec79a6d305c6053acb3b9a761d1645ee5d502f.tar.gz |
elfutils: Use own basename API implementation
This helps in building it for musl libc after this change [1]
[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7
(From OE-Core rev: ce0a4084fcb1f5da2c3210f681534cc4c4485589)
Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/recipes-devtools')
-rw-r--r-- | meta/recipes-devtools/elfutils/elfutils_0.189.bb | 1 | ||||
-rw-r--r-- | meta/recipes-devtools/elfutils/files/0001-Add-helper-function-for-basename.patch | 404 |
2 files changed, 405 insertions, 0 deletions
diff --git a/meta/recipes-devtools/elfutils/elfutils_0.189.bb b/meta/recipes-devtools/elfutils/elfutils_0.189.bb index d69828131e..220f747cb9 100644 --- a/meta/recipes-devtools/elfutils/elfutils_0.189.bb +++ b/meta/recipes-devtools/elfutils/elfutils_0.189.bb | |||
@@ -21,6 +21,7 @@ SRC_URI = "https://sourceware.org/elfutils/ftp/${PV}/${BP}.tar.bz2 \ | |||
21 | file://0001-skip-the-test-when-gcc-not-deployed.patch \ | 21 | file://0001-skip-the-test-when-gcc-not-deployed.patch \ |
22 | file://ptest.patch \ | 22 | file://ptest.patch \ |
23 | file://0001-tests-Makefile.am-compile-test_nlist-with-standard-C.patch \ | 23 | file://0001-tests-Makefile.am-compile-test_nlist-with-standard-C.patch \ |
24 | file://0001-Add-helper-function-for-basename.patch \ | ||
24 | " | 25 | " |
25 | SRC_URI:append:libc-musl = " \ | 26 | SRC_URI:append:libc-musl = " \ |
26 | file://0003-musl-utils.patch \ | 27 | file://0003-musl-utils.patch \ |
diff --git a/meta/recipes-devtools/elfutils/files/0001-Add-helper-function-for-basename.patch b/meta/recipes-devtools/elfutils/files/0001-Add-helper-function-for-basename.patch new file mode 100644 index 0000000000..3e6033fd75 --- /dev/null +++ b/meta/recipes-devtools/elfutils/files/0001-Add-helper-function-for-basename.patch | |||
@@ -0,0 +1,404 @@ | |||
1 | From 666372a5d8d5a23203c70d583904097c9e49c5a0 Mon Sep 17 00:00:00 2001 | ||
2 | From: Khem Raj <raj.khem@gmail.com> | ||
3 | Date: Sat, 9 Dec 2023 18:23:03 -0800 | ||
4 | Subject: [PATCH] Add helper function for basename | ||
5 | |||
6 | musl does not provide GNU version of basename and lately have removed | ||
7 | the definiton from string.h [1] which exposes this problem. It can be | ||
8 | made to work by providing a local implementation of basename which | ||
9 | implements the GNU basename behavior, this makes it work across C | ||
10 | libraries which have POSIX implementation only. | ||
11 | |||
12 | Upstream-Status: Submitted [https://sourceware.org/pipermail/elfutils-devel/2023q4/006727.html] | ||
13 | [1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7 | ||
14 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
15 | --- | ||
16 | lib/Makefile.am | 2 +- | ||
17 | lib/libeu.h | 1 + | ||
18 | lib/{libeu.h => xbasename.c} | 31 ++++++++++------------------ | ||
19 | libdw/dwarf_getsrc_file.c | 3 ++- | ||
20 | libdwfl/core-file.c | 3 ++- | ||
21 | libdwfl/dwfl_module_getsrc_file.c | 3 ++- | ||
22 | libdwfl/dwfl_segment_report_module.c | 3 ++- | ||
23 | libdwfl/find-debuginfo.c | 7 ++++--- | ||
24 | libdwfl/link_map.c | 3 ++- | ||
25 | libdwfl/linux-kernel-modules.c | 3 ++- | ||
26 | src/addr2line.c | 5 +++-- | ||
27 | src/ar.c | 5 +++-- | ||
28 | src/nm.c | 4 ++-- | ||
29 | src/stack.c | 3 ++- | ||
30 | src/strip.c | 2 +- | ||
31 | tests/show-die-info.c | 2 +- | ||
32 | tests/varlocs.c | 2 +- | ||
33 | 17 files changed, 42 insertions(+), 40 deletions(-) | ||
34 | copy lib/{libeu.h => xbasename.c} (57%) | ||
35 | |||
36 | --- a/lib/Makefile.am | ||
37 | +++ b/lib/Makefile.am | ||
38 | @@ -33,7 +33,7 @@ AM_CPPFLAGS += -I$(srcdir)/../libelf | ||
39 | |||
40 | noinst_LIBRARIES = libeu.a | ||
41 | |||
42 | -libeu_a_SOURCES = xasprintf.c xstrdup.c xstrndup.c xmalloc.c next_prime.c \ | ||
43 | +libeu_a_SOURCES = xasprintf.c xbasename.c xstrdup.c xstrndup.c xmalloc.c next_prime.c \ | ||
44 | crc32.c crc32_file.c \ | ||
45 | color.c error.c printversion.c | ||
46 | |||
47 | --- a/lib/libeu.h | ||
48 | +++ b/lib/libeu.h | ||
49 | @@ -42,6 +42,7 @@ extern char *xstrndup (const char *, siz | ||
50 | extern char *xasprintf(const char *fmt, ...) | ||
51 | __attribute__ ((format (printf, 1, 2))) __attribute__ ((__malloc__)); | ||
52 | |||
53 | +extern const char *xbasename(const char *s); | ||
54 | extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len); | ||
55 | extern int crc32_file (int fd, uint32_t *resp); | ||
56 | |||
57 | --- /dev/null | ||
58 | +++ b/lib/xbasename.c | ||
59 | @@ -0,0 +1,39 @@ | ||
60 | +/* Convenience function for basename extraction. | ||
61 | + Copyright (C) 2023 Khem Raj. | ||
62 | + This file is part of elfutils. | ||
63 | + | ||
64 | + This file is free software; you can redistribute it and/or modify | ||
65 | + it under the terms of either | ||
66 | + | ||
67 | + * the GNU Lesser General Public License as published by the Free | ||
68 | + Software Foundation; either version 3 of the License, or (at | ||
69 | + your option) any later version | ||
70 | + | ||
71 | + or | ||
72 | + | ||
73 | + * the GNU General Public License as published by the Free | ||
74 | + Software Foundation; either version 2 of the License, or (at | ||
75 | + your option) any later version | ||
76 | + | ||
77 | + or both in parallel, as here. | ||
78 | + | ||
79 | + elfutils is distributed in the hope that it will be useful, but | ||
80 | + WITHOUT ANY WARRANTY; without even the implied warranty of | ||
81 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
82 | + General Public License for more details. | ||
83 | + | ||
84 | + You should have received copies of the GNU General Public License and | ||
85 | + the GNU Lesser General Public License along with this program. If | ||
86 | + not, see <http://www.gnu.org/licenses/>. */ | ||
87 | + | ||
88 | +#ifdef HAVE_CONFIG_H | ||
89 | +# include <config.h> | ||
90 | +#endif | ||
91 | + | ||
92 | +#include <string.h> | ||
93 | + | ||
94 | +const char * | ||
95 | +xbasename(const char *s) { | ||
96 | + const char *p = strrchr(s, '/'); | ||
97 | + return p ? p+1 : s; | ||
98 | +} | ||
99 | --- a/libdw/dwarf_getsrc_file.c | ||
100 | +++ b/libdw/dwarf_getsrc_file.c | ||
101 | @@ -37,6 +37,7 @@ | ||
102 | #include <string.h> | ||
103 | |||
104 | #include "libdwP.h" | ||
105 | +#include "libeu.h" | ||
106 | |||
107 | |||
108 | int | ||
109 | @@ -98,7 +99,7 @@ dwarf_getsrc_file (Dwarf *dbg, const cha | ||
110 | /* Match the name with the name the user provided. */ | ||
111 | const char *fname2 = line->files->info[lastfile].name; | ||
112 | if (is_basename) | ||
113 | - lastmatch = strcmp (basename (fname2), fname) == 0; | ||
114 | + lastmatch = strcmp (xbasename (fname2), fname) == 0; | ||
115 | else | ||
116 | lastmatch = strcmp (fname2, fname) == 0; | ||
117 | } | ||
118 | --- a/libdwfl/core-file.c | ||
119 | +++ b/libdwfl/core-file.c | ||
120 | @@ -29,6 +29,7 @@ | ||
121 | |||
122 | #include <config.h> | ||
123 | #include "libelfP.h" /* For NOTE_ALIGN. */ | ||
124 | +#include "libeu.h" | ||
125 | #include "libdwflP.h" | ||
126 | #include <gelf.h> | ||
127 | |||
128 | @@ -595,7 +596,7 @@ dwfl_core_file_report (Dwfl *dwfl, Elf * | ||
129 | if (! __libdwfl_dynamic_vaddr_get (module->elf, &file_dynamic_vaddr)) | ||
130 | continue; | ||
131 | Dwfl_Module *mod; | ||
132 | - mod = __libdwfl_report_elf (dwfl, basename (module->name), module->name, | ||
133 | + mod = __libdwfl_report_elf (dwfl, xbasename (module->name), module->name, | ||
134 | module->fd, module->elf, | ||
135 | module->l_ld - file_dynamic_vaddr, | ||
136 | true, true); | ||
137 | --- a/libdwfl/dwfl_module_getsrc_file.c | ||
138 | +++ b/libdwfl/dwfl_module_getsrc_file.c | ||
139 | @@ -31,6 +31,7 @@ | ||
140 | #endif | ||
141 | |||
142 | #include "libdwflP.h" | ||
143 | +#include "libeu.h" | ||
144 | #include "libdwP.h" | ||
145 | |||
146 | |||
147 | @@ -103,7 +104,7 @@ dwfl_module_getsrc_file (Dwfl_Module *mo | ||
148 | { | ||
149 | /* Match the name with the name the user provided. */ | ||
150 | lastfile = file; | ||
151 | - lastmatch = !strcmp (is_basename ? basename (file) : file, | ||
152 | + lastmatch = !strcmp (is_basename ? xbasename (file) : file, | ||
153 | fname); | ||
154 | } | ||
155 | } | ||
156 | --- a/libdwfl/dwfl_segment_report_module.c | ||
157 | +++ b/libdwfl/dwfl_segment_report_module.c | ||
158 | @@ -29,6 +29,7 @@ | ||
159 | |||
160 | #include <config.h> | ||
161 | #include "libelfP.h" /* For NOTE_ALIGN4 and NOTE_ALIGN8. */ | ||
162 | +#include "libeu.h" | ||
163 | #include "libdwflP.h" | ||
164 | #include "common.h" | ||
165 | |||
166 | @@ -718,7 +719,7 @@ dwfl_segment_report_module (Dwfl *dwfl, | ||
167 | bias += fixup; | ||
168 | if (module->name[0] != '\0') | ||
169 | { | ||
170 | - name = basename (module->name); | ||
171 | + name = xbasename (module->name); | ||
172 | name_is_final = true; | ||
173 | } | ||
174 | break; | ||
175 | --- a/libdwfl/find-debuginfo.c | ||
176 | +++ b/libdwfl/find-debuginfo.c | ||
177 | @@ -31,6 +31,7 @@ | ||
178 | #endif | ||
179 | |||
180 | #include "libdwflP.h" | ||
181 | +#include "libeu.h" | ||
182 | #include <stdio.h> | ||
183 | #include <fcntl.h> | ||
184 | #include <sys/stat.h> | ||
185 | @@ -164,7 +165,7 @@ find_debuginfo_in_path (Dwfl_Module *mod | ||
186 | { | ||
187 | bool cancheck = debuglink_crc != (GElf_Word) 0; | ||
188 | |||
189 | - const char *file_basename = file_name == NULL ? NULL : basename (file_name); | ||
190 | + const char *file_basename = file_name == NULL ? NULL : xbasename (file_name); | ||
191 | char *localname = NULL; | ||
192 | |||
193 | /* We invent a debuglink .debug name if NULL, but then want to try the | ||
194 | @@ -278,7 +279,7 @@ find_debuginfo_in_path (Dwfl_Module *mod | ||
195 | else | ||
196 | { | ||
197 | subdir = NULL; | ||
198 | - file = basename (debuglink_file); | ||
199 | + file = xbasename (debuglink_file); | ||
200 | } | ||
201 | try_file_basename = debuglink_null; | ||
202 | break; | ||
203 | @@ -306,7 +307,7 @@ find_debuginfo_in_path (Dwfl_Module *mod | ||
204 | if (mod->dw != NULL && (p[0] == '\0' || p[0] == '/')) | ||
205 | { | ||
206 | fd = try_open (&main_stat, dir, ".dwz", | ||
207 | - basename (file), &fname); | ||
208 | + xbasename (file), &fname); | ||
209 | if (fd < 0) | ||
210 | { | ||
211 | if (errno != ENOENT && errno != ENOTDIR) | ||
212 | --- a/libdwfl/link_map.c | ||
213 | +++ b/libdwfl/link_map.c | ||
214 | @@ -29,6 +29,7 @@ | ||
215 | |||
216 | #include <config.h> | ||
217 | #include "libdwflP.h" | ||
218 | +#include "libeu.h" | ||
219 | #include "memory-access.h" | ||
220 | #include "system.h" | ||
221 | |||
222 | @@ -469,7 +470,7 @@ report_r_debug (uint_fast8_t elfclass, u | ||
223 | if (r_debug_info_module == NULL) | ||
224 | { | ||
225 | // XXX hook for sysroot | ||
226 | - mod = __libdwfl_report_elf (dwfl, basename (name), | ||
227 | + mod = __libdwfl_report_elf (dwfl, xbasename (name), | ||
228 | name, fd, elf, base, | ||
229 | true, true); | ||
230 | if (mod != NULL) | ||
231 | --- a/libdwfl/linux-kernel-modules.c | ||
232 | +++ b/libdwfl/linux-kernel-modules.c | ||
233 | @@ -40,6 +40,7 @@ | ||
234 | #include <system.h> | ||
235 | |||
236 | #include "libelfP.h" | ||
237 | +#include "libeu.h" | ||
238 | #include "libdwflP.h" | ||
239 | #include <inttypes.h> | ||
240 | #include <errno.h> | ||
241 | @@ -116,7 +117,7 @@ try_kernel_name (Dwfl *dwfl, char **fnam | ||
242 | /* Try the file's unadorned basename as DEBUGLINK_FILE, | ||
243 | to look only for "vmlinux" files. */ | ||
244 | fd = INTUSE(dwfl_standard_find_debuginfo) (&fakemod, NULL, NULL, 0, | ||
245 | - *fname, basename (*fname), | ||
246 | + *fname, xbasename (*fname), | ||
247 | 0, &fakemod.debug.name); | ||
248 | |||
249 | if (fakemod.debug.name != NULL) | ||
250 | --- a/src/addr2line.c | ||
251 | +++ b/src/addr2line.c | ||
252 | @@ -38,6 +38,7 @@ | ||
253 | |||
254 | #include <system.h> | ||
255 | #include <printversion.h> | ||
256 | +#include "libeu.h" | ||
257 | |||
258 | |||
259 | /* Name and version of program. */ | ||
260 | @@ -385,7 +386,7 @@ print_dwarf_function (Dwfl_Module *mod, | ||
261 | if (file == NULL) | ||
262 | file = "???"; | ||
263 | else if (only_basenames) | ||
264 | - file = basename (file); | ||
265 | + file = xbasename (file); | ||
266 | else if (use_comp_dir && file[0] != '/') | ||
267 | { | ||
268 | const char *const *dirs; | ||
269 | @@ -568,7 +569,7 @@ print_src (const char *src, int lineno, | ||
270 | const char *comp_dir_sep = ""; | ||
271 | |||
272 | if (only_basenames) | ||
273 | - src = basename (src); | ||
274 | + src = xbasename (src); | ||
275 | else if (use_comp_dir && src[0] != '/') | ||
276 | { | ||
277 | Dwarf_Attribute attr; | ||
278 | --- a/src/ar.c | ||
279 | +++ b/src/ar.c | ||
280 | @@ -42,6 +42,7 @@ | ||
281 | #include <printversion.h> | ||
282 | |||
283 | #include "arlib.h" | ||
284 | +#include "libeu.h" | ||
285 | |||
286 | |||
287 | /* Name and version of program. */ | ||
288 | @@ -1133,7 +1134,7 @@ do_oper_insert (int oper, const char *ar | ||
289 | for (int cnt = 0; cnt < argc; ++cnt) | ||
290 | { | ||
291 | ENTRY entry; | ||
292 | - entry.key = full_path ? argv[cnt] : basename (argv[cnt]); | ||
293 | + entry.key = full_path ? argv[cnt] : (char*)xbasename (argv[cnt]); | ||
294 | entry.data = &argv[cnt]; | ||
295 | if (hsearch (entry, ENTER) == NULL) | ||
296 | error_exit (errno, _("cannot insert into hash table")); | ||
297 | @@ -1242,7 +1243,7 @@ do_oper_insert (int oper, const char *ar | ||
298 | /* Open all the new files, get their sizes and add all symbols. */ | ||
299 | for (int cnt = 0; cnt < argc; ++cnt) | ||
300 | { | ||
301 | - const char *bname = basename (argv[cnt]); | ||
302 | + const char *bname = xbasename (argv[cnt]); | ||
303 | size_t bnamelen = strlen (bname); | ||
304 | if (found[cnt] == NULL) | ||
305 | { | ||
306 | --- a/src/nm.c | ||
307 | +++ b/src/nm.c | ||
308 | @@ -1417,7 +1417,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehd | ||
309 | int lineno; | ||
310 | (void) dwarf_lineno (line, &lineno); | ||
311 | const char *file = dwarf_linesrc (line, NULL, NULL); | ||
312 | - file = (file != NULL) ? basename (file) : "???"; | ||
313 | + file = (file != NULL) ? xbasename (file) : "???"; | ||
314 | int n; | ||
315 | n = obstack_printf (&whereob, "%s:%d%c", file, | ||
316 | lineno, '\0'); | ||
317 | @@ -1448,7 +1448,7 @@ show_symbols (int fd, Ebl *ebl, GElf_Ehd | ||
318 | { | ||
319 | /* We found the line. */ | ||
320 | int n = obstack_printf (&whereob, "%s:%" PRIu64 "%c", | ||
321 | - basename ((*found)->file), | ||
322 | + xbasename ((*found)->file), | ||
323 | (*found)->lineno, | ||
324 | '\0'); | ||
325 | sym_mem[nentries_used].where = obstack_finish (&whereob); | ||
326 | --- a/src/stack.c | ||
327 | +++ b/src/stack.c | ||
328 | @@ -31,6 +31,7 @@ | ||
329 | #include <system.h> | ||
330 | #include <printversion.h> | ||
331 | |||
332 | +#include "libeu.h" | ||
333 | /* Name and version of program. */ | ||
334 | ARGP_PROGRAM_VERSION_HOOK_DEF = print_version; | ||
335 | |||
336 | @@ -152,7 +153,7 @@ module_callback (Dwfl_Module *mod, void | ||
337 | |||
338 | int width = get_addr_width (mod); | ||
339 | printf ("0x%0*" PRIx64 "-0x%0*" PRIx64 " %s\n", | ||
340 | - width, start, width, end, basename (name)); | ||
341 | + width, start, width, end, xbasename (name)); | ||
342 | |||
343 | const unsigned char *id; | ||
344 | GElf_Addr id_vaddr; | ||
345 | --- a/src/strip.c | ||
346 | +++ b/src/strip.c | ||
347 | @@ -1807,7 +1807,7 @@ handle_elf (int fd, Elf *elf, const char | ||
348 | elf_errmsg (-1)); | ||
349 | } | ||
350 | |||
351 | - char *debug_basename = basename (debug_fname_embed ?: debug_fname); | ||
352 | + const char *debug_basename = xbasename (debug_fname_embed ?: debug_fname); | ||
353 | off_t crc_offset = strlen (debug_basename) + 1; | ||
354 | /* Align to 4 byte boundary */ | ||
355 | crc_offset = ((crc_offset - 1) & ~3) + 4; | ||
356 | --- a/tests/show-die-info.c | ||
357 | +++ b/tests/show-die-info.c | ||
358 | @@ -26,6 +26,7 @@ | ||
359 | #include <string.h> | ||
360 | #include <unistd.h> | ||
361 | |||
362 | +#include "../lib/libeu.h" | ||
363 | #include "../libdw/known-dwarf.h" | ||
364 | |||
365 | static const char * | ||
366 | @@ -318,7 +319,7 @@ main (int argc, char *argv[]) | ||
367 | int fd = open (argv[cnt], O_RDONLY); | ||
368 | Dwarf *dbg; | ||
369 | |||
370 | - printf ("file: %s\n", basename (argv[cnt])); | ||
371 | + printf ("file: %s\n", xbasename (argv[cnt])); | ||
372 | |||
373 | dbg = dwarf_begin (fd, DWARF_C_READ); | ||
374 | if (dbg == NULL) | ||
375 | --- a/tests/varlocs.c | ||
376 | +++ b/tests/varlocs.c | ||
377 | @@ -33,6 +33,7 @@ | ||
378 | |||
379 | #include "system.h" | ||
380 | #include "../libdw/known-dwarf.h" | ||
381 | +#include "../lib/libeu.h" | ||
382 | |||
383 | // The Dwarf, Dwarf_CFIs and address bias of | ||
384 | // cfi table to adjust DWARF addresses against. | ||
385 | @@ -1120,7 +1121,7 @@ main (int argc, char *argv[]) | ||
386 | |||
387 | const char *name = (modname[0] != '\0' | ||
388 | ? modname | ||
389 | - : basename (mainfile)); | ||
390 | + : xbasename (mainfile)); | ||
391 | printf ("module '%s'\n", name); | ||
392 | print_die (&cudie, "CU", 0); | ||
393 | |||
394 | --- a/tests/Makefile.am | ||
395 | +++ b/tests/Makefile.am | ||
396 | @@ -692,7 +692,7 @@ update1_LDADD = $(libelf) | ||
397 | update2_LDADD = $(libelf) | ||
398 | update3_LDADD = $(libdw) $(libelf) | ||
399 | update4_LDADD = $(libdw) $(libelf) | ||
400 | -show_die_info_LDADD = $(libdw) $(libelf) | ||
401 | +show_die_info_LDADD = $(libeu) $(libdw) $(libelf) | ||
402 | get_pubnames_LDADD = $(libdw) $(libelf) | ||
403 | show_abbrev_LDADD = $(libdw) $(libelf) | ||
404 | get_lines_LDADD = $(libdw) $(libelf) | ||