From c377eb6e2750fed7d5e44321b07f1542df5280ee Mon Sep 17 00:00:00 2001 From: zhangruifang2020 Date: Tue, 29 Aug 2023 14:52:56 +0800 Subject: [PATCH] Don not compress if section already compressed unless forced --- ...t-compress-if-section-already-compre.patch | 95 +++++++++++++++++++ elfutils.spec | 10 +- 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 backport-elfcompress-Don-t-compress-if-section-already-compre.patch diff --git a/backport-elfcompress-Don-t-compress-if-section-already-compre.patch b/backport-elfcompress-Don-t-compress-if-section-already-compre.patch new file mode 100644 index 0000000..b635240 --- /dev/null +++ b/backport-elfcompress-Don-t-compress-if-section-already-compre.patch @@ -0,0 +1,95 @@ +From 6cad4e56a930034765f8e79ba2eaa2ff1cd8394f Mon Sep 17 00:00:00 2001 +From: Mark Wielaard +Date: Sat, 22 Apr 2023 01:45:43 +0200 +Subject: [PATCH] elfcompress: Don't compress if section already compressed + unless forced + +Before commit a5b07cdf9 "support ZSTD compression algorithm" +elfcompress would not try to compress a section if it already +had the requested compression type (or was already uncompressed) +unless the --force flag was given. An else if construct was changed +to an if in the commit causing elfcompress to warn (in verbose mode) +but then still try to (re)compress the section. + +Add an explicit check so if nothing needs (un)compressing, the file +isn't changed. + +The diff looks large, but git diff -b -w is just: + ++ if (force || type != schtype) ++ { + if (shdr->sh_type != SHT_NOBITS + && (shdr->sh_flags & SHF_ALLOC) == 0) + { +@@ -554,6 +556,7 @@ process_file (const char *fname) + printf ("[%zd] %s ignoring %s section\n", ndx, sname, + (shdr->sh_type == SHT_NOBITS ? "no bits" : "allocated")); + } ++ } + +Signed-off-by: Mark Wielaard +--- + src/elfcompress.c | 43 +++++++++++++++++++++++-------------------- + 1 file changed, 23 insertions(+), 20 deletions(-) + +diff --git a/src/elfcompress.c b/src/elfcompress.c +index 18ade66f..f771b92a 100644 +--- a/src/elfcompress.c ++++ b/src/elfcompress.c +@@ -529,30 +529,33 @@ process_file (const char *fname) + } + } + +- if (shdr->sh_type != SHT_NOBITS +- && (shdr->sh_flags & SHF_ALLOC) == 0) ++ if (force || type != schtype) + { +- set_section (sections, ndx); +- /* Check if we might want to change this section name. */ +- if (! adjust_names +- && ((type != ZLIB_GNU +- && startswith (sname, ".zdebug")) +- || (type == ZLIB_GNU +- && startswith (sname, ".debug")))) +- adjust_names = true; +- +- /* We need a buffer this large if we change the names. */ +- if (adjust_names) ++ if (shdr->sh_type != SHT_NOBITS ++ && (shdr->sh_flags & SHF_ALLOC) == 0) + { +- size_t slen = strlen (sname); +- if (slen > maxnamelen) +- maxnamelen = slen; ++ set_section (sections, ndx); ++ /* Check if we might want to change this section name. */ ++ if (! adjust_names ++ && ((type != ZLIB_GNU ++ && startswith (sname, ".zdebug")) ++ || (type == ZLIB_GNU ++ && startswith (sname, ".debug")))) ++ adjust_names = true; ++ ++ /* We need a buffer this large if we change the names. */ ++ if (adjust_names) ++ { ++ size_t slen = strlen (sname); ++ if (slen > maxnamelen) ++ maxnamelen = slen; ++ } + } ++ else ++ if (verbose >= 0) ++ printf ("[%zd] %s ignoring %s section\n", ndx, sname, ++ (shdr->sh_type == SHT_NOBITS ? "no bits" : "allocated")); + } +- else +- if (verbose >= 0) +- printf ("[%zd] %s ignoring %s section\n", ndx, sname, +- (shdr->sh_type == SHT_NOBITS ? "no bits" : "allocated")); + } + + if (shdr->sh_type == SHT_SYMTAB) +-- +2.27.0 + diff --git a/elfutils.spec b/elfutils.spec index 4d514a1..2cffcd1 100644 --- a/elfutils.spec +++ b/elfutils.spec @@ -1,7 +1,7 @@ # -*- rpm-spec from http://elfutils.org/ -*- Name: elfutils Version: 0.189 -Release: 1 +Release: 2 Summary: A collection of utilities and DSOs to handle ELF files and DWARF data URL: http://elfutils.org/ License: GPLv3+ and (GPLv2+ or LGPLv3+) @@ -10,6 +10,7 @@ Source: ftp://sourceware.org/pub/elfutils/%{version}/elfutils-%{version}.tar.bz2 Patch0: Fix-segfault-in-eu-ar-m.patch Patch1: Fix-error-of-parsing-object-file-perms.patch Patch2: Fix-issue-of-moving-files-by-ar-or-br.patch +Patch3: backport-elfcompress-Don-t-compress-if-section-already-compre.patch Requires: elfutils-libelf = %{version}-%{release} Requires: elfutils-libs = %{version}-%{release} @@ -171,6 +172,7 @@ such servers to download those files on demand. %patch0 -p1 %patch1 -p1 %patch2 -p1 +%patch3 -p1 %build %if "%toolchain" == "clang" @@ -325,6 +327,12 @@ exit 0 %systemd_postun_with_restart debuginfod.service %changelog +* Tue Aug 29 2023 zhangruifang - 0.189-2 +- Type:bugfix +- CVE:NA +- SUG:NA +- DESC:Don not compress if section already compressed unless forced + * Thu Jul 13 2023 fuanan - 0.189-1 - Type:enhancement - CVE:NA -- Gitee