From 66f76524de04c53c64fd52bf4a47fa6932a01c87 Mon Sep 17 00:00:00 2001 From: Nick Clifton Date: Wed, 18 Jan 2023 11:27:31 +0000 Subject: [PATCH] Speed up objcopy's note merging algorithm. (#29993) --- binutils-objcopy-note-merge-speedup.patch | 44 +++++++++++++++++++++++ binutils.spec | 9 ++++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 binutils-objcopy-note-merge-speedup.patch diff --git a/binutils-objcopy-note-merge-speedup.patch b/binutils-objcopy-note-merge-speedup.patch new file mode 100644 index 0000000..1827fc4 --- /dev/null +++ b/binutils-objcopy-note-merge-speedup.patch @@ -0,0 +1,44 @@ +--- binutils.orig/binutils/objcopy.c 2023-01-16 12:15:46.405649346 +0000 ++++ binutils-2.39/binutils/objcopy.c 2023-01-16 12:16:48.892667868 +0000 +@@ -2383,6 +2383,8 @@ merge_gnu_build_notes (bfd * ab + other note then if they are both of the same type (open + or func) then they can be merged and one deleted. If + they are of different types then they cannot be merged. */ ++ objcopy_internal_note * prev_note = NULL; ++ + for (pnote = pnotes; pnote < pnotes_end; pnote ++) + { + /* Skip already deleted notes. +@@ -2404,7 +2406,9 @@ merge_gnu_build_notes (bfd * ab + objcopy_internal_note * back; + + /* Rule 2: Check to see if there is an identical previous note. */ +- for (iter = 0, back = pnote - 1; back >= pnotes; back --) ++ for (iter = 0, back = prev_note ? prev_note : pnote - 1; ++ back >= pnotes; ++ back --) + { + if (is_deleted_note (back)) + continue; +@@ -2466,11 +2470,18 @@ merge_gnu_build_notes (bfd * ab + break; + } + } +-#if DEBUG_MERGE ++ ++ + if (! is_deleted_note (pnote)) +- merge_debug ("Unable to do anything with note at %#08lx\n", +- (pnote->note.namedata - (char *) contents) - 12); ++ { ++ /* Keep a pointer to this note, so that we can ++ start the next search for rule 2 matches here. */ ++ prev_note = pnote; ++#if DEBUG_MERGE ++ merge_debug ("Unable to do anything with note at %#08lx\n", ++ (pnote->note.namedata - (char *) contents) - 12); + #endif ++ } + } + + /* Resort the notes. */ diff --git a/binutils.spec b/binutils.spec index 62d7776..e337502 100644 --- a/binutils.spec +++ b/binutils.spec @@ -39,7 +39,7 @@ Summary: A GNU collection of binary utilities Name: binutils%{?name_cross}%{?_with_debug:-debug} Version: 2.39 -Release: 7%{?dist} +Release: 8%{?dist} License: GPLv3+ URL: https://sourceware.org/binutils @@ -315,6 +315,10 @@ Patch23: binutils-libiberty-configure-compile-warnings.patch # Lifetime: Fixed in 2.40 Patch24: binutils-CVE-2022-4285.patch +# Purpose: Speed up objcopy's note merging algorithm. +# Lifetime: Fixed in 2.41 +Patch25: binutils-objcopy-note-merge-speedup.patch + #---------------------------------------------------------------------------- Provides: bundled(libiberty) @@ -971,6 +975,9 @@ exit 0 #---------------------------------------------------------------------------- %changelog +* Mon Jan 16 2023 Nick Clifton - 2.39-8 +- Speed up objcopy's note merging algorithm. (#29993) + * Tue Dec 13 2022 Nick Clifton - 2.39-7 - Fix a potential dereference of a NULL pointer. (#2152946)