From 16bac5cf5ea68d68b4ee27389c189dc03c3475f9 Mon Sep 17 00:00:00 2001 From: Martin Cermak Date: Thu, 17 Apr 2025 15:04:22 +0200 Subject: [PATCH] Add 0006-pr32157-handle-dwarf5-DW_UT_type-unit-type-2.patch Related: #RHEL-86686 --- ...handle-dwarf5-DW_UT_type-unit-type-2.patch | 114 ++++++++++++++++++ debugedit.spec | 6 +- 2 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 0006-pr32157-handle-dwarf5-DW_UT_type-unit-type-2.patch diff --git a/0006-pr32157-handle-dwarf5-DW_UT_type-unit-type-2.patch b/0006-pr32157-handle-dwarf5-DW_UT_type-unit-type-2.patch new file mode 100644 index 0000000..3a6102d --- /dev/null +++ b/0006-pr32157-handle-dwarf5-DW_UT_type-unit-type-2.patch @@ -0,0 +1,114 @@ +commit a359559d4a7696a415cfec5f924363d26cb9a4eb +Author: Mark Wielaard +Date: Sat Sep 28 23:39:29 2024 +0200 + + debugedit: Handle DWARF5 DW_UT_type (Unit type 2) in ET_EXE/DYN + + Handle DW_UT_type as if it is a DW_UT_compile unit by skipping the + type id and offset in the header. Which are the only differences with + DW_UT_compile. And the id and offset don't need to be rewritten. This + doesn't handle debug types in objects or partial linked (ET_REL) files + that contain COMDAT sections (because debugedit doesn't handle more + than one debug_info section). Add a testcase for foobarbaz.exe. + + https://sourceware.org/bugzilla/show_bug.cgi?id=32157 + + Signed-off-by: Mark Wielaard + +diff --git a/tests/debugedit.at b/tests/debugedit.at +index 9432e30..55f9b54 100644 +--- a/tests/debugedit.at ++++ b/tests/debugedit.at +@@ -510,9 +510,9 @@ AT_CLEANUP + + # === + # Make sure -fdebug-types-section has updated strings in executable. +-# Currently only works with DWARF4 ++# DWARF4 + # === +-AT_SETUP([debugedit .debug_types exe]) ++AT_SETUP([debugedit .debug_types exe DWARF4]) + AT_KEYWORDS([debugtypes] [debugedit]) + DEBUGEDIT_SETUP([-fdebug-types-section -gdwarf-4]) + +@@ -537,6 +537,37 @@ readelf --debug-dump=info ./foobarbaz.exe \ + + AT_CLEANUP + ++# === ++# Make sure -fdebug-types-section has updated strings in executable. ++# DWARF5 ++# === ++AT_SETUP([debugedit .debug_types exe DWARF5]) ++AT_KEYWORDS([debugtypes] [debugedit]) ++DEBUGEDIT_SETUP([-fdebug-types-section -gdwarf-5]) ++AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"]) ++AT_SKIP_IF([! $READELF --debug-dump=info ./foobarbaz.exe | grep -F -q 'DW_TAG_type_unit']) ++ ++AT_DATA([expout], ++[st1 ++stb ++stf ++stringp1 ++stringp_bar ++stringp_baz ++stringp_foo ++stz ++]) ++ ++AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]]) ++AT_CHECK([[ ++$READELF --debug-dump=info ./foobarbaz.exe \ ++ | awk '/Abbrev Number:.*DW_TAG_type_unit/{p=1}{if(p)print}/^$/{p=0}' \ ++ | sed -n 's/^.*> *DW_AT_name *:.* \(stringp[^ ]*\|st.\)$/\1/p' \ ++ | sort ++]],[0],[expout]) ++ ++AT_CLEANUP ++ + # foo.o and bar.o are build with relative paths and so will use the + # comp_dir (from .debug_info). But bar.o is build from sources with + # an absolute path, so the .debug_line Directory Table should contain +diff --git a/tools/debugedit.c b/tools/debugedit.c +index 64be05c..939db62 100644 +--- a/tools/debugedit.c ++++ b/tools/debugedit.c +@@ -2602,10 +2602,13 @@ edit_info (DSO *dso, int phase, struct debug_section *sec) + + int cu_ptr_size = 0; + ++ uint8_t unit_type = DW_UT_compile; + if (cu_version >= 5) + { +- uint8_t unit_type = read_8 (ptr); +- if (unit_type != DW_UT_compile && unit_type != DW_UT_partial) ++ unit_type = read_8 (ptr); ++ if (unit_type != DW_UT_compile ++ && unit_type != DW_UT_partial ++ && unit_type != DW_UT_type) + { + error (0, 0, "%s: Unit type %u unhandled", dso->filename, + unit_type); +@@ -2615,7 +2618,12 @@ edit_info (DSO *dso, int phase, struct debug_section *sec) + cu_ptr_size = read_8 (ptr); + } + +- unsigned char *header_end = (cu_start + 23 + (cu_version < 5 ? 0 : 1)); ++ unsigned char *header_end = (cu_start + 23 ++ + (cu_version < 5 ++ ? 0 ++ : (unit_type != DW_UT_type ++ ? 1 /* unit */ ++ : 1 + 8 + 4))); /* unit, id, off */ + if (header_end > endsec) + { + error (0, 0, "%s: %s CU header too small", dso->filename, sec->name); +@@ -2653,7 +2661,7 @@ edit_info (DSO *dso, int phase, struct debug_section *sec) + return 1; + } + +- if (sec != &debug_sections[DEBUG_INFO]) ++ if (sec != &debug_sections[DEBUG_INFO] || unit_type == DW_UT_type) + ptr += 12; /* Skip type_signature and type_offset. */ + + abbrev = read_abbrev (dso, diff --git a/debugedit.spec b/debugedit.spec index 88a85d9..ef796dc 100644 --- a/debugedit.spec +++ b/debugedit.spec @@ -1,6 +1,6 @@ Name: debugedit Version: 5.0 -Release: 9%{?dist} +Release: 10%{?dist} Summary: Tools for debuginfo creation License: GPLv3+ and GPLv2+ and LGPLv2+ URL: https://sourceware.org/debugedit/ @@ -47,6 +47,7 @@ Patch6: 0005-writable.patch patch7: 0001-debug_str_offsets-header-version-and-padding-are-2-b.patch patch8: 0001-debugedit-Handle-unused-.debug_str_offsets-entries.patch Patch9: 0001-find-debuginfo-Fix-skip_mini-.gnu_debugdata-handling.patch +Patch10: 0006-pr32157-handle-dwarf5-DW_UT_type-unit-type-2.patch %description The debugedit project provides programs and scripts for creating @@ -90,6 +91,9 @@ make check %{?_smp_mflags} %{_mandir}/man1/find-debuginfo.1* %changelog +* Thu Apr 17 2025 Martin Cermak - 5.0-10 +- Add 0006-pr32157-handle-dwarf5-DW_UT_type-unit-type-2.patch + * Tue Apr 15 2025 Mark Wielaard - 5.0-9 - Add 0001-find-debuginfo-Fix-skip_mini-.gnu_debugdata-handling.patch