]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
elfcompress: Don't compress if section already compressed unless forced
authorMark Wielaard <mark@klomp.org>
Fri, 21 Apr 2023 23:45:43 +0000 (01:45 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 8 May 2023 16:14:15 +0000 (18:14 +0200)
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

index 18ade66f349c47284241296355d36c525728f981..f771b92afabf9974e3e2cf26d4ea3bd2bd7a3789 100644 (file)
@@ -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)