From 9f91a3e7bb5ba4c2fd80beb142eceb2e5747db64 Mon Sep 17 00:00:00 2001 From: hugel <2712504175@qq.com> Date: Thu, 12 Dec 2024 16:16:51 +0800 Subject: [PATCH] backport patches from upstream --- ...heck-files-are-writable-before-modif.patch | 102 +++++++++++++++++ ...emove-duplicate-filenames-when-creat.patch | 36 ++++++ ...h-Exit-with-real-exit-status-in-para.patch | 107 ++++++++++++++++++ ...err-output-of-readelf-in-debugedit.a.patch | 0 debugedit.spec | 10 +- 5 files changed, 253 insertions(+), 2 deletions(-) create mode 100644 backport-find-debuginfo-Check-files-are-writable-before-modif.patch create mode 100644 backport-find-debuginfo-remove-duplicate-filenames-when-creat.patch create mode 100644 backport-find-debuginfo.sh-Exit-with-real-exit-status-in-para.patch rename tests-Ignore-stderr-output-of-readelf-in-debugedit.a.patch => backport-tests-Ignore-stderr-output-of-readelf-in-debugedit.a.patch (100%) diff --git a/backport-find-debuginfo-Check-files-are-writable-before-modif.patch b/backport-find-debuginfo-Check-files-are-writable-before-modif.patch new file mode 100644 index 0000000..b422f9e --- /dev/null +++ b/backport-find-debuginfo-Check-files-are-writable-before-modif.patch @@ -0,0 +1,102 @@ +From 971a74d79b48a19ff1446642f39b3c5a8a7db238 Mon Sep 17 00:00:00 2001 +From: Mark Wielaard +Date: Thu, 28 Nov 2024 17:58:54 +0100 +Subject: [PATCH] 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. + +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 +--- + 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 a360bf0..4e4ef5a 100755 +--- a/scripts/find-debuginfo.in ++++ b/scripts/find-debuginfo.in +@@ -481,14 +481,29 @@ do_file() + $strict && return 2 + fi + ++ # debugedit makes sure to to get write permission to the file and ++ # restores original state after modifications. Other utilities ++ # might not. ++ f_writable="false" ++ if test -w "$f"; then f_writable="true"; fi ++ + # Add .gdb_index if requested. + if $include_gdb_index; then + if type gdb-add-index >/dev/null 2>&1; then ++ if test "$f_writable" = "false"; then ++ chmod u+w "$f" ++ fi + 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" + return 2 +@@ -497,7 +512,13 @@ do_file() + + # Compress any annobin notes in the original binary. + # Ignore any errors, since older objcopy don't support --merge-notes. ++ if test "$f_writable" = "false"; then ++ chmod u+w "$f" ++ fi + objcopy --merge-notes "$f" 2>/dev/null || true ++ if test "$f_writable" = "false"; then ++ chmod u-w "$f" ++ fi + + # A binary already copied into /usr/lib/debug doesn't get stripped, + # just has its file names collected and adjusted. +@@ -507,7 +528,7 @@ do_file() + esac + + mkdir -p "${debugdn}" +- if test -w "$f"; then ++ if test "$f_writable" = "true"; then + strip_to_debug "${debugfn}" "$f" + else + chmod u+w "$f" +@@ -529,7 +550,15 @@ do_file() + application/x-executable*) skip_mini=false ;; + application/x-pie-executable*) skip_mini=false ;; + esac +- $skip_mini || add_minidebug "${debugfn}" "$f" ++ if test "$skip_mini" = "true"; then ++ if test "$f_writable" = "false"; then ++ chmod u+w "$f" ++ fi ++ add_minidebug "${debugfn}" "$f" ++ if test "$f_writable" = "false"; then ++ chmod u-w "$f" ++ fi ++ fi + fi + + echo "./${f#$RPM_BUILD_ROOT}" >> "$ELFBINSFILE" +-- +2.33.0 + diff --git a/backport-find-debuginfo-remove-duplicate-filenames-when-creat.patch b/backport-find-debuginfo-remove-duplicate-filenames-when-creat.patch new file mode 100644 index 0000000..2b333ae --- /dev/null +++ b/backport-find-debuginfo-remove-duplicate-filenames-when-creat.patch @@ -0,0 +1,36 @@ +From 41fc1335b8b364c95a8ee2ed2956bbdfe7957853 Mon Sep 17 00:00:00 2001 +From: Denys Vlasenko +Date: Wed, 14 Jun 2023 16:56:38 +0200 +Subject: [PATCH] find-debuginfo: remove duplicate filenames when creating + debugsources.list + +We remove duplicate filenames when we _process_ debugsources.list. +However, this means that momentarily we may have a very large +(in the range of *giga*bytes) debugsources.list. + +This is unnecessary, we can also remove dups when we *create* it. + +Signed-off-by: Denys Vlasenko +--- + scripts/find-debuginfo.in | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in +index 7dec3c3..e7ac095 100755 +--- a/scripts/find-debuginfo.in ++++ b/scripts/find-debuginfo.in +@@ -575,7 +575,10 @@ else + exit 1 + fi + done +- cat "$temp"/debugsources.* >"$SOURCEFILE" ++ # List of sources may have lots of duplicates. A kernel build was seen ++ # with this list reaching 448 megabytes in size. "sort" helps to not have ++ # _two_ sets of 448 megabytes of temp files here. ++ LC_ALL=C sort -z -u "$temp"/debugsources.* >"$SOURCEFILE" + cat "$temp"/elfbins.* >"$ELFBINSFILE" + fi + +-- +2.33.0 + diff --git a/backport-find-debuginfo.sh-Exit-with-real-exit-status-in-para.patch b/backport-find-debuginfo.sh-Exit-with-real-exit-status-in-para.patch new file mode 100644 index 0000000..2ba40f9 --- /dev/null +++ b/backport-find-debuginfo.sh-Exit-with-real-exit-status-in-para.patch @@ -0,0 +1,107 @@ +From dfe1f7ff30f4e0be538835fca1e6348723ea7aa7 Mon Sep 17 00:00:00 2001 +From: Keith Seitz +Date: Fri, 16 Aug 2024 11:54:20 -0700 +Subject: [PATCH] find-debuginfo.sh: Exit with real exit status in parallel + jobs + +Currently, when the script is executed in parallel (-jN), the +resulting exit status will always be 0. + +The script execs an appropriate number of clones of itself, calling +run_job to run the actual workload. This then calls do_file(), saving +the exit status into "res.$jobid". + +In do_file(), though, if an error occurs, exit is called. This causes +the entire exec'd shell to exit with status 0 (since there are almost +always echo calls as the last executed statement). The real exit +status is therefor never written to the "res.$jobid" files by run_job(). + +The simple solution is to use 'return' instead of 'exit'. A number +of minor adjustments are also made to propagate this properly so that +it is reported as the correct exit status. + +While at it, I've incorporated a patch for find-debuginfo/30505. +Using this patch and another patch to the RPM package (submitted as +github issue #3215), failures of gdb-add-index.sh will now properly fail +the build instead of being swallowed. It should be much easier for +developers to figure out why their builds have failed should gdb crash. + +Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30505 +Signed-off-by: Keith Seitz +--- + scripts/find-debuginfo.in | 23 ++++++++++++++++++----- + 1 file changed, 18 insertions(+), 5 deletions(-) + +diff --git a/scripts/find-debuginfo.in b/scripts/find-debuginfo.in +index ae0818f..5998b9d 100755 +--- a/scripts/find-debuginfo.in ++++ b/scripts/find-debuginfo.in +@@ -477,16 +477,20 @@ do_file() + -l "$SOURCEFILE" "$f") || exit + if [ -z "$id" ]; then + echo >&2 "*** ${strict_error}: No build ID note found in $f" +- $strict && exit 2 ++ $strict && return 2 + fi + + # Add .gdb_index if requested. + if $include_gdb_index; then + if type gdb-add-index >/dev/null 2>&1; then +- gdb-add-index "$f" ++ gdb-add-index "$f" || { ++ status=$? ++ echo >&2 "*** ERROR:: GDB exited with exit status $status during index generation" ++ return 2 ++ } + else + echo >&2 "*** ERROR: GDB index requested, but no gdb-add-index installed" +- exit 2 ++ return 2 + fi + fi + +@@ -547,6 +551,7 @@ run_job() + { + local jobid=$1 filenum + local SOURCEFILE=$temp/debugsources.$jobid ELFBINSFILE=$temp/elfbins.$jobid ++ local res=0 + + >"$SOURCEFILE" + >"$ELFBINSFILE" +@@ -558,8 +563,12 @@ run_job() + break + fi + do_file $(sed -n "$(( 0x$filenum )) p" "$temp/primary") ++ res=$? ++ if [ $res != 0 ]; then ++ break ++ fi + done +- echo 0 >"$temp/res.$jobid" ++ echo $res >"$temp/res.$jobid" + } + + n_files=$(wc -l <"$temp/primary") +@@ -570,6 +579,10 @@ fi + if [ $n_jobs -le 1 ]; then + while read nlinks inum f; do + do_file "$nlinks" "$inum" "$f" ++ res=$? ++ if [ "$res" != "0" ]; then ++ exit $res ++ fi + done <"$temp/primary" + else + for ((i = 1; i <= n_files; i++)); do +@@ -587,7 +600,7 @@ else + test -f "$f" || continue + res=$(< "$f") + if [ "$res" != "0" ]; then +- exit 1 ++ exit $res + fi + done + # List of sources may have lots of duplicates. A kernel build was seen +-- +2.33.0 + diff --git a/tests-Ignore-stderr-output-of-readelf-in-debugedit.a.patch b/backport-tests-Ignore-stderr-output-of-readelf-in-debugedit.a.patch similarity index 100% rename from tests-Ignore-stderr-output-of-readelf-in-debugedit.a.patch rename to backport-tests-Ignore-stderr-output-of-readelf-in-debugedit.a.patch diff --git a/debugedit.spec b/debugedit.spec index c044ec6..1605d1d 100644 --- a/debugedit.spec +++ b/debugedit.spec @@ -1,6 +1,6 @@ Name: debugedit Version: 5.0 -Release: 7 +Release: 8 Summary: Tools for debuginfo creation License: GPL-2.0-or-later and LGPL-2.1-only and GPL-3.0-only Group: Applications @@ -19,12 +19,15 @@ Requires: sed dwz grep Patch0: tests-Handle-zero-directory-entry-in-.debug_line-DWA.patch Patch1: find-debuginfo.sh-decompress-DWARF-compressed-ELF-se.patch -Patch2: tests-Ignore-stderr-output-of-readelf-in-debugedit.a.patch Patch1000: add-loongarch-support-not-upstream-modified.patch Patch1001: add-sw_64-support-not-upstream-modified.patch Patch6000: backport-Fix-u-option.patch +Patch6001: backport-tests-Ignore-stderr-output-of-readelf-in-debugedit.a.patch +Patch6002: backport-find-debuginfo-remove-duplicate-filenames-when-creat.patch +Patch6003: backport-find-debuginfo.sh-Exit-with-real-exit-status-in-para.patch +Patch6004: backport-find-debuginfo-Check-files-are-writable-before-modif.patch %description Debugedit provides programs and scripts for creating debuginfo and @@ -68,6 +71,9 @@ make check %{?_smp_mflags} %{_rpmconfigdir}/debugedit %changelog +* Thu Dec 12 2024 hugel - 5.0-8 +- backport patches from upstream + * Fri Nov 29 2024 laokz - 5.0-7 - backport upstream patch to avoid tests failure -- Gitee