public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] elfcompress: Don't compress if section already compressed unless forced
@ 2023-04-21 23:45 Mark Wielaard
  2023-05-08 16:16 ` Mark Wielaard
  0 siblings, 1 reply; 2+ messages in thread
From: Mark Wielaard @ 2023-04-21 23:45 UTC (permalink / raw)
  To: elfutils-devel; +Cc: Mark Wielaard

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.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] elfcompress: Don't compress if section already compressed unless forced
  2023-04-21 23:45 [PATCH] elfcompress: Don't compress if section already compressed unless forced Mark Wielaard
@ 2023-05-08 16:16 ` Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2023-05-08 16:16 UTC (permalink / raw)
  To: elfutils-devel

Hi,

On Sat, 2023-04-22 at 01:45 +0200, Mark Wielaard wrote:
> 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"));
>         }
> +   }

This was tested in Fedora and I now pushed it.

Cheers,

Mark

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-08 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-21 23:45 [PATCH] elfcompress: Don't compress if section already compressed unless forced Mark Wielaard
2023-05-08 16:16 ` Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).