From 056631d658fb6f64e4a79ba0d47ed2de83ded1e849ed0063dfaa36b9f989f683 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Mon, 21 Sep 2020 20:56:09 +0000 Subject: [PATCH] Accepting request 835904 from home:tomdevries:branches:devel:tools-dwarves-kernel-dwz - Backport fixes for segfault when processing dwz-ed kernel [bsc#1176095,https://github.com/acmel/dwarves/issues/10]. * dwarves-dwarf_loader-Bail-out-at-DW_TAG_imported_unit-tags.patch * dwarves-dwarf_loader-Ignore-entries-in-a-DW_TAG_partial_unit-for-now.patch OBS-URL: https://build.opensuse.org/request/show/835904 OBS-URL: https://build.opensuse.org/package/show/devel:tools/dwarves?expand=0&rev=43 --- ...ail-out-at-DW_TAG_imported_unit-tags.patch | 32 ++++++++++++++++ ...ies-in-a-DW_TAG_partial_unit-for-now.patch | 38 +++++++++++++++++++ dwarves.changes | 8 ++++ dwarves.spec | 2 + 4 files changed, 80 insertions(+) create mode 100644 dwarves-dwarf_loader-Bail-out-at-DW_TAG_imported_unit-tags.patch create mode 100644 dwarves-dwarf_loader-Ignore-entries-in-a-DW_TAG_partial_unit-for-now.patch diff --git a/dwarves-dwarf_loader-Bail-out-at-DW_TAG_imported_unit-tags.patch b/dwarves-dwarf_loader-Bail-out-at-DW_TAG_imported_unit-tags.patch new file mode 100644 index 0000000..260dae8 --- /dev/null +++ b/dwarves-dwarf_loader-Bail-out-at-DW_TAG_imported_unit-tags.patch @@ -0,0 +1,32 @@ +dwarf_loader: Bail out at DW_TAG_imported_unit tags + +We need to support these in a future version, for now, just bail out to +avoid segfaults afterwards. + + $ pahole examples/sles/vmlinux-5.3.18-109.g8ff6392-default.debug + WARNING: DW_TAG_partial_unit used, some types will not be considered! + Probably this was optimized using a tool like 'dwz' + A future version of pahole will take support this. + $ + +Reported-by: Tom de Vries +Bugtracker: https://github.com/acmel/dwarves/issues/10 +Signed-off-by: Arnaldo Carvalho de Melo + +--- + dwarf_loader.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/dwarf_loader.c b/dwarf_loader.c +index 90c1e11..4d4a72e 100644 +--- a/dwarf_loader.c ++++ b/dwarf_loader.c +@@ -1615,6 +1615,8 @@ static struct tag *__die__process_tag(Dwarf_Die *die, struct cu *cu, + struct tag *tag; + + switch (dwarf_tag(die)) { ++ case DW_TAG_imported_unit: ++ return NULL; // We don't support imported units yet, so to avoid segfaults + case DW_TAG_array_type: + tag = die__create_new_array(die, cu); break; + case DW_TAG_base_type: diff --git a/dwarves-dwarf_loader-Ignore-entries-in-a-DW_TAG_partial_unit-for-now.patch b/dwarves-dwarf_loader-Ignore-entries-in-a-DW_TAG_partial_unit-for-now.patch new file mode 100644 index 0000000..5f55edb --- /dev/null +++ b/dwarves-dwarf_loader-Ignore-entries-in-a-DW_TAG_partial_unit-for-now.patch @@ -0,0 +1,38 @@ +dwarf_loader: Ignore entries in a DW_TAG_partial_unit, for now + +We will have to keep all CUs in memory and do lookups in imported units, +for now, just don't segfault. + +Reported-by: Tom de Vries +Bugtracker: https://github.com/acmel/dwarves/issues/10 +Signed-off-by: Arnaldo Carvalho de Melo + +--- + dwarf_loader.c | 14 +++++++++++++- + 1 file changed, 13 insertions(+), 1 deletion(-) + +diff --git a/dwarf_loader.c b/dwarf_loader.c +index 09edcfb..90c1e11 100644 +--- a/dwarf_loader.c ++++ b/dwarf_loader.c +@@ -2085,7 +2085,19 @@ static int die__process(Dwarf_Die *die, struct cu *cu) + Dwarf_Die child; + const uint16_t tag = dwarf_tag(die); + +- if (tag != DW_TAG_compile_unit && tag != DW_TAG_type_unit && tag != DW_TAG_partial_unit) { ++ if (tag == DW_TAG_partial_unit) { ++ static bool warned; ++ ++ if (!warned) { ++ fprintf(stderr, "WARNING: DW_TAG_partial_unit used, some types will not be considered!\n" ++ " Probably this was optimized using a tool like 'dwz'\n" ++ " A future version of pahole will take support this.\n"); ++ warned = true; ++ } ++ return 0; // so that other units can be processed ++ } ++ ++ if (tag != DW_TAG_compile_unit && tag != DW_TAG_type_unit) { + fprintf(stderr, "%s: DW_TAG_compile_unit, DW_TAG_type_unit or DW_TAG_partial_unit expected got %s!\n", + __FUNCTION__, dwarf_tag_name(tag)); + return -EINVAL; diff --git a/dwarves.changes b/dwarves.changes index 379b022..2d88ff1 100644 --- a/dwarves.changes +++ b/dwarves.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Mon Sep 21 18:48:25 UTC 2020 - Tom de Vries + +- Backport fixes for segfault when processing dwz-ed kernel + [bsc#1176095,https://github.com/acmel/dwarves/issues/10]. + * dwarves-dwarf_loader-Bail-out-at-DW_TAG_imported_unit-tags.patch + * dwarves-dwarf_loader-Ignore-entries-in-a-DW_TAG_partial_unit-for-now.patch + ------------------------------------------------------------------- Wed Sep 2 08:39:24 UTC 2020 - Jiri Slaby diff --git a/dwarves.spec b/dwarves.spec index 1b222a5..5b30e72 100644 --- a/dwarves.spec +++ b/dwarves.spec @@ -29,6 +29,8 @@ Source: https://fedorapeople.org/~acme/dwarves/dwarves-%version.tar.xz Source2: https://fedorapeople.org/~acme/dwarves/dwarves-%version.tar.sign Source9: baselibs.conf Patch0: libbpf-Fix-libbpf-hashmap-on-I-LP32-architectures.patch +Patch1: dwarves-dwarf_loader-Ignore-entries-in-a-DW_TAG_partial_unit-for-now.patch +Patch2: dwarves-dwarf_loader-Bail-out-at-DW_TAG_imported_unit-tags.patch BuildRequires: cmake BuildRequires: libdw-devel >= 0.170 %if 0%{?suse_version} < 1550