Don not compress if section already compressed unless forced

(cherry picked from commit c377eb6e2750fed7d5e44321b07f1542df5280ee)
This commit is contained in:
zhangruifang2020 2023-08-29 14:52:56 +08:00 committed by openeuler-sync-bot
parent ce61b860a0
commit 1415db7303
2 changed files with 104 additions and 1 deletions

View File

@ -0,0 +1,95 @@
From 6cad4e56a930034765f8e79ba2eaa2ff1cd8394f Mon Sep 17 00:00:00 2001
From: Mark Wielaard <mark@klomp.org>
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 <mark@klomp.org>
---
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

View File

@ -1,7 +1,7 @@
# -*- rpm-spec from http://elfutils.org/ -*- # -*- rpm-spec from http://elfutils.org/ -*-
Name: elfutils Name: elfutils
Version: 0.189 Version: 0.189
Release: 1 Release: 2
Summary: A collection of utilities and DSOs to handle ELF files and DWARF data Summary: A collection of utilities and DSOs to handle ELF files and DWARF data
URL: http://elfutils.org/ URL: http://elfutils.org/
License: GPLv3+ and (GPLv2+ or LGPLv3+) 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 Patch0: Fix-segfault-in-eu-ar-m.patch
Patch1: Fix-error-of-parsing-object-file-perms.patch Patch1: Fix-error-of-parsing-object-file-perms.patch
Patch2: Fix-issue-of-moving-files-by-ar-or-br.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-libelf = %{version}-%{release}
Requires: elfutils-libs = %{version}-%{release} Requires: elfutils-libs = %{version}-%{release}
@ -171,6 +172,7 @@ such servers to download those files on demand.
%patch0 -p1 %patch0 -p1
%patch1 -p1 %patch1 -p1
%patch2 -p1 %patch2 -p1
%patch3 -p1
%build %build
%if "%toolchain" == "clang" %if "%toolchain" == "clang"
@ -325,6 +327,12 @@ exit 0
%systemd_postun_with_restart debuginfod.service %systemd_postun_with_restart debuginfod.service
%changelog %changelog
* Tue Aug 29 2023 zhangruifang <zhangruifang1@h-partners.com> - 0.189-2
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:Don not compress if section already compressed unless forced
* Thu Jul 13 2023 fuanan <fuanan3@h-partners.com> - 0.189-1 * Thu Jul 13 2023 fuanan <fuanan3@h-partners.com> - 0.189-1
- Type:enhancement - Type:enhancement
- CVE:NA - CVE:NA