From 010be1a119b5dd9eb8cc92ef1faa8cf563dc5380 Mon Sep 17 00:00:00 2001 From: linzhuorong Date: Wed, 30 Nov 2022 15:36:14 +0800 Subject: [PATCH 1/2] [Backport] readelf: Handle DW_LLE_GNU_view_pair Signed-off-by: linzhuorong --- ...-readelf-Handle-DW_LLE_GNU_view_pair.patch | 71 +++++++++++++++++++ elfutils.spec | 9 ++- 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 backport-readelf-Handle-DW_LLE_GNU_view_pair.patch diff --git a/backport-readelf-Handle-DW_LLE_GNU_view_pair.patch b/backport-readelf-Handle-DW_LLE_GNU_view_pair.patch new file mode 100644 index 0000000..c8dec86 --- /dev/null +++ b/backport-readelf-Handle-DW_LLE_GNU_view_pair.patch @@ -0,0 +1,71 @@ +From 4f97f4200f0e8a535cf045d5cb48edf50d67fa17 Mon Sep 17 00:00:00 2001 +From: Mark Wielaard +Date: Thu, 20 Oct 2022 00:02:39 +0200 +Subject: [PATCH] readelf: Handle DW_LLE_GNU_view_pair + +DW_LLE_GNU_view_pair is used by gcc -gvariable-location-views=incompat5. +As described in http://www.fsfla.org/~lxoliva/papers/sfn/dwarf6-sfn-lvu.txt +and proposed for DWARF6 https://dwarfstd.org/ShowIssue.php?issue=170427.1 + +Reference:https://sourceware.org/git/?p=elfutils.git;a=commit;h=85f4c22f60c87bd2f67b241974f1b5f0f355a29b + +Conflict: +libdw/ChangLog +src/ChangeLog + +Signed-off-by: Mark Wielaard +--- + libdw/dwarf.h | 6 +++++- + src/readelf.c | 12 ++++++++++++ + 2 files changed, 17 insertions(+), 1 deletion(-) + +diff --git a/libdw/dwarf.h b/libdw/dwarf.h +index 19a4be9..89af5cd 100644 +--- a/libdw/dwarf.h ++++ b/libdw/dwarf.h +@@ -927,7 +927,11 @@ enum + DW_LLE_GNU_end_of_list_entry = 0x0, + DW_LLE_GNU_base_address_selection_entry = 0x1, + DW_LLE_GNU_start_end_entry = 0x2, +- DW_LLE_GNU_start_length_entry = 0x3 ++ DW_LLE_GNU_start_length_entry = 0x3, ++ ++ // http://www.fsfla.org/~lxoliva/papers/sfn/dwarf6-sfn-lvu.txt ++ // https://dwarfstd.org/ShowIssue.php?issue=170427.1 ++ DW_LLE_GNU_view_pair = 0x9 + }; + + +diff --git a/src/readelf.c b/src/readelf.c +index 9b47262..c19b0a5 100644 +--- a/src/readelf.c ++++ b/src/readelf.c +@@ -4120,6 +4120,8 @@ dwarf_loc_list_encoding_string (unsigned int kind) + #define DWARF_ONE_KNOWN_DW_LLE(NAME, CODE) case CODE: return #NAME; + DWARF_ALL_KNOWN_DW_LLE + #undef DWARF_ONE_KNOWN_DW_LLE ++ /* DW_LLE_GNU_view_pair is special/incompatible with default codes. */ ++ case DW_LLE_GNU_view_pair: return "GNU_view_pair"; + default: + return NULL; + } +@@ -9514,6 +9516,16 @@ print_debug_loclists_section (Dwfl_Module *dwflmod, + readp += len; + break; + ++ case DW_LLE_GNU_view_pair: ++ if ((uint64_t) (nexthdr - readp) < 1) ++ goto invalid_entry; ++ get_uleb128 (op1, readp, nexthdr); ++ if ((uint64_t) (nexthdr - readp) < 1) ++ goto invalid_entry; ++ get_uleb128 (op2, readp, nexthdr); ++ printf (" %" PRIx64 ", %" PRIx64 "\n", op1, op2); ++ break; ++ + default: + goto invalid_entry; + } +-- +2.27.0 + diff --git a/elfutils.spec b/elfutils.spec index ecd7d3b..9f949be 100644 --- a/elfutils.spec +++ b/elfutils.spec @@ -1,7 +1,7 @@ # -*- rpm-spec from http://elfutils.org/ -*- Name: elfutils Version: 0.185 -Release: 14 +Release: 15 Summary: A collection of utilities and DSOs to handle ELF files and DWARF data URL: http://elfutils.org/ License: GPLv3+ and (GPLv2+ or LGPLv3+) @@ -12,6 +12,7 @@ Patch1: Fix-segfault-in-eu-ar-m.patch Patch2: Fix-error-of-parsing-object-file-perms.patch Patch3: Fix-issue-of-moving-files-by-ar-or-br.patch Patch4: Get-instance-correctly-for-eu-ar-N-option.patch +Patch5: backport-readelf-Handle-DW_LLE_GNU_view_pair.patch Provides: elfutils-libelf elfutils-default-yama-scope default-yama-scope elfutils-libs Obsoletes: elfutils-libelf < %{version}-%{release} elfutils-default-yama-scope < %{version}-%{release} elfutils-libs < %{version}-%{release} @@ -254,6 +255,12 @@ exit 0 %systemd_postun_with_restart debuginfod.service %changelog +* Wed Nov 30 2022 linzhuorong - 0.185-15 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:readelf: Handle DW_LLE_GNU_view_pair + * Fri Sep 30 2022 hubin - 0.185-14 - Type:bugfix - ID:NA -- Gitee From 63fe559af0ea65c86fa6c55ea1b8dde1bfe9cb6f Mon Sep 17 00:00:00 2001 From: linzhuorong Date: Wed, 30 Nov 2022 08:32:38 +0000 Subject: [PATCH 2/2] [Backport] ar: Correct -N COUNT off-by-one Signed-off-by: linzhuorong --- backport-ar-Correct-N-COUNT-off-by-one.patch | 144 +++++++++++++++++++ elfutils.spec | 9 +- 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 backport-ar-Correct-N-COUNT-off-by-one.patch diff --git a/backport-ar-Correct-N-COUNT-off-by-one.patch b/backport-ar-Correct-N-COUNT-off-by-one.patch new file mode 100644 index 0000000..d1c99d1 --- /dev/null +++ b/backport-ar-Correct-N-COUNT-off-by-one.patch @@ -0,0 +1,144 @@ +From e18ea521e0bf16a939bfe0cbbbccbccf0399e2c9 Mon Sep 17 00:00:00 2001 +From: Mark Wielaard +Date: Sun, 28 Aug 2022 17:46:08 +0200 +Subject: [PATCH] ar: Correct -N COUNT off-by-one + +When using instance [COUNT], the instance check is wrong. +instance-- == 0 should be --instance == 0. + +Add a testcase run-ar-N.sh that uses -N COUNT with extract and delete +operations checking the right instance was extracted and deleted. + +https://sourceware.org/bugzilla/show_bug.cgi?id=28725 + +Reference: https://sourceware.org/git/?p=elfutils.git;a=commit;h=6cb01b4ef3cdd4f83d21bbcec72fa66712ac14e6 + +Conflict: +src/ChangeLog +tests/ChangeLog + +Reported-by: panxiaohe +Signed-off-by: Mark Wielaard +--- + src/ar.c | 4 ++-- + tests/Makefile.am | 2 ++ + tests/run-ar-N.sh | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 3 files changed, 69 insertions(+), 2 deletions(-) + create mode 100755 tests/run-ar-N.sh + +diff --git a/src/ar.c b/src/ar.c +index 771f631..f94fa2c 100644 +--- a/src/ar.c ++++ b/src/ar.c +@@ -519,7 +519,7 @@ do_oper_extract (int oper, const char *arfname, char **argv, int argc, + ENTRY entry; + entry.key = arhdr->ar_name; + ENTRY *res = hsearch (entry, FIND); +- if (res != NULL && (instance < 0 || instance-- == 0) ++ if (res != NULL && (instance < 0 || --instance == 0) + && !found[(char **) res->data - argv]) + found[(char **) res->data - argv] = do_extract = true; + } +@@ -954,7 +954,7 @@ do_oper_delete (const char *arfname, char **argv, int argc, + ENTRY entry; + entry.key = arhdr->ar_name; + ENTRY *res = hsearch (entry, FIND); +- if (res != NULL && (instance < 0 || instance-- == 0) ++ if (res != NULL && (instance < 0 || --instance == 0) + && !found[(char **) res->data - argv]) + found[(char **) res->data - argv] = do_delete = true; + } +diff --git a/tests/Makefile.am b/tests/Makefile.am +index dc7517d..5fddb62 100644 +--- a/tests/Makefile.am ++++ b/tests/Makefile.am +@@ -93,6 +93,7 @@ test-nlist$(EXEEXT): test-nlist.c + $(test_nlist_CFLAGS) $(GCOV_FLAGS) -o $@ $< $(test_nlist_LDADD) + + TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ ++ run-ar-N.sh \ + update1 update2 update3 update4 \ + run-show-die-info.sh run-get-files.sh run-get-lines.sh \ + run-next-files.sh run-next-lines.sh \ +@@ -215,6 +216,7 @@ endif + endif + + EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ ++ run-ar-N.sh \ + run-show-die-info.sh run-get-files.sh run-get-lines.sh \ + run-next-files.sh run-next-lines.sh testfile-only-debug-line.bz2 \ + run-get-pubnames.sh run-get-aranges.sh \ +diff --git a/tests/run-ar-N.sh b/tests/run-ar-N.sh +new file mode 100755 +index 0000000..de8f62b +--- /dev/null ++++ b/tests/run-ar-N.sh +@@ -0,0 +1,65 @@ ++#! /usr/bin/env bash ++# Copyright (C) 2022 Mark J. Wielaard ++# This file is part of elfutils. ++# ++# This file is free software; you can redistribute it and/or modify ++# it under the terms of the GNU General Public License as published by ++# the Free Software Foundation; either version 3 of the License, or ++# (at your option) any later version. ++# ++# elfutils is distributed in the hope that it will be useful, but ++# WITHOUT ANY WARRANTY; without even the implied warranty of ++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++# GNU General Public License for more details. ++# ++# You should have received a copy of the GNU General Public License ++# along with this program. If not, see . ++ ++. $srcdir/test-subr.sh ++ ++tempfiles testfile test.ar ++ ++echo create test.ar with 3 testfile ++echo 1 > testfile ++testrun ${abs_top_builddir}/src/ar -vr test.ar testfile ++echo 2 > testfile ++testrun ${abs_top_builddir}/src/ar -vq test.ar testfile ++testrun ${abs_top_builddir}/src/ar -t test.ar ++echo 3 > testfile ++testrun ${abs_top_builddir}/src/ar -vq test.ar testfile ++testrun_compare ${abs_top_builddir}/src/ar -t test.ar << EOF ++testfile ++testfile ++testfile ++EOF ++ ++echo list content of testfile 1 2 3 ++testrun ${abs_top_builddir}/src/ar -vx -N 1 test.ar testfile ++diff -u testfile - << EOF ++1 ++EOF ++testrun ${abs_top_builddir}/src/ar -vx -N 2 test.ar testfile ++diff -u testfile - << EOF ++2 ++EOF ++testrun ${abs_top_builddir}/src/ar -vx -N 3 test.ar testfile ++diff -u testfile - << EOF ++3 ++EOF ++ ++echo delete testfile 2 ++testrun ${abs_top_builddir}/src/ar -vd -N 2 test.ar testfile ++testrun_compare ${abs_top_builddir}/src/ar -t test.ar << EOF ++testfile ++testfile ++EOF ++testrun ${abs_top_builddir}/src/ar -vx -N 1 test.ar testfile ++diff -u testfile - << EOF ++1 ++EOF ++testrun ${abs_top_builddir}/src/ar -vx -N 2 test.ar testfile ++diff -u testfile - << EOF ++3 ++EOF ++ ++exit 0 +-- +2.12.3 + diff --git a/elfutils.spec b/elfutils.spec index 9f949be..2436434 100644 --- a/elfutils.spec +++ b/elfutils.spec @@ -1,7 +1,7 @@ # -*- rpm-spec from http://elfutils.org/ -*- Name: elfutils Version: 0.185 -Release: 15 +Release: 16 Summary: A collection of utilities and DSOs to handle ELF files and DWARF data URL: http://elfutils.org/ License: GPLv3+ and (GPLv2+ or LGPLv3+) @@ -13,6 +13,7 @@ Patch2: Fix-error-of-parsing-object-file-perms.patch Patch3: Fix-issue-of-moving-files-by-ar-or-br.patch Patch4: Get-instance-correctly-for-eu-ar-N-option.patch Patch5: backport-readelf-Handle-DW_LLE_GNU_view_pair.patch +Patch6: backport-ar-Correct-N-COUNT-off-by-one.patch Provides: elfutils-libelf elfutils-default-yama-scope default-yama-scope elfutils-libs Obsoletes: elfutils-libelf < %{version}-%{release} elfutils-default-yama-scope < %{version}-%{release} elfutils-libs < %{version}-%{release} @@ -255,6 +256,12 @@ exit 0 %systemd_postun_with_restart debuginfod.service %changelog +* Wed Nov 30 2022 linzhuorong - 0.185-16 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:ar: Correct -N COUNT off-by-one + * Wed Nov 30 2022 linzhuorong - 0.185-15 - Type:bugfix - ID:NA -- Gitee