diff options
author | Alexander Kanavin <alexander.kanavin@linux.intel.com> | 2017-11-10 17:38:59 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-01-02 17:24:36 +0000 |
commit | 0d5475a3b28d9e2c9273967a03726bb6c427bd11 (patch) | |
tree | 9c9149b6987b0aeb9786511256e7fe5de0448624 | |
parent | b09bad9de0e2c848dea1592f06d6a30d194ec575 (diff) | |
download | poky-0d5475a3b28d9e2c9273967a03726bb6c427bd11.tar.gz |
package.bbclass: replace rpm/debugedit with dwarfsrcfiles
Debugedit provided by rpm 4.14 is rewriting binaries in-place, and was
found to produce broken output at least for grub:
http://lists.openembedded.org/pipermail/openembedded-core/2017-November/143989.html
A replacement utility was suggested via private mail:
https://lists.fedorahosted.org/archives/list/elfutils-devel@lists.fedorahosted.org/message/VZP4G5N2ELYZEDAB3QYLXYHDGX4WMCUF/
(From OE-Core rev: f2e6e1d3bfd4c92ef0f5ed4721fd9050c59dafca)
Signed-off-by: Alexander Kanavin <alexander.kanavin@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/package.bbclass | 29 | ||||
-rw-r--r-- | meta/recipes-devtools/dwarfsrcfiles/dwarfsrcfiles.bb | 22 | ||||
-rw-r--r-- | meta/recipes-devtools/dwarfsrcfiles/files/dwarfsrcfiles.c | 111 |
3 files changed, 156 insertions, 6 deletions
diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass index 2053d46395..7dc759699f 100644 --- a/meta/classes/package.bbclass +++ b/meta/classes/package.bbclass | |||
@@ -52,7 +52,8 @@ LOCALE_SECTION ?= '' | |||
52 | ALL_MULTILIB_PACKAGE_ARCHS = "${@all_multilib_tune_values(d, 'PACKAGE_ARCHS')}" | 52 | ALL_MULTILIB_PACKAGE_ARCHS = "${@all_multilib_tune_values(d, 'PACKAGE_ARCHS')}" |
53 | 53 | ||
54 | # rpm is used for the per-file dependency identification | 54 | # rpm is used for the per-file dependency identification |
55 | PACKAGE_DEPENDS += "rpm-native" | 55 | # dwarfsrcfiles is used to determine the list of debug source files |
56 | PACKAGE_DEPENDS += "rpm-native dwarfsrcfiles-native" | ||
56 | 57 | ||
57 | 58 | ||
58 | # If your postinstall can execute at rootfs creation time rather than on | 59 | # If your postinstall can execute at rootfs creation time rather than on |
@@ -334,6 +335,16 @@ def checkbuildpath(file, d): | |||
334 | 335 | ||
335 | return False | 336 | return False |
336 | 337 | ||
338 | def parse_debugsources_from_dwarfsrcfiles_output(dwarfsrcfiles_output): | ||
339 | debugfiles = {} | ||
340 | |||
341 | for line in dwarfsrcfiles_output.splitlines(): | ||
342 | if line.startswith("\t"): | ||
343 | debugfiles[os.path.normpath(line.split()[0])] = "" | ||
344 | |||
345 | return debugfiles.keys() | ||
346 | |||
347 | |||
337 | def splitdebuginfo(file, debugfile, debugsrcdir, sourcefile, d): | 348 | def splitdebuginfo(file, debugfile, debugsrcdir, sourcefile, d): |
338 | # Function to split a single file into two components, one is the stripped | 349 | # Function to split a single file into two components, one is the stripped |
339 | # target system binary, the other contains any debugging information. The | 350 | # target system binary, the other contains any debugging information. The |
@@ -345,7 +356,6 @@ def splitdebuginfo(file, debugfile, debugsrcdir, sourcefile, d): | |||
345 | 356 | ||
346 | dvar = d.getVar('PKGD') | 357 | dvar = d.getVar('PKGD') |
347 | objcopy = d.getVar("OBJCOPY") | 358 | objcopy = d.getVar("OBJCOPY") |
348 | debugedit = d.expand("${STAGING_LIBDIR_NATIVE}/rpm/debugedit") | ||
349 | 359 | ||
350 | # We ignore kernel modules, we don't generate debug info files. | 360 | # We ignore kernel modules, we don't generate debug info files. |
351 | if file.find("/lib/modules/") != -1 and file.endswith(".ko"): | 361 | if file.find("/lib/modules/") != -1 and file.endswith(".ko"): |
@@ -359,10 +369,18 @@ def splitdebuginfo(file, debugfile, debugsrcdir, sourcefile, d): | |||
359 | 369 | ||
360 | # We need to extract the debug src information here... | 370 | # We need to extract the debug src information here... |
361 | if debugsrcdir: | 371 | if debugsrcdir: |
362 | cmd = "'%s' -i -l '%s' '%s'" % (debugedit, sourcefile, file) | 372 | cmd = "'dwarfsrcfiles' '%s'" % (file) |
363 | (retval, output) = oe.utils.getstatusoutput(cmd) | 373 | (retval, output) = oe.utils.getstatusoutput(cmd) |
364 | if retval: | 374 | # 255 means a specific file wasn't fully parsed to get the debug file list, which is not a fatal failure |
365 | bb.fatal("debugedit failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else "")) | 375 | if retval != 0 and retval != 255: |
376 | bb.fatal("dwarfsrcfiles failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else "")) | ||
377 | |||
378 | debugsources = parse_debugsources_from_dwarfsrcfiles_output(output) | ||
379 | # filenames are null-separated - this is an artefact of the previous use | ||
380 | # of rpm's debugedit, which was writing them out that way, and the code elsewhere | ||
381 | # is still assuming that. | ||
382 | debuglistoutput = '\0'.join(debugsources) + '\0' | ||
383 | open(sourcefile, 'a').write(debuglistoutput) | ||
366 | 384 | ||
367 | bb.utils.mkdirhier(os.path.dirname(debugfile)) | 385 | bb.utils.mkdirhier(os.path.dirname(debugfile)) |
368 | 386 | ||
@@ -393,7 +411,6 @@ def copydebugsources(debugsrcdir, d): | |||
393 | dvar = d.getVar('PKGD') | 411 | dvar = d.getVar('PKGD') |
394 | strip = d.getVar("STRIP") | 412 | strip = d.getVar("STRIP") |
395 | objcopy = d.getVar("OBJCOPY") | 413 | objcopy = d.getVar("OBJCOPY") |
396 | debugedit = d.expand("${STAGING_LIBDIR_NATIVE}/rpm/bin/debugedit") | ||
397 | workdir = d.getVar("WORKDIR") | 414 | workdir = d.getVar("WORKDIR") |
398 | workparentdir = os.path.dirname(os.path.dirname(workdir)) | 415 | workparentdir = os.path.dirname(os.path.dirname(workdir)) |
399 | workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir) | 416 | workbasedir = os.path.basename(os.path.dirname(workdir)) + "/" + os.path.basename(workdir) |
diff --git a/meta/recipes-devtools/dwarfsrcfiles/dwarfsrcfiles.bb b/meta/recipes-devtools/dwarfsrcfiles/dwarfsrcfiles.bb new file mode 100644 index 0000000000..c59a006eda --- /dev/null +++ b/meta/recipes-devtools/dwarfsrcfiles/dwarfsrcfiles.bb | |||
@@ -0,0 +1,22 @@ | |||
1 | SUMMARY = "A small utility for printing debig source file locations embedded in binaries" | ||
2 | LICENSE = "GPLv2+" | ||
3 | LIC_FILES_CHKSUM = "file://../dwarfsrcfiles.c;md5=31483894e453a77acbb67847565f1b5c;beginline=1;endline=8" | ||
4 | |||
5 | SRC_URI = "file://dwarfsrcfiles.c" | ||
6 | BBCLASSEXTEND = "native" | ||
7 | DEPENDS = "elfutils" | ||
8 | DEPENDS_append_libc-musl = " argp-standalone" | ||
9 | |||
10 | do_compile () { | ||
11 | ${CC} ${CFLAGS} ${LDFLAGS} -o dwarfsrcfiles ../dwarfsrcfiles.c -lelf -ldw | ||
12 | } | ||
13 | |||
14 | do_compile_libc-musl () { | ||
15 | ${CC} ${CFLAGS} ${LDFLAGS} -o dwarfsrcfiles ../dwarfsrcfiles.c -lelf -ldw -largp | ||
16 | } | ||
17 | |||
18 | do_install () { | ||
19 | install -d ${D}${bindir} | ||
20 | install -t ${D}${bindir} dwarfsrcfiles | ||
21 | } | ||
22 | |||
diff --git a/meta/recipes-devtools/dwarfsrcfiles/files/dwarfsrcfiles.c b/meta/recipes-devtools/dwarfsrcfiles/files/dwarfsrcfiles.c new file mode 100644 index 0000000000..af7af524eb --- /dev/null +++ b/meta/recipes-devtools/dwarfsrcfiles/files/dwarfsrcfiles.c | |||
@@ -0,0 +1,111 @@ | |||
1 | // dwarfsrcfiles.c - Get source files associated with the dwarf in a elf file. | ||
2 | // gcc -Wall -g -O2 -lelf -ldw -o dwarfsrcfiles dwarfsrcfiles.c | ||
3 | // | ||
4 | // Copyright (C) 2011, Mark Wielaard <mjw@redhat.com> | ||
5 | // | ||
6 | // This file is free software. You can redistribute it and/or modify | ||
7 | // it under the terms of the GNU General Public License (GPL); either | ||
8 | // version 2, or (at your option) any later version. | ||
9 | |||
10 | #include <argp.h> | ||
11 | #include <stdio.h> | ||
12 | |||
13 | #include <dwarf.h> | ||
14 | #include <elfutils/libdw.h> | ||
15 | #include <elfutils/libdwfl.h> | ||
16 | |||
17 | static int | ||
18 | process_cu (Dwarf_Die *cu_die) | ||
19 | { | ||
20 | Dwarf_Attribute attr; | ||
21 | const char *name; | ||
22 | const char *dir = NULL; | ||
23 | |||
24 | Dwarf_Files *files; | ||
25 | size_t n; | ||
26 | int i; | ||
27 | |||
28 | if (dwarf_tag (cu_die) != DW_TAG_compile_unit) | ||
29 | { | ||
30 | fprintf (stderr, "DIE isn't a compile unit"); | ||
31 | return -1; | ||
32 | } | ||
33 | |||
34 | if (dwarf_attr (cu_die, DW_AT_name, &attr) == NULL) | ||
35 | { | ||
36 | fprintf(stderr, "CU doesn't have a DW_AT_name"); | ||
37 | return -1; | ||
38 | } | ||
39 | |||
40 | name = dwarf_formstring (&attr); | ||
41 | if (name == NULL) | ||
42 | { | ||
43 | fprintf(stderr, "Couldn't get DW_AT_name as string, %s", | ||
44 | dwarf_errmsg (-1)); | ||
45 | return -1; | ||
46 | } | ||
47 | |||
48 | if (dwarf_attr (cu_die, DW_AT_comp_dir, &attr) != NULL) | ||
49 | { | ||
50 | dir = dwarf_formstring (&attr); | ||
51 | if (dir == NULL) | ||
52 | { | ||
53 | fprintf(stderr, "Couldn't get DW_AT_comp_die as string, %s", | ||
54 | dwarf_errmsg (-1)); | ||
55 | return -1; | ||
56 | } | ||
57 | } | ||
58 | |||
59 | if (dir == NULL) | ||
60 | printf ("%s\n", name); | ||
61 | else | ||
62 | printf ("%s/%s\n", dir, name); | ||
63 | |||
64 | if (dwarf_getsrcfiles (cu_die, &files, &n) != 0) | ||
65 | { | ||
66 | fprintf(stderr, "Couldn't get CU file table, %s", | ||
67 | dwarf_errmsg (-1)); | ||
68 | return -1; | ||
69 | } | ||
70 | |||
71 | for (i = 1; i < n; i++) | ||
72 | { | ||
73 | const char *file = dwarf_filesrc (files, i, NULL, NULL); | ||
74 | if (dir != NULL && file[0] != '/') | ||
75 | printf ("\t%s/%s\n", dir, file); | ||
76 | else | ||
77 | printf ("\t%s\n", file); | ||
78 | } | ||
79 | |||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | int | ||
84 | main (int argc, char **argv) | ||
85 | { | ||
86 | char* args[3]; | ||
87 | int res = 0; | ||
88 | Dwfl *dwfl; | ||
89 | Dwarf_Addr bias; | ||
90 | |||
91 | if (argc != 2) | ||
92 | fprintf(stderr, "Usage %s <file>", argv[0]); | ||
93 | |||
94 | // Pretend "dwarfsrcfiles -e <file>" was given, so we can use standard | ||
95 | // dwfl argp parser to open the file for us and get our Dwfl. Useful | ||
96 | // in case argument is an ET_REL file (like kernel modules). libdwfl | ||
97 | // will fix up relocations for us. | ||
98 | args[0] = argv[0]; | ||
99 | args[1] = "-e"; | ||
100 | args[2] = argv[1]; | ||
101 | |||
102 | argp_parse (dwfl_standard_argp (), 3, args, 0, NULL, &dwfl); | ||
103 | |||
104 | Dwarf_Die *cu = NULL; | ||
105 | while ((cu = dwfl_nextcu (dwfl, cu, &bias)) != NULL) | ||
106 | res |= process_cu (cu); | ||
107 | |||
108 | dwfl_end (dwfl); | ||
109 | |||
110 | return res; | ||
111 | } | ||