Compare commits

...

No commits in common. "c9-beta" and "c10s" have entirely different histories.

24 changed files with 448 additions and 1907 deletions

View File

@ -1,3 +0,0 @@
e15e23409266e2a0be8b3748235b126bedbc7b6b SOURCES/debugedit-5.0.tar.xz
1c91547813dddd09e345df31d8ecfbd0b1aaa9e9 SOURCES/debugedit-5.0.tar.xz.sig
4c6ca620f5b14e24492616195f7848df0029451c SOURCES/gpgkey-5C1D1AA44BE649DE760A.gpg

1
.fmf/version Normal file
View File

@ -0,0 +1 @@
1

11
.gitignore vendored
View File

@ -1,3 +1,8 @@
SOURCES/debugedit-5.0.tar.xz
SOURCES/debugedit-5.0.tar.xz.sig
SOURCES/gpgkey-5C1D1AA44BE649DE760A.gpg
/debugedit-0.2.tar.xz
/debugedit-0.2.tar.xz.sig
/debugedit-0.3.tar.xz
/debugedit-0.3.tar.xz.sig
/debugedit-5.0.tar.xz
/debugedit-5.0.tar.xz.sig
/debugedit-5.1.tar.xz
/debugedit-5.1.tar.xz.sig

View File

@ -64,13 +64,15 @@ index b1d39f4ac1fc..7fab084f31f2 100644
# Some source files that are needed by the tests
EXTRA_DIST += data/SOURCES/foo.c \
diff --git a/tests/atlocal.in b/tests/atlocal.in
--- a/tests/atlocal.in.orig 2025-06-20 12:58:03.601406269 +0200
+++ b/tests/atlocal.in 2025-06-20 12:58:26.398096509 +0200
@@ -14,3 +14,4 @@
index 9da28786ba26..e9bd31fe3f13 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -16,4 +16,5 @@ GDWARF_5_FLAG=@GDWARF_5_FLAG@
GZ_NONE_FLAG=@GZ_NONE_FLAG@
GZ_ZLIB_FLAG=@GZ_ZLIB_FLAG@
DWARF_5_DEBUGLINE=@DWARF_5_DEBUGLINE@
+DWARF_5_DEBUGADDR=@DWARF_5_DEBUGADDR@
DEBUG_MACRO_FLAG=@DEBUG_MACRO_FLAG@
diff --git a/tests/find-debuginfo.at b/tests/find-debuginfo.at
new file mode 100644
index 000000000000..d6f6ae9ee07a

View File

@ -162,7 +162,7 @@ index 43f9cee65cf8..fcf8f7d6564b 100644
@@ -1707,7 +1762,7 @@ edit_strp (DSO *dso, uint32_t form, unsigned char *ptr, int phase,
struct strings *strings = (form == DW_FORM_line_strp
? &dso->debug_line_str : &dso->debug_str);
idx = do_read_32_relocated (ptr);
idx = do_read_32_relocated (ptr, sec);
- entry = string_find_entry (strings, idx);
+ entry = string_find_entry (strings, idx, false);
new_idx = strent_offset (entry->entry);
@ -186,14 +186,14 @@ index 43f9cee65cf8..fcf8f7d6564b 100644
{
struct stridxentry *entry;
size_t idx, new_idx;
idx = do_read_32_relocated (ptr);
idx = do_read_32_relocated (ptr, str_off_sec);
- entry = string_find_entry (&dso->debug_str, idx);
+ entry = string_find_entry (&dso->debug_str, idx, true);
+ if (entry == &debugedit_stridxentry)
+ error (0, 0, "Warning, .debug_str_offsets table at offset %zx "
+ "index [%zd] .debug_str [%zx] entry '%s' unused, "
+ "replacing with '<debugedit>'\n",
+ (index_start - debug_sections[DEBUG_STR_OFFSETS].data),
+ (index_start - str_off_sec->data),
+ (ptr - offstart) / sizeof (uint32_t), idx,
+ orig_str (&dso->debug_str, idx));
new_idx = strent_offset (entry->entry);
@ -212,7 +212,7 @@ index 43f9cee65cf8..fcf8f7d6564b 100644
@@ -3211,7 +3278,8 @@ edit_dwarf2 (DSO *dso)
struct stridxentry *entry;
size_t idx, new_idx;
idx = do_read_32_relocated (ptr);
idx = do_read_32_relocated (ptr, macro_sec);
- entry = string_find_entry (&dso->debug_str, idx);
+ entry = string_find_entry (&dso->debug_str, idx,
+ false);
@ -241,3 +241,4 @@ index 43f9cee65cf8..fcf8f7d6564b 100644
&debug_sections[DEBUG_LINE_STR]);
--
2.49.0

View File

@ -1,31 +1,32 @@
commit 971a74d79b48a19ff1446642f39b3c5a8a7db238
Author: Mark Wielaard <mark@klomp.org>
Date: Thu Nov 28 17:58:54 2024 +0100
From 67dee55d160e312b9d0db607630eacfaa3ce08e4 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Thu, 28 Nov 2024 17:58:54 +0100
Subject: [PATCH] find-debuginfo: Check files are writable before modifying
them
find-debuginfo: Check files are writable before modifying them
Since commit dfe1f7ff3 ("find-debuginfo.sh: Exit with real exit status
in parallel jobs") there is a check whether gdb-add-index worked
correctly and find-debuginfo would fail (even in parallel mode) if an
error occured.
Since commit dfe1f7ff3 ("find-debuginfo.sh: Exit with real exit status
in parallel jobs") there is a check whether gdb-add-index worked
correctly and find-debuginfo would fail (even in parallel mode) if an
error occured.
This turned out to show that gdb-add-index needs write permission to
add the gdb index to the file. This is also the case for a couple of
other things, like running objcopy --merge-notes. debugedit and
add_minidebug already made sure it had write permission.
This turned out to show that gdb-add-index needs write permission to
add the gdb index to the file. This is also the case for a couple of
other things, like running objcopy --merge-notes. debugedit and
add_minidebug already made sure it had write permission.
To make sure find-debuginfo doesn't (partially) fail extend the
writable check to include the gdb-add-index and objcopy --merge-notes
invocation.
Signed-off-by: Mark Wielaard <mark@klomp.org>
To make sure find-debuginfo doesn't (partially) fail extend the
writable check to include the gdb-add-index and objcopy --merge-notes
invocation.
---
scripts/find-debuginfo.in | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in
index a360bf0582dc..4e4ef5a64005 100755
--- a/scripts/find-debuginfo.in
+++ b/scripts/find-debuginfo.in
@@ -467,10 +467,22 @@
$strict && exit 2
@@ -481,14 +481,29 @@ do_file()
$strict && return 2
fi
+ # debugedit makes sure to to get write permission to the file and
@ -40,13 +41,20 @@ index a360bf0582dc..4e4ef5a64005 100755
+ if test "$f_writable" = "false"; then
+ chmod u+w "$f"
+ fi
gdb-add-index "$f"
gdb-add-index "$f" || {
status=$?
echo >&2 "*** ERROR:: GDB exited with exit status $status during index generation"
+ if test "$f_writable" = "false"; then
+ chmod u-w "$f"
+ fi
return 2
}
+ if test "$f_writable" = "false"; then
+ chmod u-w "$f"
+ fi
else
echo >&2 "*** ERROR: GDB index requested, but no gdb-add-index installed"
exit 2
return 2
@@ -497,7 +512,13 @@ do_file()
# Compress any annobin notes in the original binary.
@ -87,3 +95,6 @@ index a360bf0582dc..4e4ef5a64005 100755
fi
echo "./${f#$RPM_BUILD_ROOT}" >> "$ELFBINSFILE"
--
2.47.0

View File

@ -0,0 +1,68 @@
From 1869e3b886c4596fb4ce471dd08121401d207cfa Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Thu, 16 Jan 2025 19:09:00 +0100
Subject: [PATCH] find-debuginfo: Make return from do_file explicit
Make all returns from do_file explicit so they don't implicitly return
the result of the last command. Also make sure the $temp/linked file
exists, even if it is empty. A file could have hardlinks to files not
under the buildroot.
https://bugzilla.redhat.com/show_bug.cgi?id=2334760
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
scripts/find-debuginfo.in | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in
index a360bf0582dc..d102e8937775 100755
--- a/scripts/find-debuginfo.in
+++ b/scripts/find-debuginfo.in
@@ -434,6 +434,7 @@ trap 'rm -rf "$temp"' EXIT
# Build a list of unstripped ELF files and their hardlinks
touch "$temp/primary"
+touch "$temp/linked"
find "$RPM_BUILD_ROOT" ! -path "${debugdir}/*.debug" -type f \
\( -perm -0100 -or -perm -0010 -or -perm -0001 \) \
-print | LC_ALL=C sort |
@@ -458,7 +459,7 @@ do_file()
local nlinks=$1 inum=$2 f=$3 id link linked
get_debugfn "$f"
- [ -f "${debugfn}" ] && return
+ [ -f "${debugfn}" ] && return 0
$verbose && echo "extracting debug info from $f"
# See also cpio SOURCEFILE copy. Directories must match up.
@@ -475,7 +476,7 @@ do_file()
id=$(debugedit -b "$debug_base_name" -d "$debug_dest_name" \
$no_recompute -i \
${build_id_seed:+--build-id-seed="$build_id_seed"} \
- -l "$SOURCEFILE" "$f") || exit
+ -l "$SOURCEFILE" "$f") || return 1
if [ -z "$id" ]; then
echo >&2 "*** ${strict_error}: No build ID note found in $f"
$strict && return 2
@@ -503,7 +504,7 @@ do_file()
# just has its file names collected and adjusted.
case "$dn" in
/usr/lib/debug/*)
- return ;;
+ return 0 ;;
esac
mkdir -p "${debugdn}"
@@ -544,6 +545,8 @@ do_file()
mkdir -p "$(dirname "$debugfn")" && ln -nf "$link" "$debugfn"
done
fi
+
+ return 0
}
# 16^6 - 1 or about 16 million files
--
2.47.1

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# debugedit
The debugedit package

View File

@ -1,34 +0,0 @@
From bd45e5ad0541036b698ad7ed8b95f5a5f977b7c8 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Sun, 5 May 2024 20:41:12 +0200
Subject: [PATCH] debug_str_offsets header version and padding are 2 bytes, not
4 bytes
Reading too much bytes for the header made debugedit skip the first
actual string offsets table entry.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
tools/debugedit.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/debugedit.c b/tools/debugedit.c
index 2990f962cd37..1307a149de8b 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -2731,10 +2731,10 @@ update_str_offsets (DSO *dso)
if (unit_length == 0xffffffff || endp - ptr < unit_length)
break;
unsigned char *endidxp = ptr + unit_length;
- uint32_t version = read_32 (ptr);
+ uint32_t version = read_16 (ptr);
if (version != 5)
break;
- uint32_t padding = read_32 (ptr);
+ uint32_t padding = read_16 (ptr);
if (padding != 0)
break;
--
2.49.0

View File

@ -1,432 +0,0 @@
From 3e7aeeab4f744ad15108775685db68d3a35b0735 Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Thu, 23 Mar 2023 18:07:40 +0100
Subject: [PATCH] debugedit: Add support for .debug_str_offsets (DW_FORM_strx)
In theory supporting strx .debug_str_offsets is easy, the strings in
.debug_str are just read through an indirection table. When the
strings are updated in .debug_str we just need to rewrite the
indirection table.
The tricky part is the ET_REL (object files or kernel modules)
support. Relocation reading is "global" per section and we expect to
read a relocation only once. But we need to read the
DW_AT_str_offsets_base before reading any strx form attributes. So we
read that first, then reset the relptr. And when we read from the
.debug_str_offsets section we need to save and restore the .debug_info
relptr.
* tools/debugedit.c (do_read_24): New function.
(str_offsets_base): New static variable.
(buf_read_ule24): New function.
(buf_read_ube24): Likewise.
(setup_relbuf): Handle .debug_str_offsets.
(do_read_uleb128): New function.
(do_read_str_form_relocated): Likewise.
(read_abbrev): Handle DW_FORM_strx[1234].
(edit_strp): Take the actual string form as argument.
Use do_read_str_form_relocated.
(read_dwarf5_line_entries): Pass form to edit_strp.
(edit_attributes_str_comp_dir): Take the actual string
form as argument. Use do_read_str_form_relocated.
(edit_attributes): Handle DW_FORM_strx[1234].
(edit_info): Read DW_AT_str_offsets_base first.
(update_str_offsets): New function.
(edit_dwarf2): Setup do_read_24. Call update_str_offsets.
https://sourceware.org/bugzilla/show_bug.cgi?id=28728
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
tools/debugedit.c | 216 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 192 insertions(+), 24 deletions(-)
diff --git a/tools/debugedit.c b/tools/debugedit.c
index e654981..7802f9f 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -1,4 +1,5 @@
/* Copyright (C) 2001-2003, 2005, 2007, 2009-2011, 2016, 2017 Red Hat, Inc.
+ Copyright (C) 2022, 2023 Mark J. Wielaard <mark@klomp.org>
Written by Alexander Larsson <alexl@redhat.com>, 2002
Based on code by Jakub Jelinek <jakub@redhat.com>, 2001.
String/Line table rewriting by Mark Wielaard <mjw@redhat.com>, 2017.
@@ -264,6 +264,7 @@ typedef struct
})
static uint16_t (*do_read_16) (unsigned char *ptr);
+static uint32_t (*do_read_24) (unsigned char *ptr);
static uint32_t (*do_read_32) (unsigned char *ptr);
static void (*do_write_16) (unsigned char *ptr, uint16_t val);
static void (*do_write_32) (unsigned char *ptr, uint32_t val);
@@ -271,6 +272,9 @@ static void (*do_write_32) (unsigned char *ptr, uint32_t val);
static int ptr_size;
static int cu_version;
+/* The offset into the .debug_str_offsets section for the current CU. */
+static uint32_t str_offsets_base;
+
static inline uint16_t
buf_read_ule16 (unsigned char *data)
{
@@ -283,6 +287,18 @@ buf_read_ube16 (unsigned char *data)
return data[1] | (data[0] << 8);
}
+static inline uint32_t
+buf_read_ule24 (unsigned char *data)
+{
+ return data[0] | (data[1] << 8) | (data[2] << 16);
+}
+
+static inline uint32_t
+buf_read_ube24 (unsigned char *data)
+{
+ return data[2] | (data[1] << 8) | (data[0] << 16);
+}
+
static inline uint32_t
buf_read_ule32 (unsigned char *data)
{
@@ -544,10 +560,12 @@ setup_relbuf (DSO *dso, debug_section *sec, int *reltype)
/* Relocations against section symbols are uninteresting in REL. */
if (dso->shdr[i].sh_type == SHT_REL && sym.st_value == 0)
continue;
- /* Only consider relocations against .debug_str, .debug_line,
- .debug_line_str, and .debug_abbrev. */
+ /* Only consider relocations against .debug_str,
+ .debug_str_offsets, .debug_line, .debug_line_str, and
+ .debug_abbrev. */
if (sym.st_shndx == 0 ||
(sym.st_shndx != debug_sections[DEBUG_STR].sec
+ && sym.st_shndx != debug_sections[DEBUG_STR_OFFSETS].sec
&& sym.st_shndx != debug_sections[DEBUG_LINE].sec
&& sym.st_shndx != debug_sections[DEBUG_LINE_STR].sec
&& sym.st_shndx != debug_sections[DEBUG_ABBREV].sec))
@@ -684,6 +702,59 @@ update_rela_data (DSO *dso, struct debug_section *sec)
free (sec->relbuf);
}
+static inline uint32_t
+do_read_uleb128 (unsigned char *ptr)
+{
+ unsigned char *uleb_ptr = ptr;
+ return read_uleb128 (uleb_ptr);
+}
+
+static inline uint32_t
+do_read_str_form_relocated (DSO *dso, uint32_t form, unsigned char *ptr)
+{
+ uint32_t idx;
+ switch (form)
+ {
+ case DW_FORM_strp:
+ case DW_FORM_line_strp:
+ return do_read_32_relocated (ptr);
+
+ case DW_FORM_strx1:
+ idx = *ptr;
+ break;
+ case DW_FORM_strx2:
+ idx = do_read_16 (ptr);
+ break;
+ case DW_FORM_strx3:
+ idx = do_read_24 (ptr);
+ break;
+ case DW_FORM_strx4:
+ idx = do_read_32 (ptr);
+ break;
+ case DW_FORM_strx:
+ idx = do_read_uleb128 (ptr);
+ break;
+ default:
+ error (1, 0, "Unhandled string form DW_FORM_0x%x", form);
+ return -1;
+ }
+
+ unsigned char *str_off_ptr = debug_sections[DEBUG_STR_OFFSETS].data;
+ str_off_ptr += str_offsets_base;
+ str_off_ptr += idx * 4;
+
+ /* Switch rel reading... */
+ REL *old_relptr = relptr;
+ REL *old_relend = relend;
+ setup_relbuf(dso, &debug_sections[DEBUG_STR_OFFSETS], &reltype);
+
+ uint32_t str_off = do_read_32_relocated (str_off_ptr);
+
+ relptr = old_relptr;
+ relend = old_relend;
+ return str_off;
+}
+
struct abbrev_attr
{
unsigned int attr;
@@ -789,7 +860,12 @@ no_memory:
|| form == DW_FORM_addrx1
|| form == DW_FORM_addrx2
|| form == DW_FORM_addrx3
- || form == DW_FORM_addrx4)))
+ || form == DW_FORM_addrx4
+ || form == DW_FORM_strx
+ || form == DW_FORM_strx1
+ || form == DW_FORM_strx2
+ || form == DW_FORM_strx3
+ || form == DW_FORM_strx4)))
{
error (0, 0, "%s: Unknown DWARF DW_FORM_0x%x", dso->filename,
form);
@@ -1520,9 +1596,10 @@ edit_dwarf2_line (DSO *dso)
}
}
-/* Record or adjust (according to phase) DW_FORM_strp or DW_FORM_line_strp. */
+/* Record or adjust (according to phase) DW_FORM_strp or DW_FORM_line_strp.
+ Also handles DW_FORM_strx, but just for recording the (indexed) string. */
static void
-edit_strp (DSO *dso, bool line_strp, unsigned char *ptr, int phase,
+edit_strp (DSO *dso, uint32_t form, unsigned char *ptr, int phase,
bool handled_strp)
{
unsigned char *ptr_orig = ptr;
@@ -1537,16 +1614,19 @@ edit_strp (DSO *dso, bool line_strp, unsigned char *ptr, int phase,
recorded. */
if (! handled_strp)
{
- size_t idx = do_read_32_relocated (ptr);
- record_existing_string_entry_idx (line_strp, dso, idx);
+ size_t idx = do_read_str_form_relocated (dso, form, ptr);
+ record_existing_string_entry_idx (form == DW_FORM_line_strp,
+ dso, idx);
}
}
- else if (line_strp
- ? need_line_strp_update : need_strp_update) /* && phase == 1 */
+ else if ((form == DW_FORM_strp
+ || form == DW_FORM_line_strp) /* DW_FORM_strx stays the same. */
+ && (form == DW_FORM_line_strp
+ ? need_line_strp_update : need_strp_update)) /* && phase == 1 */
{
struct stridxentry *entry;
size_t idx, new_idx;
- struct strings *strings = (line_strp
+ struct strings *strings = (form == DW_FORM_line_strp
? &dso->debug_line_str : &dso->debug_str);
idx = do_read_32_relocated (ptr);
entry = string_find_entry (strings, idx);
@@ -1926,9 +2006,10 @@ read_dwarf5_line_entries (DSO *dso, unsigned char **ptrp,
switch (form)
{
+ /* Note we don't expect DW_FORM_strx in the line table. */
case DW_FORM_strp:
case DW_FORM_line_strp:
- edit_strp (dso, line_strp, *ptrp, phase, handled_strp);
+ edit_strp (dso, form, *ptrp, phase, handled_strp);
break;
}
@@ -2110,11 +2191,12 @@ find_new_list_offs (struct debug_lines *lines, size_t idx)
/* Read DW_FORM_strp or DW_FORM_line_strp collecting compilation directory. */
static void
-edit_attributes_str_comp_dir (bool line_strp, DSO *dso, unsigned char **ptrp,
+edit_attributes_str_comp_dir (uint32_t form, DSO *dso, unsigned char **ptrp,
int phase, char **comp_dirp, bool *handled_strpp)
{
const char *dir;
- size_t idx = do_read_32_relocated (*ptrp);
+ size_t idx = do_read_str_form_relocated (dso, form, *ptrp);
+ bool line_strp = form == DW_FORM_line_strp;
/* In phase zero we collect the comp_dir. */
if (phase == 0)
{
@@ -2245,20 +2327,29 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
}
}
}
- else if (form == DW_FORM_strp)
- edit_attributes_str_comp_dir (false /* line_strp */, dso,
+ else if (form == DW_FORM_strp
+ || form == DW_FORM_line_strp
+ || form == DW_FORM_strx
+ || form == DW_FORM_strx1
+ || form == DW_FORM_strx2
+ || form == DW_FORM_strx3
+ || form == DW_FORM_strx4)
+ edit_attributes_str_comp_dir (form, dso,
&ptr, phase, &comp_dir,
&handled_strp);
- else if (form == DW_FORM_line_strp)
- edit_attributes_str_comp_dir (true /* line_strp */, dso, &ptr,
- phase, &comp_dir, &handled_strp);
}
else if ((t->tag == DW_TAG_compile_unit
|| t->tag == DW_TAG_partial_unit)
&& ((form == DW_FORM_strp
&& debug_sections[DEBUG_STR].data)
|| (form == DW_FORM_line_strp
- && debug_sections[DEBUG_LINE_STR].data))
+ && debug_sections[DEBUG_LINE_STR].data)
+ || ((form == DW_FORM_strx
+ || form == DW_FORM_strx1
+ || form == DW_FORM_strx2
+ || form == DW_FORM_strx3
+ || form == DW_FORM_strx4)
+ && debug_sections[DEBUG_STR_OFFSETS].data))
&& t->attr[i].attr == DW_AT_name)
{
bool line_strp = form == DW_FORM_line_strp;
@@ -2267,7 +2358,7 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
unit. If starting with / it is a full path name.
Note that we don't handle DW_FORM_string in this
case. */
- size_t idx = do_read_32_relocated (ptr);
+ size_t idx = do_read_str_form_relocated (dso, form, ptr);
/* In phase zero we will look for a comp_dir to use. */
if (phase == 0)
@@ -2314,10 +2405,13 @@ edit_attributes (DSO *dso, unsigned char *ptr, struct abbrev_tag *t, int phase)
switch (form)
{
case DW_FORM_strp:
- edit_strp (dso, false /* line_strp */, ptr, phase, handled_strp);
- break;
case DW_FORM_line_strp:
- edit_strp (dso, true /* line_strp */, ptr, phase, handled_strp);
+ case DW_FORM_strx:
+ case DW_FORM_strx1:
+ case DW_FORM_strx2:
+ case DW_FORM_strx3:
+ case DW_FORM_strx4:
+ edit_strp (dso, form, ptr, phase, handled_strp);
break;
}
@@ -2404,6 +2498,8 @@ edit_info (DSO *dso, int phase, struct debug_section *sec)
uint32_t value;
htab_t abbrev;
struct abbrev_tag tag, *t;
+ int i;
+ bool first;
ptr = sec->data;
if (ptr == NULL)
@@ -2507,6 +2603,8 @@ edit_info (DSO *dso, int phase, struct debug_section *sec)
if (abbrev == NULL)
return 1;
+ first = true;
+ str_offsets_base = 0;
while (ptr < endcu)
{
tag.entry = read_uleb128 (ptr);
@@ -2521,6 +2619,30 @@ edit_info (DSO *dso, int phase, struct debug_section *sec)
return 1;
}
+ /* We need str_offsets_base before processing the CU. */
+ if (first)
+ {
+ first = false;
+ if (cu_version >= 5)
+ {
+ uint32_t form;
+ unsigned char *fptr = ptr;
+ // We will read this DIE again, save and reset rel reading
+ REL *old_relptr = relptr;
+ for (i = 0; i < t->nattr; ++i)
+ {
+ form = t->attr[i].form;
+ if (t->attr[i].attr == DW_AT_str_offsets_base)
+ {
+ str_offsets_base = do_read_32_relocated (fptr);
+ break;
+ }
+ skip_form (dso, &form, &fptr);
+ }
+ // Reset the rel reading...
+ relptr = old_relptr;
+ }
+ }
ptr = edit_attributes (dso, ptr, t, phase);
if (ptr == NULL)
break;
@@ -2554,6 +2676,41 @@ edit_dwarf2_any_str (DSO *dso, struct strings *strings, debug_section *secp)
strings->str_buf = strdata->d_buf;
}
+/* Rebuild .debug_str_offsets. */
+static void
+update_str_offsets (DSO *dso)
+{
+ unsigned char *ptr = debug_sections[DEBUG_STR_OFFSETS].data;
+ unsigned char *endp = ptr + debug_sections[DEBUG_STR_OFFSETS].size;
+
+ while (ptr < endp)
+ {
+ /* Read header, unit_length, version and padding. */
+ if (endp - ptr < 3 * 4)
+ break;
+ uint32_t unit_length = read_32 (ptr);
+ if (unit_length == 0xffffffff || endp - ptr < unit_length)
+ break;
+ unsigned char *endidxp = ptr + unit_length;
+ uint32_t version = read_32 (ptr);
+ if (version != 5)
+ break;
+ uint32_t padding = read_32 (ptr);
+ if (padding != 0)
+ break;
+
+ while (ptr < endidxp)
+ {
+ struct stridxentry *entry;
+ size_t idx, new_idx;
+ idx = do_read_32_relocated (ptr);
+ entry = string_find_entry (&dso->debug_str, idx);
+ new_idx = strent_offset (entry->entry);
+ write_32_relocated (ptr, new_idx);
+ }
+ }
+}
+
static int
edit_dwarf2 (DSO *dso)
{
@@ -2675,6 +2832,7 @@ edit_dwarf2 (DSO *dso)
if (dso->ehdr.e_ident[EI_DATA] == ELFDATA2LSB)
{
do_read_16 = buf_read_ule16;
+ do_read_24 = buf_read_ule24;
do_read_32 = buf_read_ule32;
do_write_16 = dwarf2_write_le16;
do_write_32 = dwarf2_write_le32;
@@ -2682,6 +2840,7 @@ edit_dwarf2 (DSO *dso)
else if (dso->ehdr.e_ident[EI_DATA] == ELFDATA2MSB)
{
do_read_16 = buf_read_ube16;
+ do_read_24 = buf_read_ube24;
do_read_32 = buf_read_ube32;
do_write_16 = dwarf2_write_be16;
do_write_32 = dwarf2_write_be32;
@@ -2997,6 +3156,15 @@ edit_dwarf2 (DSO *dso)
dirty_section (DEBUG_MACRO);
if (need_stmt_update || need_line_strp_update)
dirty_section (DEBUG_LINE);
+ if (need_strp_update && debug_sections[DEBUG_STR_OFFSETS].data != NULL)
+ {
+ setup_relbuf(dso, &debug_sections[DEBUG_STR_OFFSETS], &reltype);
+ rel_updated = false;
+ update_str_offsets (dso);
+ dirty_section (DEBUG_STR_OFFSETS);
+ if (rel_updated)
+ update_rela_data (dso, &debug_sections[DEBUG_STR_OFFSETS]);
+ }
/* Update any relocations addends we might have touched. */
if (info_rel_updated)
--
2.42.0

View File

@ -1,130 +0,0 @@
From ae27211cbbfb63a0ad3c141cd1310d7f583ec40e Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
Date: Fri, 30 Jul 2021 18:09:46 +0200
Subject: [PATCH] tests: Handle zero directory entry in .debug_line DWARF5
debugedit.at
We were skipping the zero directory entry, because it was always
the same as the directory entry at position one. But that isn't
true anymore with gcc 11.2.1. There the zero dir entry is unique.
Fix the debugedit.at .debug_line testcases using DWARF5 to also
include dir entry zero.
Signed-off-by: Mark Wielaard <mark@klomp.org>
---
configure.ac | 14 ++++++++++++++
tests/atlocal.in | 1 +
tests/debugedit.at | 18 ++++++++++++------
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/configure.ac b/configure.ac
index e5c9230..6a53365 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,6 +87,20 @@ CFLAGS="$save_CFLAGS"
GDWARF_5_FLAG=$ac_cv_gdwarf_5
AC_SUBST([GDWARF_5_FLAG])
+AC_CACHE_CHECK([whether -gdwarf-5 produced DWARF5 .debug_line], ac_cv_dwarf_5_debugline, [dnl
+save_CFLAGS="$CFLAGS"
+CFLAGS="-gdwarf-5"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([[int i=0;]],[[/* empty main */]])],
+ [if readelf --debug-dump=line conftest.o 2>&1 | \
+ grep "DWARF Version:" 2>&1 | grep "5" > /dev/null 2>&1; \
+ then ac_cv_dwarf_5_debugline=yes; \
+ else ac_cv_dwarf_5_debugline=no; fi],
+ ac_cv_dwarf_5_debugline=no)
+CFLAGS="$save_CFLAGS"
+])
+DWARF_5_DEBUGLINE=$ac_cv_dwarf_5_debugline
+AC_SUBST([DWARF_5_DEBUGLINE])
+
AC_CACHE_CHECK([whether gcc supports -gz=none], ac_cv_gz_none, [dnl
save_CFLAGS="$CFLAGS"
CFLAGS="-gz=none"
diff --git a/tests/atlocal.in b/tests/atlocal.in
index 8399f8d..d916301 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -13,3 +13,4 @@ READELF="@READELF@"
GDWARF_5_FLAG=@GDWARF_5_FLAG@
GZ_NONE_FLAG=@GZ_NONE_FLAG@
+DWARF_5_DEBUGLINE=@DWARF_5_DEBUGLINE@
diff --git a/tests/debugedit.at b/tests/debugedit.at
index 0311d26..725e68e 100644
--- a/tests/debugedit.at
+++ b/tests/debugedit.at
@@ -488,10 +488,12 @@ AT_CLEANUP
AT_SETUP([debugedit .debug_line objects DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
+AT_SKIP_IF([test "$DWARF_5_DEBUGLINE" = "no"])
DEBUGEDIT_SETUP([-gdwarf-5])
AT_DATA([expout],
[foo/bar/baz
+foo/bar/baz/subdir_bar
foo/bar/baz/subdir_headers
])
@@ -500,8 +502,8 @@ AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
readelf --debug-dump=line foo.o subdir_bar/bar.o baz.o \
- | grep -A5 "The Directory Table" | grep "^ [123]" \
- | cut -f2- -d/ | grep ^foo/ | sort
+ | grep -A5 "The Directory Table" | grep "^ [0123]" \
+ | cut -f2- -d/ | grep ^foo/ | sort -u
]],[0],[expout])
AT_CLEANUP
@@ -535,18 +537,20 @@ AT_CLEANUP
AT_SETUP([debugedit .debug_line partial DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
+AT_SKIP_IF([test "$DWARF_5_DEBUGLINE" = "no"])
DEBUGEDIT_SETUP([-gdwarf-5])
AT_DATA([expout],
[foo/bar/baz
+foo/bar/baz/subdir_bar
foo/bar/baz/subdir_headers
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
readelf --debug-dump=line ./foobarbaz.part.o \
- | grep -A5 "The Directory Table" | grep "^ [123]" \
- | cut -f2- -d/ | grep ^foo/ | sort
+ | grep -A5 "The Directory Table" | grep "^ [0123]" \
+ | cut -f2- -d/ | grep ^foo/ | sort -u
]],[0],[expout])
AT_CLEANUP
@@ -580,18 +584,20 @@ AT_CLEANUP
AT_SETUP([debugedit .debug_line exe DWARF5])
AT_KEYWORDS([debuginfo] [debugedit])
AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
+AT_SKIP_IF([test "$DWARF_5_DEBUGLINE" = "no"])
DEBUGEDIT_SETUP([-gdwarf-5])
AT_DATA([expout],
[foo/bar/baz
+foo/bar/baz/subdir_bar
foo/bar/baz/subdir_headers
])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
readelf --debug-dump=line ./foobarbaz.exe \
- | grep -A5 "The Directory Table" | grep "^ [123]" \
- | cut -f2- -d/ | grep ^foo/ | sort
+ | grep -A5 "The Directory Table" | grep "^ [0123]" \
+ | cut -f2- -d/ | grep ^foo/ | sort -u
]],[0],[expout])
AT_CLEANUP
--
2.27.0

View File

@ -1,116 +0,0 @@
From b8ac71d9f88202f00a32c5a8b3b4b93bb2fa110a Mon Sep 17 00:00:00 2001
From: Prarit Bhargava <prarit@redhat.com>
Date: Thu, 26 Jan 2023 16:08:57 -0500
Subject: [PATCH] scripts/find-debuginfo.in: Add -q|--quiet
Projects with a large number of compiled files end up with a large number
of 'extracting debug info from' messages in the build log. In the case of
the Fedora kernel these messages account for 8504 lines in the log, or 61%
of the entire log [1].
Removing these lines make the log easier to view and comprehend for some
projects, however, not all projects will want to silence these messages so
suppressing them must be optional.
Add a -q|--quiet which allows users to silence the non-error output from
the script.
[1] https://kojipkgs.fedoraproject.org//packages/kernel/6.2.0/0.rc5.20230123git2475bf0250de.38.fc38/data/logs/x86_64/build.log
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
---
scripts/find-debuginfo.in | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in
index 8090c84..7dec3c3 100755
--- a/scripts/find-debuginfo.in
+++ b/scripts/find-debuginfo.in
@@ -26,7 +26,7 @@ Usage: find-debuginfo [OPTION]... [builddir]
automagically generates debug info and file lists
Options:
-[--strict-build-id] [-g] [-r] [-m] [-i] [-n]
+[--strict-build-id] [-g] [-r] [-m] [-i] [-n] [-q]
[--keep-section SECTION] [--remove-section SECTION]
[--g-libs]
[-j N] [--jobs N]
@@ -94,6 +94,8 @@ will be called /usr/debug/src/<BASE>. This makes sure the debug source
dirs are unique between package version, release and achitecture (Use
--unique-debug-src-base "%{name}-%{VERSION}-%{RELEASE}.%{_arch}")
+The -q or --quiet flag silences non-error output from the script.
+
All file names in switches are relative to builddir ('.' if not given).
EOF
}
@@ -146,6 +148,9 @@ n_jobs=1
# exit early on --version or --help
done=false
+# silence non-error output
+quiet=false
+
BUILDDIR=.
out=debugfiles.list
srcout=
@@ -239,6 +244,9 @@ while [ $# -gt 0 ]; do
srcout=$2
shift
;;
+ -q|--quiet)
+ quiet=true
+ ;;
--version)
echo "find-debuginfo @VERSION@"
done=true;
@@ -437,7 +445,7 @@ do_file()
get_debugfn "$f"
[ -f "${debugfn}" ] && return
- echo "extracting debug info from $f"
+ $quiet || echo "extracting debug info from $f"
# See also cpio SOURCEFILE copy. Directories must match up.
debug_base_name="$RPM_BUILD_DIR"
debug_dest_name="/usr/src/debug"
@@ -513,7 +521,7 @@ do_file()
grep "^$inum " "$temp/linked" | while read inum linked; do
link=$debugfn
get_debugfn "$linked"
- echo "hard linked $link to $debugfn"
+ $quiet || echo "hard linked $link to $debugfn"
mkdir -p "$(dirname "$debugfn")" && ln -nf "$link" "$debugfn"
done
fi
@@ -576,7 +584,7 @@ if $run_dwz \
&& [ -d "${RPM_BUILD_ROOT}/usr/lib/debug" ]; then
readarray dwz_files < <(cd "${RPM_BUILD_ROOT}/usr/lib/debug"; find -type f -name \*.debug | LC_ALL=C sort)
if [ ${#dwz_files[@]} -gt 0 ]; then
- size_before=$(du -sk ${RPM_BUILD_ROOT}/usr/lib/debug | cut -f1)
+ $quiet || size_before=$(du -sk ${RPM_BUILD_ROOT}/usr/lib/debug | cut -f1)
dwz_multifile_name="${RPM_PACKAGE_NAME}-${RPM_PACKAGE_VERSION}-${RPM_PACKAGE_RELEASE}.${RPM_ARCH}"
dwz_multifile_suffix=
dwz_multifile_idx=0
@@ -600,8 +608,8 @@ if $run_dwz \
echo >&2 "*** ERROR: DWARF compression requested, but no dwz installed"
exit 2
fi
- size_after=$(du -sk ${RPM_BUILD_ROOT}/usr/lib/debug | cut -f1)
- echo "original debug info size: ${size_before}kB, size after compression: ${size_after}kB"
+ $quiet || size_after=$(du -sk ${RPM_BUILD_ROOT}/usr/lib/debug | cut -f1)
+ $quiet || echo "original debug info size: ${size_before}kB, size after compression: ${size_after}kB"
# Remove .dwz directory if empty
rmdir "${RPM_BUILD_ROOT}/usr/lib/debug/.dwz" 2>/dev/null
@@ -621,7 +629,7 @@ do
f=${f#$RPM_BUILD_ROOT}
t=${t#$RPM_BUILD_ROOT}
if [ -f "$debugdir$t" ]; then
- echo "symlinked /usr/lib/debug$t to /usr/lib/debug${f}.debug"
+ $quiet || echo "symlinked /usr/lib/debug$t to /usr/lib/debug${f}.debug"
debug_link "/usr/lib/debug$t" "${f}.debug"
fi
done
--
2.39.1

View File

@ -1,46 +0,0 @@
commit 7497274aed00c459a0d74bf171e1b11358b0210c
Author: Mark Wielaard <mark@klomp.org>
Date: Thu Apr 21 00:05:38 2022 +0200
debugedit: Use standard libelf elf_strptr
The strptr function in debugedit.c does the same thing as libelf
elf_strptr. But elf_strptr handles bounds checks and invalid section
offsets better. And elf_strptr handles compressed sections.
* tools/debugedit.c (strptr): Just call elf_strptr.
Signed-off-by: Mark Wielaard <mark@klomp.org>
diff --git a/tools/debugedit.c b/tools/debugedit.c
index e734dd7caadd..d82ae5a169df 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -295,25 +296,9 @@ buf_read_ube32 (unsigned char *data)
}
static const char *
-strptr (DSO *dso, int sec, off_t offset)
+strptr (DSO *dso, size_t sec, size_t offset)
{
- Elf_Scn *scn;
- Elf_Data *data;
-
- scn = dso->scn[sec];
- if (offset >= 0 && (GElf_Addr) offset < dso->shdr[sec].sh_size)
- {
- data = NULL;
- while ((data = elf_getdata (scn, data)) != NULL)
- {
- if (data->d_buf
- && offset >= data->d_off
- && offset < data->d_off + data->d_size)
- return (const char *) data->d_buf + (offset - data->d_off);
- }
- }
-
- return NULL;
+ return elf_strptr (dso->elf, sec, offset);
}

View File

@ -1,548 +0,0 @@
commit c156ae62c3913aa86bd4cd4abda93772747e029f
Author: Morten Linderud <morten@linderud.pw>
Date: Sun Nov 6 18:10:23 2022 +0100
debugedit: decompress (and recompress) DWARF sections
When encountering compressed DWARF section try to decompress them
before rewriting. Afterwards recompress them. All this is
automatic. No new command line options.
Decompression was added by Morten, Mark then added recompression.
The recompression support needed a bit of workaround for an elfutils
< 0.192 bug https://sourceware.org/bugzilla/show_bug.cgi?id=32102
Various new tests were added. In debugedit.at DEBUGEDIT_SETUP now
takes an (optional) second arg to set the -gz=... option. readelf is
now called with -zp to automatically decompress any compressed
data/string sections.
https://sourceware.org/bugzilla/show_bug.cgi?id=27636
Signed-off-by: Morten Linderud <morten@linderud.pw>
Signed-off-by: Mark Wielaard <mark@klomp.org>
diff --git a/configure.ac b/configure.ac
index f0065c9932f4..96922267b7fe 100644
--- a/configure.ac
+++ b/configure.ac
@@ -113,6 +113,19 @@
fi
AC_SUBST([GZ_NONE_FLAG])
+AC_CACHE_CHECK([whether gcc supports -gz=zlib], ac_cv_gz_zlib, [dnl
+save_CFLAGS="$CFLAGS"
+CFLAGS="-gz=zlib"
+AC_LINK_IFELSE([AC_LANG_PROGRAM()], ac_cv_gz_zlib=yes, ac_cv_gz_zlib=no)
+CFLAGS="$save_CFLAGS"
+])
+if test "$ac_cv_gz_zlib" = "yes"; then
+ GZ_ZLIB_FLAG="-gz=zlib"
+else
+ GZ_ZLIB_FLAG=""
+fi
+AC_SUBST([GZ_ZLIB_FLAG])
+
# And generate the output files.
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
diff --git a/tests/atlocal.in b/tests/atlocal.in
index 01b998c83c7f..d3364d3e9e58 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -12,4 +12,5 @@
GDWARF_5_FLAG=@GDWARF_5_FLAG@
GZ_NONE_FLAG=@GZ_NONE_FLAG@
+GZ_ZLIB_FLAG=@GZ_ZLIB_FLAG@
DWARF_5_DEBUGLINE=@DWARF_5_DEBUGLINE@
diff --git a/tests/debugedit.at b/tests/debugedit.at
index 94b0caee5423..b125e627546d 100644
--- a/tests/debugedit.at
+++ b/tests/debugedit.at
@@ -1,6 +1,6 @@
# debugedit.at: Tests for the debugedit tool
#
-# Copyright (C) 2019 Mark J. Wielaard <mark@klomp.org>
+# Copyright (C) 2019, 2024 Mark J. Wielaard <mark@klomp.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -22,7 +22,11 @@
AT_TESTED([debugedit])
# Helper to create some test binaries.
-# Optional parameter can specify additional gcc parameters.
+# Optional fist parameter can specify additional gcc parameters.
+# e.g. -gdwarf-4 or -gdwarf-5 for explicit DWARF version.
+# -g3 is always given. Second parameter can be a compression flag
+# like $GZ_ZLIB_FLAG (if it exists), when not given $GZ_NONE_FLAG
+# is used.
m4_define([DEBUGEDIT_SETUP],[[
# Create some test binaries. Create and build them in different subdirs
# to make sure they produce different relative/absolute paths.
@@ -36,12 +40,19 @@
cp "${abs_srcdir}"/data/SOURCES/foobar.h subdir_headers
cp "${abs_srcdir}"/data/SOURCES/baz.c .
+# Check second param, if given use compression
+if test -z "$2"; then
+GZ_FLAG=$GZ_NONE_FLAG
+else
+GZ_FLAG=$2
+fi
+
# First three object files (foo.o subdir_bar/bar.o and baz.o)
-$CC $CFLAGS -g3 $GZ_NONE_FLAG -Isubdir_headers $1 -c subdir_foo/foo.c
+$CC $CFLAGS -g3 $GZ_FLAG -Isubdir_headers $1 -c subdir_foo/foo.c
cd subdir_bar
-$CC $CFLAGS -g3 $GZ_NONE_FLAG -I../subdir_headers $1 -c bar.c
+$CC $CFLAGS -g3 $GZ_FLAG -I../subdir_headers $1 -c bar.c
cd ..
-$CC $CFLAGS -g3 $GZ_NONE_FLAG -I$(pwd)/subdir_headers $1 -c $(pwd)/baz.c
+$CC $CFLAGS -g3 $GZ_FLAG -I$(pwd)/subdir_headers $1 -c $(pwd)/baz.c
# Then a partially linked object file (somewhat like a kernel module).
# This will still have relocations between the debug sections.
@@ -49,7 +60,7 @@
# Create an executable. Relocations between debug sections will
# have been resolved.
-$CC $CFLAGS -g3 $GZ_NONE_FLAG -o foobarbaz.exe foo.o subdir_bar/bar.o baz.o
+$CC $CFLAGS -g3 $GZ_FLAG $1 -o foobarbaz.exe foo.o subdir_bar/bar.o baz.o
]])
# ===
@@ -83,6 +94,17 @@
AT_CLEANUP
+AT_SETUP([debugedit executable (compressed)])
+AT_KEYWORDS([debuginfo] [debugedit])
+AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
+DEBUGEDIT_SETUP([], [$GZ_ZLIB_FLAG])
+
+AT_CHECK([[./foobarbaz.exe]])
+AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
+AT_CHECK([[./foobarbaz.exe]])
+
+AT_CLEANUP
+
# ===
# debugedit should at least replace the .debug_str directory paths
# in the objects.
@@ -93,7 +115,7 @@
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
-readelf -p.debug_str foo.o subdir_bar/bar.o baz.o | cut -c13- \
+readelf -zp.debug_str foo.o subdir_bar/bar.o baz.o | cut -c13- \
| grep ^$(pwd) | sort \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
@@ -108,7 +130,7 @@
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
-readelf -p.debug_str foo.o subdir_bar/bar.o baz.o | cut -c13- \
+readelf -zp.debug_str foo.o subdir_bar/bar.o baz.o | cut -c13- \
| grep ^/foo/bar/baz | sort
]],[0],[expout])
@@ -125,7 +147,7 @@
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
-readelf -p.debug_str -p.debug_line_str foo.o subdir_bar/bar.o baz.o \
+readelf -zp.debug_str -p.debug_line_str foo.o subdir_bar/bar.o baz.o \
| cut -c13- \
| grep ^$(pwd) | sort | uniq \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
@@ -141,7 +163,7 @@
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
AT_CHECK([[
-readelf -p.debug_str -p.debug_line_str foo.o subdir_bar/bar.o baz.o \
+readelf -zp.debug_str -p.debug_line_str foo.o subdir_bar/bar.o baz.o \
| cut -c13- \
| grep ^/foo/bar/baz | sort | uniq
]],[0],[expout],[ignore])
@@ -160,7 +182,7 @@
# (and replace that textually with /foo/bar/baz)
# Note that partially linked files, might have multiple duplicate
# strings, but debugedit will merge them. So use sort -u.
-readelf -p.debug_str ./foobarbaz.part.o | cut -c13- \
+readelf -zp.debug_str ./foobarbaz.part.o | cut -c13- \
| grep ^$(pwd) | sort -u \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
@@ -173,7 +195,7 @@
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
-readelf -p.debug_str ./foobarbaz.part.o | cut -c13- \
+readelf -zp.debug_str ./foobarbaz.part.o | cut -c13- \
| grep ^/foo/bar/baz | sort
]],[0],[expout])
@@ -192,7 +214,7 @@
# (and replace that textually with /foo/bar/baz)
# Note that partially linked files, might have multiple duplicate
# strings, but debugedit will merge them. So use sort -u.
-readelf -p.debug_str -p.debug_line_str ./foobarbaz.part.o | cut -c13- \
+readelf -zp.debug_str -zp.debug_line_str ./foobarbaz.part.o | cut -c13- \
| grep ^$(pwd) | sort -u | uniq \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
@@ -205,7 +227,7 @@
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
AT_CHECK([[
-readelf -p.debug_str -p.debug_line_str ./foobarbaz.part.o | cut -c13- \
+readelf -zp.debug_str -zp.debug_line_str ./foobarbaz.part.o | cut -c13- \
| grep ^/foo/bar/baz | sort | uniq
]],[0],[expout],[ignore])
@@ -221,7 +243,7 @@
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
-readelf -p.debug_str foobarbaz.exe | cut -c13- \
+readelf -zp.debug_str foobarbaz.exe | cut -c13- \
| grep ^$(pwd) | sort \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
@@ -235,7 +257,7 @@
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
-readelf -p.debug_str foobarbaz.exe | cut -c13- \
+readelf -zp.debug_str foobarbaz.exe | cut -c13- \
| grep ^/foo/bar/baz | sort
]],[0],[expout])
@@ -252,7 +274,7 @@
# Capture strings that start with the testdir (pwd) directory path
# (and replace that textually with /foo/bar/baz)
-readelf -p.debug_str -p.debug_line_str foobarbaz.exe | cut -c13- \
+readelf -zp.debug_str -zp.debug_line_str foobarbaz.exe | cut -c13- \
| grep ^$(pwd) | sort | uniq \
| sed -e "s@$(pwd)@/foo/bar/baz@" > expout
@@ -266,7 +288,7 @@
# Check the replaced strings are all there.
AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
AT_CHECK([[
-readelf -p.debug_str -p.debug_line_str foobarbaz.exe | cut -c13- \
+readelf -zp.debug_str -zp.debug_line_str foobarbaz.exe | cut -c13- \
| grep ^/foo/bar/baz | sort | uniq
]],[0],[expout],[ignore])
@@ -312,6 +334,30 @@
AT_CLEANUP
+AT_SETUP([debugedit .debug_info objects (compressed)])
+AT_KEYWORDS([debuginfo] [debugedit])
+AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
+DEBUGEDIT_SETUP([], [$GZ_ZLIB_FLAG])
+
+AT_DATA([expout],
+[/foo/bar/baz
+/foo/bar/baz/baz.c
+/foo/bar/baz/subdir_bar
+])
+
+AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foo.o]])
+AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./subdir_bar/bar.o]])
+AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./baz.o]])
+AT_CHECK([[
+(readelf --debug-dump=info foo.o; \
+ readelf --debug-dump=info subdir_bar/bar.o; \
+ readelf --debug-dump=info baz.o) \
+ | grep -E 'DW_AT_(name|comp_dir)' \
+ | rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
+]],[0],[expout])
+
+AT_CLEANUP
+
# ===
# Make sure DW_AT_name and DW_AT_comp_dir strings are replaced
# in partial linked object.
@@ -335,6 +381,26 @@
AT_CLEANUP
+AT_SETUP([debugedit .debug_info partial (compressed)])
+AT_KEYWORDS([debuginfo] [debugedit])
+AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
+DEBUGEDIT_SETUP([], [$GZ_ZLIB_FLAG])
+
+AT_DATA([expout],
+[/foo/bar/baz
+/foo/bar/baz/baz.c
+/foo/bar/baz/subdir_bar
+])
+
+AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.part.o]])
+AT_CHECK([[
+readelf --debug-dump=info ./foobarbaz.part.o \
+ | grep -E 'DW_AT_(name|comp_dir)' \
+ | rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
+]],[0],[expout])
+
+AT_CLEANUP
+
# ===
# Make sure DW_AT_name and DW_AT_comp_dir strings are replaced
# in executable.
@@ -357,6 +423,25 @@
AT_CLEANUP
+AT_SETUP([debugedit .debug_info exe (compressed)])
+AT_KEYWORDS([debuginfo] [debugedit])
+AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
+DEBUGEDIT_SETUP([], [$GZ_ZLIB_FLAG])
+
+AT_DATA([expout],
+[/foo/bar/baz
+/foo/bar/baz/baz.c
+/foo/bar/baz/subdir_bar
+])
+
+AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
+AT_CHECK([[
+readelf --debug-dump=info ./foobarbaz.exe | grep -E 'DW_AT_(name|comp_dir)' \
+ | rev | cut -d: -f1 | rev | cut -c2- | grep ^/foo/bar/baz | sort -u
+]],[0],[expout])
+
+AT_CLEANUP
+
# ===
# Make sure -fdebug-types-section has updated strings in objects.
# Currently only works with DWARF4
@@ -673,6 +758,26 @@
AT_CLEANUP
+AT_SETUP([debugedit .debug_macro exe (compressed)])
+AT_KEYWORDS([debuginfo] [debugedit])
+AT_SKIP_IF([test -z "$GZ_ZLIB_FLAG"])
+DEBUGEDIT_SETUP([$DEBUG_MACRO_FLAG], [$GZ_ZLIB_FLAG])
+
+# We expect 3 for each compile unit.
+AT_DATA([expout],
+[NUMBER 42
+NUMBER 42
+NUMBER 42
+])
+
+AT_CHECK([[debugedit -b $(pwd) -d /foo/bar/baz ./foobarbaz.exe]])
+AT_CHECK([[
+readelf --debug-dump=macro ./foobarbaz.exe \
+ | grep NUMBER | rev | cut -d: -f1 | rev | cut -c2-
+]],[0],[expout])
+
+AT_CLEANUP
+
# ===
# source list mode dwarf-4
# ===
@@ -696,3 +801,26 @@
AT_CHECK([[debugedit -l sources.list main]])
AT_CHECK([[grep -q main.c sources.list]])
AT_CLEANUP
+
+# ===
+# source list with compression dwarf-4
+# ===
+AT_SETUP([debugedit --list-file compressed DWARF4])
+AT_KEYWORDS([debuginfo] [debugedit])
+echo "int main () { }" > main.c
+$CC $CFLAGS $GZ_ZLIB_FLAG -gdwarf-4 -o main main.c
+AT_CHECK([[debugedit -l sources.list main]])
+AT_CHECK([[grep -q main.c sources.list]])
+AT_CLEANUP
+
+# ===
+# source list with compression dwarf-5
+# ===
+AT_SETUP([debugedit --list-file compressed DWARF5])
+AT_KEYWORDS([debuginfo] [debugedit])
+AT_SKIP_IF([test "$GDWARF_5_FLAG" = "no"])
+echo "int main () { }" > main.c
+$CC $CFLAGS $GZ_ZLIB_FLAG -gdwarf-5 -o main main.c
+AT_CHECK([[debugedit -l sources.list main]])
+AT_CHECK([[grep -q main.c sources.list]])
+AT_CLEANUP
diff --git a/tools/debugedit.c b/tools/debugedit.c
index 6712f0fca2d0..beefd65bab6a 100644
--- a/tools/debugedit.c
+++ b/tools/debugedit.c
@@ -41,6 +41,7 @@
#include <gelf.h>
#include <dwarf.h>
+#include <libelf.h>
#ifndef MAX
#define MAX(m, n) ((m) < (n) ? (n) : (m))
@@ -118,6 +119,10 @@ static bool need_line_strp_update = false;
DW_AT_stmt_list attributes indexes in the debug_info. */
static bool need_stmt_update = false;
+/* If we recompress any debug section we need to write out the ELF
+ again. */
+static bool recompressed = false;
+
/* Storage for dynamically allocated strings to put into string
table. Keep together in memory blocks of 16K. */
#define STRMEMSIZE (16 * 1024)
@@ -445,6 +445,7 @@
int sec, relsec;
REL *relbuf;
REL *relend;
+ uint32_t ch_type;
/* Only happens for COMDAT .debug_macro and .debug_types. */
struct debug_section *next;
} debug_section;
@@ -1503,16 +1509,22 @@ static void
edit_dwarf2_line (DSO *dso)
{
Elf_Data *linedata = debug_sections[DEBUG_LINE].elf_data;
- int linendx = debug_sections[DEBUG_LINE].sec;
- Elf_Scn *linescn = dso->scn[linendx];
unsigned char *old_buf = linedata->d_buf;
- /* Out with the old. */
- linedata->d_size = 0;
+ /* A nicer way to do this would be to set the original d_size to
+ zero and add a new Elf_Data section to contain the new data.
+ Out with the old. In with the new.
- /* In with the new. */
+ int linendx = debug_sections[DEBUG_LINE].sec;
+ Elf_Scn *linescn = dso->scn[linendx];
+ linedata->d_size = 0;
linedata = elf_newdata (linescn);
+ But when we then (recompress) the section there is a bug in
+ elfutils < 0.192 that causes the compression to fail/create bad
+ compressed data. So we just reuse the existing linedata (possibly
+ loosing track of the original d_buf, which will be overwritten). */
+
dso->lines.line_buf = malloc (dso->lines.debug_lines_len);
if (dso->lines.line_buf == NULL)
error (1, ENOMEM, "No memory for new .debug_line table (0x%zx bytes)",
@@ -1660,6 +1672,7 @@ edit_dwarf2_line (DSO *dso)
memcpy (ptr, optr, remaining);
ptr += remaining;
}
+ elf_flagdata (linedata, ELF_C_SET, ELF_F_DIRTY);
}
/* Record or adjust (according to phase) DW_FORM_strp or DW_FORM_line_strp.
@@ -2744,20 +2757,28 @@ edit_dwarf2_any_str (DSO *dso, struct strings *strings, debug_section *secp)
{
Strtab *strtab = strings->str_tab;
Elf_Data *strdata = secp->elf_data;
+
+ /* A nicer way to do this would be to set the original d_size to
+ zero and add a new Elf_Data section to contain the new data.
+ Out with the old. In with the new.
+
int strndx = secp->sec;
Elf_Scn *strscn = dso->scn[strndx];
-
- /* Out with the old. */
strdata->d_size = 0;
- /* In with the new. */
strdata = elf_newdata (strscn);
+ But when we then (recompress) the section there is a bug in
+ elfutils < 0.192 that causes the compression to fail/create bad
+ compressed data. So we just reuse the existing strdata (possibly
+ loosing track of the original d_buf, which will be overwritten). */
+
/* We really should check whether we had enough memory,
but the old ebl version will just abort on out of
memory... */
strtab_finalize (strtab, strdata);
secp->size = strdata->d_size;
strings->str_buf = strdata->d_buf;
+ elf_flagdata (strdata, ELF_C_SET, ELF_F_DIRTY);
}
/* Rebuild .debug_str_offsets. */
@@ -2869,6 +2890,22 @@ edit_dwarf2 (DSO *dso)
}
scn = dso->scn[i];
+
+ /* Check for compressed DWARF headers. Records
+ ch_type so we can recompress headers after we
+ processed the data. */
+ if (dso->shdr[i].sh_flags & SHF_COMPRESSED)
+ {
+ GElf_Chdr chdr;
+ if (gelf_getchdr(dso->scn[i], &chdr) == NULL)
+ error (1, 0, "Couldn't get compressed header: %s",
+ elf_errmsg (-1));
+ debug_sec->ch_type = chdr.ch_type;
+ if (elf_compress (scn, 0, 0) < 0)
+ error (1, 0, "Failed decompression");
+ gelf_getshdr (scn, &dso->shdr[i]);
+ }
+
data = elf_getdata (scn, NULL);
assert (data != NULL && data->d_buf != NULL);
assert (elf_getdata (scn, data) == NULL);
@@ -3743,6 +3780,35 @@ main (int argc, char *argv[])
}
}
+ /* Recompress any debug sections that might have been uncompressed. */
+ if (dirty_elf)
+ for (int s = 0; debug_sections[s].name; s++)
+ {
+ for (struct debug_section *secp = &debug_sections[s]; secp != NULL;
+ secp = secp->next)
+ {
+ if (secp->ch_type != 0)
+ {
+ int sec = secp->sec;
+ Elf_Scn *scn = dso->scn[sec];
+ GElf_Shdr shdr = dso->shdr[sec];
+ Elf_Data *data;
+ data = elf_getdata (scn, NULL);
+ if (elf_compress (scn, secp->ch_type, 0) < 0)
+ error (1, 0, "Failed recompression");
+ gelf_getshdr (scn, &shdr);
+ dso->shdr[secp->sec] = shdr;
+ data = elf_getdata (scn, NULL);
+ secp->elf_data = data;
+ secp->data = data->d_buf;
+ secp->size = data->d_size;
+ elf_flagshdr (scn, ELF_C_SET, ELF_F_DIRTY);
+ elf_flagdata (data, ELF_C_SET, ELF_F_DIRTY);
+ recompressed = 1;
+ }
+ }
+ }
+
/* Normally we only need to explicitly update the section headers
and data when any section data changed size. But because of a bug
in elfutils before 0.169 we will have to update and write out all
@@ -3750,7 +3816,8 @@ main (int argc, char *argv[])
set). https://sourceware.org/bugzilla/show_bug.cgi?id=21199 */
bool need_update = (need_strp_update
|| need_line_strp_update
- || need_stmt_update);
+ || need_stmt_update
+ || recompressed);
#if !_ELFUTILS_PREREQ (0, 169)
/* string replacements or build_id updates don't change section size. */

View File

@ -1,114 +0,0 @@
commit a359559d4a7696a415cfec5f924363d26cb9a4eb
Author: Mark Wielaard <mark@klomp.org>
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 <mark@klomp.org>
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,

View File

@ -1,298 +0,0 @@
# The original tests were written against debugedit 5.1
# There are some small differences with debugedit 5.0
# - readelf is used hardcoded s/$READELF/readelf/
# - find-debuginfo emits some stderr output so change [] to [ignore]
# - find-debuginfo prints all files processed instead a summary
# s/Extracting debug info from 3 files/extracting debug info from/
# - find-debuginfo doesn't print how many files dwz will process
# So just remove AT_CHECK([grep "DWARF-compressing 3 files" stdout]...)
--- a/tests/find-debuginfo.at 2025-06-20 17:06:25.346478796 +0200
+++ b/tests/find-debuginfo.at 2025-06-20 17:06:04.035015633 +0200
@@ -49,9 +49,9 @@
AT_KEYWORDS([find-debuginfo] [sources])
FIND_DEBUGINFO_PKG_BUILD_SETUP
# Sanity check the binaries have debug sections
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [0], [ignore], [])
# We need to set some environment variables for running find-debuginfo
# normally set by rpmbuild.
#
@@ -63,19 +63,19 @@
RPM_PACKAGE_RELEASE=rel \
RPM_ARCH=arch \
find-debuginfo ${PWD}/subdir_build],
- [0], [stdout], [])
+ [0], [stdout], [ignore])
# Make sure all three binaries are processed
-AT_CHECK([grep "Extracting debug info from 3 files" stdout], [0], [ignore], [])
+AT_CHECK([grep "extracting debug info from" stdout], [0], [ignore], [])
# debug sections should have been removed
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [1], [ignore], [])
# Now there are .debug files with those .debug_ sections
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
[0], [ignore], [])
# Check all sources are listed in debugsources.list
AT_DATA([expout],
@@ -94,9 +94,9 @@
AT_KEYWORDS([find-debuginfo] [sources] [debugdata] [gdb-index])
FIND_DEBUGINFO_PKG_BUILD_SETUP
# Sanity check the binaries have debug sections
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [0], [ignore], [])
# We need to set some environment variables for running find-debuginfo
# normally set by rpmbuild.
#
@@ -108,33 +108,33 @@
RPM_PACKAGE_RELEASE=rel \
RPM_ARCH=arch \
find-debuginfo -m -i ${PWD}/subdir_build],
- [0], [stdout], [])
+ [0], [stdout], [ignore])
# Make sure all three binaries are processed
-AT_CHECK([grep "Extracting debug info from 3 files" stdout], [0], [ignore], [])
+AT_CHECK([grep "extracting debug info from" stdout], [0], [ignore], [])
# debug sections should have been removed
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [1], [ignore], [])
# But they now have a .gnu_debugdata section
-AT_CHECK([$READELF -S subdir_build/foo | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/foo | grep gnu_debugdata],
[0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/bar | grep gnu_debugdata],
[0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/baz | grep gnu_debugdata],
[0], [ignore], [])
# There are .debug files with those .debug_ sections
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
[0], [ignore], [])
# The .debug files should also have a .gdb_index sections
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/foo.debug | grep gdb_index],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/bar.debug | grep gdb_index],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/baz.debug | grep gdb_index],
[0], [ignore], [])
# Check all sources are listed in debugsources.list
AT_DATA([expout],
@@ -154,9 +154,9 @@
AT_KEYWORDS([find-debuginfo] [sources] [debugdata] [gdb-index] [jobs])
FIND_DEBUGINFO_PKG_BUILD_SETUP
# Sanity check the binaries have debug sections
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [0], [ignore], [])
# We need to set some environment variables for running find-debuginfo
# normally set by rpmbuild.
#
@@ -168,33 +168,33 @@
RPM_PACKAGE_RELEASE=rel \
RPM_ARCH=arch \
find-debuginfo -m -i -j6 ${PWD}/subdir_build],
- [0], [stdout], [])
+ [0], [stdout], [ignore])
# Make sure all three binaries are processed
-AT_CHECK([grep "Extracting debug info from 3 files" stdout], [0], [ignore], [])
+AT_CHECK([grep "extracting debug info from" stdout], [0], [ignore], [])
# debug sections should have been removed
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [1], [ignore], [])
# But they now have a .gnu_debugdata section
-AT_CHECK([$READELF -S subdir_build/foo | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/foo | grep gnu_debugdata],
[0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/bar | grep gnu_debugdata],
[0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/baz | grep gnu_debugdata],
[0], [ignore], [])
# There are .debug files with those .debug_ sections
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
[0], [ignore], [])
# The .debug files should also have a .gdb_index sections
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/foo.debug | grep gdb_index],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/bar.debug | grep gdb_index],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/baz.debug | grep gdb_index],
[0], [ignore], [])
# Check all sources are listed in debugsources.list
AT_DATA([expout],
@@ -216,9 +216,9 @@
AT_SKIP_IF([test "$DWARF_5_DEBUGADDR" = "yes"])
FIND_DEBUGINFO_PKG_BUILD_SETUP
# Sanity check the binaries have debug sections
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [0], [ignore], [])
# We need to set some environment variables for running find-debuginfo
# normally set by rpmbuild.
#
@@ -231,34 +231,33 @@
RPM_PACKAGE_RELEASE=rel \
RPM_ARCH=arch \
find-debuginfo -m -i --run-dwz ${PWD}/subdir_build],
- [0], [stdout], [])
+ [0], [stdout], [ignore])
# Make sure all three binaries are processed
-AT_CHECK([grep "Extracting debug info from 3 files" stdout], [0], [ignore], [])
-AT_CHECK([grep "DWARF-compressing 3 files" stdout], [0], [ignore], [])
+AT_CHECK([grep "extracting debug info from" stdout], [0], [ignore], [])
# debug sections should have been removed
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [1], [ignore], [])
# But they now have a .gnu_debugdata section
-AT_CHECK([$READELF -S subdir_build/foo | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/foo | grep gnu_debugdata],
[0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/bar | grep gnu_debugdata],
[0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/baz | grep gnu_debugdata],
[0], [ignore], [])
# There are .debug files with those .debug_ sections
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
[0], [ignore], [])
# The .debug files should also have a .gdb_index sections
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/foo.debug | grep gdb_index],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/bar.debug | grep gdb_index],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/baz.debug | grep gdb_index],
[0], [ignore], [])
# There should also be a dwz multi file now
AT_CHECK([test -f usr/lib/debug/.dwz/pkg-ver-rel.arch], [0], [], [])
@@ -282,9 +281,9 @@
AT_SKIP_IF([test "$DWARF_5_DEBUGADDR" = "yes"])
FIND_DEBUGINFO_PKG_BUILD_SETUP
# Sanity check the binaries have debug sections
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [0], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [0], [ignore], [])
# We need to set some environment variables for running find-debuginfo
# normally set by rpmbuild.
#
@@ -297,34 +296,33 @@
RPM_PACKAGE_RELEASE=rel \
RPM_ARCH=arch \
find-debuginfo -m -i --run-dwz -j6 ${PWD}/subdir_build],
- [0], [stdout], [])
+ [0], [stdout], [ignore])
# Make sure all three binaries are processed
-AT_CHECK([grep "Extracting debug info from 3 files" stdout], [0], [ignore], [])
-AT_CHECK([grep "DWARF-compressing 3 files" stdout], [0], [ignore], [])
+AT_CHECK([grep "extracting debug info from" stdout], [0], [ignore], [])
# debug sections should have been removed
-AT_CHECK([$READELF -S subdir_build/foo | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep debug_], [1], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/foo | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/bar | grep debug_], [1], [ignore], [])
+AT_CHECK([readelf -S subdir_build/baz | grep debug_], [1], [ignore], [])
# But they now have a .gnu_debugdata section
-AT_CHECK([$READELF -S subdir_build/foo | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/foo | grep gnu_debugdata],
[0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/bar | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/bar | grep gnu_debugdata],
[0], [ignore], [])
-AT_CHECK([$READELF -S subdir_build/baz | grep gnu_debugdata],
+AT_CHECK([readelf -S subdir_build/baz | grep gnu_debugdata],
[0], [ignore], [])
# There are .debug files with those .debug_ sections
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/foo.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/bar.debug | grep debug_],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/baz.debug | grep debug_],
[0], [ignore], [])
# The .debug files should also have a .gdb_index sections
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/foo.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/foo.debug | grep gdb_index],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/bar.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/bar.debug | grep gdb_index],
[0], [ignore], [])
-AT_CHECK([$READELF -S usr/lib/debug/subdir_build/baz.debug | grep gdb_index],
+AT_CHECK([readelf -S usr/lib/debug/subdir_build/baz.debug | grep gdb_index],
[0], [ignore], [])
# There should also be a dwz multi file now
AT_CHECK([test -f usr/lib/debug/.dwz/pkg-ver-rel.arch], [0], [], [])

View File

@ -1,152 +0,0 @@
Name: debugedit
Version: 5.0
Release: 11%{?dist}
Summary: Tools for debuginfo creation
License: GPLv3+ and GPLv2+ and LGPLv2+
URL: https://sourceware.org/debugedit/
Source0: https://sourceware.org/pub/debugedit/%{version}/%{name}-%{version}.tar.xz
Source1: https://sourceware.org/pub/debugedit/%{version}/%{name}-%{version}.tar.xz.sig
Source2: gpgkey-5C1D1AA44BE649DE760A.gpg
BuildRequires: make gcc
BuildRequires: pkgconfig(libelf)
BuildRequires: pkgconfig(libdw)
BuildRequires: help2man
BuildRequires: gnupg2
# For the testsuite.
BuildRequires: autoconf
BuildRequires: automake
# The find-debuginfo.sh script has a couple of tools it needs at runtime.
# For strip_to_debug, eu-strip
Requires: elfutils
# For add_minidebug, readelf, awk, nm, sort, comm, objcopy, xz
Requires: binutils, gawk, coreutils, xz
# For find and xargs
Requires: findutils
# For do_file, gdb_add_index
# We only need gdb-add-index, so suggest gdb-minimal (full gdb is also ok)
Requires: /usr/bin/gdb-add-index
Suggests: gdb-minimal
# For run_job, sed
Requires: sed
# For dwz
Requires: dwz
# For append_uniq, grep
Requires: grep
%global _hardened_build 1
Patch1: 0001-tests-Handle-zero-directory-entry-in-.debug_line-DWA.patch
Patch2: 0002-scripts-find-debuginfo.in-Add-q-quiet.patch
Patch3: 0001-debugedit-Add-support-for-.debug_str_offsets-DW_FORM.patch
Patch4: 0003-elf_strptr.patch
Patch5: 0004-compress.patch
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
Patch11: 0001-Add-basic-find-debuginfo-script-tests.patch
Patch12: debugedit-5.0-find-debuginfo-tests-fixups.patch
%description
The debugedit project provides programs and scripts for creating
debuginfo and source file distributions, collect build-ids and rewrite
source paths in DWARF data for debugging, tracing and profiling.
It is based on code originally from the rpm project plus libiberty and
binutils. It depends on the elfutils libelf and libdw libraries to
read and write ELF files, DWARF data and build-ids.
%prep
%{gpgverify} --keyring='%{SOURCE2}' --signature='%{SOURCE1}' --data='%{SOURCE0}'
%autosetup -p1
%build
autoreconf -f -v -i
%configure
%make_build
%install
%make_install
# Temp symlink to make sure things don't break.
cd %{buildroot}%{_bindir}
ln -s find-debuginfo find-debuginfo.sh
%check
# The testsuite should be zero fail.
# It uses its own CFLAGS and LDFLAGS settings.
sed -i 's/^\(C\|LD\)FLAGS=.*/\1FLAGS=""/' tests/atlocal
make check %{?_smp_mflags}
%files
%license COPYING COPYING3 COPYING.LIB
%doc README
%{_bindir}/debugedit
%{_bindir}/sepdebugcrcfix
%{_bindir}/find-debuginfo
%{_bindir}/find-debuginfo.sh
%{_mandir}/man1/debugedit.1*
%{_mandir}/man1/sepdebugcrcfix.1*
%{_mandir}/man1/find-debuginfo.1*
%changelog
* Fri Jun 20 2025 Mark Wielaard <mjw@redhat.com> - 5.0-11
- Add 0001-Add-basic-find-debuginfo-script-tests.patch
- Add debugedit-5.0-find-debuginfo-tests-fixups.patch
* Thu Apr 17 2025 Martin Cermak <mcermak@redhat.com> - 5.0-10
- Add 0006-pr32157-handle-dwarf5-DW_UT_type-unit-type-2.patch
* Tue Apr 15 2025 Mark Wielaard <mjw@redhat.com> - 5.0-9
- Add 0001-find-debuginfo-Fix-skip_mini-.gnu_debugdata-handling.patch
* Fri Apr 11 2025 Mark Wielaard <mjw@redhat.com> - 5.0-8
- Add 0001-debug_str_offsets-header-version-and-padding-are-2-b.patch
- Add 0001-debugedit-Handle-unused-.debug_str_offsets-entries.patch
* Fri Mar 21 2025 Mark Wielaard <mjw@redhat.com> - 5.0-7
- Add 0005-writable.patch
* Fri Mar 21 2025 Mark Wielaard <mjw@redhat.com> - 5.0-6
- Add 0003-elf_strptr.patch
- Add 0004-compress.patch
* Mon Dec 4 2023 Mark Wielaard <mjw@redhat.com> - 5.0-5
- Add 0001-debugedit-Add-support-for-.debug_str_offsets-DW_FORM.patch
* Tue Mar 28 2023 Mark Wielaard <mjw@redhat.com> - 5.0-4
- Add 0002-scripts-find-debuginfo.in-Add-q-quiet.patch
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 5.0-3
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688
* Tue Aug 3 2021 Mark Wielaard <mjw@redhat.com> - 5.0-2
- Add testsuite fix for GCC 11.2.1
* Mon Jul 26 2021 Mark Wielaard <mjw@redhat.com> - 5.0-1
- Upgrade to upstream 5.0 release.
- Removes find-debuginfo .sh suffix.
- This release still has a find-debuginfo.sh -> find-debuginfo symlink.
* Wed May 5 2021 Mark Wielaard <mjw@fedoraproject.org> - 0.2-1
- Update to upstream 0.2 pre-release. Adds documentation.
* Wed Apr 28 2021 Mark Wielaard <mjw@fedoraproject.org> - 0.1-5
- Add dist to Release. Use file dependency for /usr/bin/gdb-add-index.
* Tue Apr 27 2021 Mark Wielaard <mjw@fedoraproject.org> - 0.1-4
- Use numbered Sources and https.
* Mon Apr 26 2021 Mark Wielaard <mjw@fedoraproject.org> - 0.1-3
- Fix some rpmlint issues, add comments, add license and doc,
gpg verification, use pkgconfig BuildRequires, enable _hardened_build
* Mon Mar 29 2021 Panu Matilainen <pmatilai@redhat.com>
- Add pile of missing runtime utility dependencies
* Tue Mar 23 2021 Panu Matilainen <pmatilai@redhat.com>
- Initial packaging

View File

@ -0,0 +1,107 @@
commit 737da0cb62a2bd614040c3e11b7016aca743c34f
Author: Mark Wielaard <mark@klomp.org>
Date: Thu Feb 20 16:30:07 2025 +0100
find-debuginfo: Allow overriding binutils tools
find-debuginfo relies on a couple of binutils tools (readelf, objcopy
and nm) that might not have been build with cross-arch support. Make
it possible to configure with specific (target) versions and to
override the specific binaries by setting READELF, OBJCOPY or NM
environment variables.
* Makefile.am (do_subst): Add OBJCOPY and NM substitutions.
* configure.ac: Add OBJCOPY and NM tools override.
* scripts/find-debuginfo.in: Allow READELF, OBJCOPY and NM
environment overrides.
Signed-off-by: Mark Wielaard <mark@klomp.org>
diff --git a/Makefile.am b/Makefile.am
index 35fd947f8db2..562ffa46fa30 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -34,6 +34,8 @@ CLEANFILES = $(bin_SCRIPTS)
do_subst = ($(SED) -e 's,[@]PACKAGE[@],$(PACKAGE),g' \
-e 's,[@]VERSION[@],$(VERSION),g' \
-e 's,[@]READELF[@],$(READELF),g' \
+ -e 's,[@]OBJCOPY[@],$(OBJCOPY),g' \
+ -e 's,[@]NM[@],$(NM),g' \
-e 's,[@]DWZ_J[@],$(DWZ_J),g')
find-debuginfo: $(top_srcdir)/scripts/find-debuginfo.in Makefile
diff --git a/configure.ac b/configure.ac
index 32dd27d287a3..ad4d70c63995 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,6 +45,8 @@ m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_C99])
AC_PROG_LN_S
AC_CHECK_TOOL([LD], [ld])
AC_CHECK_TOOL([READELF], [readelf])
+AC_CHECK_TOOL([OBJCOPY], [objcopy])
+AC_CHECK_TOOL([NM], [nm])
AM_MISSING_PROG(HELP2MAN, help2man)
# Whether dwz support -j.
diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in
index 7f2c00728b94..4cc49f2f8cd0 100755
--- a/scripts/find-debuginfo.in
+++ b/scripts/find-debuginfo.in
@@ -108,6 +108,14 @@ EOF
install_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PATH=${install_dir}:$PATH
+# A couple of binutils helper tools are used in this script.
+# Let the user override them by setting them in environment variables.
+# The default is the (target variant) of the tool found when debugedit
+# was configured.
+READELF=${READELF:=@READELF@}
+OBJCOPY=${OBJCOPY:=@OBJCOPY@}
+NM=${NM:=@NM@}
+
# With -g arg, pass it to strip on libraries or executables.
strip_g=false
@@ -360,7 +368,7 @@ add_minidebug()
# symbol and NOBITS sections so cannot use --keep-only because that is
# too aggressive. Field $2 is the section name, $3 is the section type
# and $8 are the section flags.
- local remove_sections=`@READELF@ -W -S "$debuginfo" \
+ local remove_sections=`${READELF} -W -S "$debuginfo" \
| awk '{ if (index($2,".debug_") != 1 \
&& ($3 == "PROGBITS" || $3 == "NOTE" || $3 == "NOBITS") \
&& index($8,"A") == 0) \
@@ -368,20 +376,20 @@ add_minidebug()
# Extract the dynamic symbols from the main binary, there is no need to also have these
# in the normal symbol table
- nm -D "$binary" --format=posix --defined-only | awk '{ print $1 }' | sort > "$dynsyms"
+ ${NM} -D "$binary" --format=posix --defined-only | awk '{ print $1 }' | sort > "$dynsyms"
# Extract all the text (i.e. function) symbols from the debuginfo
# Use format sysv to make sure we can match against the actual ELF FUNC
# symbol type. The binutils nm posix format symbol type chars are
# ambigous for architectures that might use function descriptors.
- nm "$debuginfo" --format=sysv --defined-only | awk -F \| '{ if ($4 ~ "FUNC") print $1 }' | sort > "$funcsyms"
+ ${NM} "$debuginfo" --format=sysv --defined-only | awk -F \| '{ if ($4 ~ "FUNC") print $1 }' | sort > "$funcsyms"
# Keep all the function symbols not already in the dynamic symbol table
comm -13 "$dynsyms" "$funcsyms" > "$keep_symbols"
# Copy the full debuginfo, keeping only a minumal set of symbols and removing some unnecessary sections
- objcopy -S $remove_sections --keep-symbols="$keep_symbols" "$debuginfo" "$mini_debuginfo" &> /dev/null
+ ${OBJCOPY} -S $remove_sections --keep-symbols="$keep_symbols" "$debuginfo" "$mini_debuginfo" &> /dev/null
#Inject the compressed data into the .gnu_debugdata section of the original binary
xz "$mini_debuginfo"
mini_debuginfo="${mini_debuginfo}.xz"
- objcopy --add-section .gnu_debugdata="$mini_debuginfo" "$binary"
+ ${OBJCOPY} --add-section .gnu_debugdata="$mini_debuginfo" "$binary"
rm -f "$dynsyms" "$funcsyms" "$keep_symbols" "$mini_debuginfo"
}
@@ -516,7 +524,7 @@ do_file()
if test "$f_writable" = "false"; then
chmod u+w "$f"
fi
- objcopy --merge-notes "$f" 2>/dev/null || true
+ ${OBJCOPY} --merge-notes "$f" 2>/dev/null || true
if test "$f_writable" = "false"; then
chmod u-w "$f"
fi

200
debugedit.spec Normal file
View File

@ -0,0 +1,200 @@
Name: debugedit
Version: 5.1
Release: 8%{?dist}
Summary: Tools and scripts for creating debuginfo and source file distributions, collect build-ids and rewrite source paths in DWARF data for debugging, tracing and profiling.
License: GPL-3.0-or-later AND GPL-2.0-or-later AND LGPL-2.0-or-later
URL: https://sourceware.org/debugedit/
Source0: https://sourceware.org/pub/debugedit/%{version}/%{name}-%{version}.tar.xz
Source1: https://sourceware.org/pub/debugedit/%{version}/%{name}-%{version}.tar.xz.sig
Source2: gpgkey-5C1D1AA44BE649DE760A.gpg
BuildRequires: make gcc
BuildRequires: pkgconfig(libelf)
BuildRequires: pkgconfig(libdw)
BuildRequires: help2man
BuildRequires: gnupg2
# For configure checking -j support
BuildRequires: dwz
# For debugedit build-id recomputation
BuildRequires: xxhash-devel
# debugedit builds with XXH_INLINE_ALL, so depend on (virtual) xxhash-static
BuildRequires: xxhash-static
# For the testsuite.
BuildRequires: autoconf
BuildRequires: automake
# The find-debuginfo.sh script has a couple of tools it needs at runtime.
# For strip_to_debug, eu-strip
Requires: elfutils
# For add_minidebug, readelf, awk, nm, sort, comm, objcopy, xz
Requires: binutils, gawk, coreutils, xz
# For find and xargs
Requires: findutils
# For do_file, gdb_add_index
# We only need gdb-add-index, so suggest gdb-minimal (full gdb is also ok)
Requires: /usr/bin/gdb-add-index
Suggests: gdb-minimal
# For run_job, sed
Requires: sed
# For dwz
Requires: dwz
# For append_uniq, grep
Requires: grep
%global _hardened_build 1
Patch1: 0001-find-debuginfo-Check-files-are-writable-before-modif.patch
Patch2: 0001-find-debuginfo-Fix-skip_mini-.gnu_debugdata-handling.patch
patch3: 0001-find-debuginfo-Make-return-from-do_file-explicit.patch
patch4: debugedit-5.1-binutils-tools-override.patch
patch5: 0001-debugedit-Handle-unused-.debug_str_offsets-entries.patch
patch6: 0001-Add-basic-find-debuginfo-script-tests.patch
%description
The debugedit project provides programs and scripts for creating
debuginfo and source file distributions, collect build-ids and rewrite
source paths in DWARF data for debugging, tracing and profiling.
It is based on code originally from the rpm project plus libiberty and
binutils. It depends on the elfutils libelf and libdw libraries to
read and write ELF files, DWARF data and build-ids.
%prep
%{gpgverify} --keyring='%{SOURCE2}' --signature='%{SOURCE1}' --data='%{SOURCE0}'
%autosetup -p1
%build
autoreconf -f -v -i
%configure
%make_build
%install
%make_install
# Temp symlink to make sure things don't break.
cd %{buildroot}%{_bindir}
ln -s find-debuginfo find-debuginfo.sh
%check
# The testsuite should be zero fail.
make check %{?_smp_mflags}
%files
%license COPYING COPYING3 COPYING.LIB
%doc README
%{_bindir}/debugedit
%{_bindir}/sepdebugcrcfix
%{_bindir}/find-debuginfo
%{_bindir}/find-debuginfo.sh
%{_mandir}/man1/debugedit.1*
%{_mandir}/man1/sepdebugcrcfix.1*
%{_mandir}/man1/find-debuginfo.1*
%changelog
* Fri Jun 20 2025 Mark Wielaard <mjw@redhat.com> - 5.1-8
- Add 0001-Add-basic-find-debuginfo-script-tests.patch
* Fri Apr 11 2025 Mark Wielaard <mjw@redhat.com> - 5.1-7
- Add 0001-debugedit-Handle-unused-.debug_str_offsets-entries.patch
* Fri Mar 21 2025 Martin Cermak <mcermak@redhat.com> - 5.1-6
- NVR bump and rebuild for RHEL-10.1
* Mon Mar 3 2025 Mark Wielaard <mjw@redhat.com> - 5.1-5
- Add debugedit-5.1-binutils-tools-override.patch
* Thu Jan 16 2025 Mark Wielaard <mjw@redhat.com> - 5.1-4
- Add 0001-find-debuginfo-Make-return-from-do_file-explicit.patch
* Thu Jan 16 2025 Mark Wielaard <mjw@redhat.com> - 5.1-3
- Add 0001-find-debuginfo-Fix-skip_mini-.gnu_debugdata-handling.patch
* Thu Nov 28 2024 Mark Wielaard <mjw@redhat.com> - 5.1-2
- Add 0001-find-debuginfo-Check-files-are-writable-before-modif.patch
* Tue Oct 29 2024 Mark Wielaard <mjw@redhat.com> - 5.1-1
- New upstream 5.1 release
- Drop all local patches
* Tue Oct 29 2024 Troy Dawson <tdawson@redhat.com> - 5.0-16
- Bump release for October 2024 mass rebuild:
Resolves: RHEL-64018
* Mon Jun 24 2024 Troy Dawson <tdawson@redhat.com> - 5.0-15
- Bump release for June 2024 mass rebuild
* Wed Jan 24 2024 Fedora Release Engineering <releng@fedoraproject.org> - 5.0-14
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild
* Fri Jan 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 5.0-13
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild
* Mon Dec 4 2023 Mark Wirlaard <mjw@fedoraproject.org> - 5.0-12
- Add 0001-debugedit-Add-support-for-.debug_str_offsets-DW_FORM.patch
* Fri Nov 17 2023 Mark Wirlaard <mjw@fedoraproject.org> - 5.0-11
- migrated to SPDX license
* Wed Jul 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 5.0-10
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
* Fri Jun 30 2023 Mark Wielaard <mjw@fedoraproject.org> - 5.0-9
- Add 0001-find-debuginfo-Add-v-verbose-for-per-file-messages.patch
* Fri Jun 30 2023 Mark Wielaard <mjw@fedoraproject.org> - 5.0-8
- Add 0001-find-debuginfo-Prefix-install_dir-to-PATH.patch
* Fri Jan 27 2023 Mark Wielaard <mjw@fedoraproject.org> - 5.0-7
- Refresh 0001-tests-Handle-zero-directory-entry-in-.debug_line-DWA.patch
- Add new upstream patches:
0001-use-READELF-not-readelf.patch
0001-find-debuginfo-Pass-j-down-to-dwz.patch
0002-configure.ac-Use-AC_LINK_IFELSE-for-gz-none-check.patch
0003-configure.ac-Use-AC_LANG_PROGRAM-for-AC_LINK_IFELSE-.patch
0004-scripts-find-debuginfo.in-Add-q-quiet.patch
* Thu Jan 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 5.0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild
* Thu Jul 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 5.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
* Tue May 10 2022 Romanos Skiadas <rom.skiad@gmail.com> - 5.0-4
- Remove CFLAGS/LDFLAGS sed as they are already set to "" by debugedit
* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 5.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
* Fri Jul 30 2021 Mark Wielaard <mjw@fedoraproject.org> - 5.0-2
- Add testsuite fix for GCC 11.2.1
* Mon Jul 26 2021 Mark Wielaard <mjw@fedoraproject.org> - 5.0-1
- Upgrade to upstream 5.0 release.
* Wed Jul 21 2021 Fedora Release Engineering <releng@fedoraproject.org> - 0.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
* Thu Jun 17 2021 Mark Wielaard <mjw@fedoraproject.org> - 0.3-1
- Update to upstream 0.3 pre-release. Removes find-debuginfo .sh suffix.
- This release still has a find-debuginfo.sh -> find-debuginfo symlink.
* Wed May 5 2021 Mark Wielaard <mjw@fedoraproject.org> - 0.2-1
- Update to upstream 0.2 pre-release. Adds documentation.
* Wed Apr 28 2021 Mark Wielaard <mjw@fedoraproject.org> - 0.1-5
- Add dist to Release. Use file dependency for /usr/bin/gdb-add-index.
* Tue Apr 27 2021 Mark Wielaard <mjw@fedoraproject.org> - 0.1-4
- Use numbered Sources and https.
* Mon Apr 26 2021 Mark Wielaard <mjw@fedoraproject.org> - 0.1-3
- Fix some rpmlint issues, add comments, add license and doc,
gpg verification, use pkgconfig BuildRequires, enable _hardened_build
* Mon Mar 29 2021 Panu Matilainen <pmatilai@redhat.com>
- Add pile of missing runtime utility dependencies
* Tue Mar 23 2021 Panu Matilainen <pmatilai@redhat.com>
- Initial packaging

6
gating.yaml Normal file
View File

@ -0,0 +1,6 @@
--- !Policy
product_versions:
- rhel-10
decision_context: osci_compose_gate
rules:
- !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}

Binary file not shown.

8
plans/ci.fmf Normal file
View File

@ -0,0 +1,8 @@
summary: CI Gating Plan
discover:
how: fmf
url: https://gitlab.cee.redhat.com/toolchain-qe/tests/debugedit.git
ref: main
directory: tests
execute:
how: tmt

2
sources Normal file
View File

@ -0,0 +1,2 @@
SHA512 (debugedit-5.1.tar.xz) = 72f4dcc0fba223a85d261aa38400e229f04c7c96adafe455919a8f702d3d7d9cdfb991b403d53f2ac4948ca19eeb43d3d49c0ea2616065657c120647a30575d3
SHA512 (debugedit-5.1.tar.xz.sig) = 8fc5072f05df2df630994844bd758dece9479c5f68182c10fd7ba4bc1c9a9601f6e399a2ad3146e58cdef75aa36871b642b64cb53c42cedfb05b310773994e5f