From patchwork Fri Apr 21 23:45:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Wielaard X-Patchwork-Id: 68152 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A62573857351 for ; Fri, 21 Apr 2023 23:45:58 +0000 (GMT) X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from gnu.wildebeest.org (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 653373858D20 for ; Fri, 21 Apr 2023 23:45:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 653373858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from csb.redhat.com (deer0x03.wildebeest.org [172.31.17.133]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 16BAA302BB02; Sat, 22 Apr 2023 01:45:50 +0200 (CEST) Received: by csb.redhat.com (Postfix, from userid 10916) id E4CEACEF4F; Sat, 22 Apr 2023 01:45:49 +0200 (CEST) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] elfcompress: Don't compress if section already compressed unless forced Date: Sat, 22 Apr 2023 01:45:43 +0200 Message-Id: <20230421234543.1052146-1-mark@klomp.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3036.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" 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)