From patchwork Tue Oct 4 08:13:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 1671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp16246wrs; Tue, 4 Oct 2022 01:14:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4GgY5C4wfNRp1I0yUdDMHAiNhuXDywpY4Q+tkNqqDHA/yRSTfZP4im2nBrSpMX+RieIZNX X-Received: by 2002:a17:907:9493:b0:78d:1eca:1cda with SMTP id dm19-20020a170907949300b0078d1eca1cdamr243276ejc.407.1664871241422; Tue, 04 Oct 2022 01:14:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664871241; cv=none; d=google.com; s=arc-20160816; b=YSo1lFvjNRxi3d6x5CRM+BoBccVJz1BzVjw+7/Jm0alQeay88IYGcZEZhAFmuRRwdl ScKWXPnJFWOI6c/L4BGA9rFa8AmGC6IE+9NSa/IV4O3d4ak+ecJi+ySFB5CjOshuCXrO 7jlih7UMHn6JXid3mRJ0acksDGAudQA5oJUdO80wquyt6FgfiRi+A9/CTBwmB+UHPMYR +8tZYHKo1vfSbIjIzRczUkkxdyWz3wNaCic5WrCJaVUfCufQfrLLomAVuWdl9PN9AhPO Ia87F82arbS4tCFHKt3qwqJZuGT5zKZP9rk1fDK2XmC0ogTm0QK4e8ejS7+RsLQ09Aby 13og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=hUnIdLOWOaPHokJAdAskFPW7075EZY+oSzTrm8Oc71c=; b=TcuaoD/eCKJoVHxyf+28YLTHMmiIJu/WtAKnsSLD0As7jACRqCFyh+u4fZ27HdgKKf 9Vm4MjjZP48iMcqWAhL429PlaUmUbPzKT1SbXD2ZgujIMxgAPQMYQdZNXtDzR6x8yIWd ve/C37kgxGpVxUfcbVlxHGm03cz290JFgYcppJSwNnzTmeinTJ1Q2waMGNkGr+v5nvMZ MHIY7A+qgutm+dM2K6KQLaG5Tmf2m/a3DPh+t/zrN5kMgSfywowBjV/Pv6yneXtT5xHh 90OwPI5rr/gXk1nuKazIZ190W2o8fzZtSKxhWtYXlc5bb5uZK3/cKd9x6Vl6AA0Vh4op 7zyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ii1BMhTQ; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hp16-20020a1709073e1000b0078a802cce5dsi6494697ejc.592.2022.10.04.01.14.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 01:14:01 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=ii1BMhTQ; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 78260385383F for ; Tue, 4 Oct 2022 08:13:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78260385383F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1664871239; bh=hUnIdLOWOaPHokJAdAskFPW7075EZY+oSzTrm8Oc71c=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ii1BMhTQHiiS49mo0mZM5ZkrQWPGgaEzaORJuMgHgalGN0/Mh/0ZqArLp6k6R0KJl bcjpHih6XV24WOIvtjexQLbvlSGneWt2ZwgmON0fVayaa52z4ZY2yAdnWKb4aY2wMR 873MEJMmIkxHwLscvKmd/i60AZWvVD8vqtTqRdI4= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 5E6E5385E010 for ; Tue, 4 Oct 2022 08:13:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5E6E5385E010 Received: by mail-pl1-x634.google.com with SMTP id f23so12030589plr.6 for ; Tue, 04 Oct 2022 01:13:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=hUnIdLOWOaPHokJAdAskFPW7075EZY+oSzTrm8Oc71c=; b=4oQw/lXTFErLG9qbw4wSGtlJY5mCS7w2Pf6cRnqRXHO8eZCUL3eQCcShDqrmgYPEGQ rtQ421DPSIcLhYKFV581aPjBi3QsosXM+BEREsBprErgM0VZ0kPJL9xFQOqb5kuUEEiH J/ip6Zn4S479PoIsDzLvuzxq5XcBK2Nv+TVSsjfptKk0DgmKKyp9FQnN8sCMqQFSkOI1 OUCROutG4NaUwdvruLxtlAbGBAly4KpbAcGTF/lOLnkF5jpbREFdCOuYNJ55gDliid/w Q+XZZHTho+YnwC/rhSuoMbQhKN4dL142WNHzW0M8w88RW9ZCYLaUk33M3uaCxqnRB75N dxhA== X-Gm-Message-State: ACrzQf1Mi3/rZoP2nSFTdWxM+ISIHeVYE829LTUPN0OGoa2TeSCWi+sn POHMJsJ6RQUiQHWhJ5c9yS1XzKnIVIY= X-Received: by 2002:a17:902:6542:b0:172:95d8:a777 with SMTP id d2-20020a170902654200b0017295d8a777mr25610897pln.61.1664871219696; Tue, 04 Oct 2022 01:13:39 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:63b5:ea40:cab:894b]) by smtp.gmail.com with ESMTPSA id b15-20020a1709027e0f00b001752216ca51sm1346623plm.39.2022.10.04.01.13.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 01:13:39 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 931751142DF5; Tue, 4 Oct 2022 18:43:36 +1030 (ACDT) Date: Tue, 4 Oct 2022 18:43:36 +1030 To: binutils@sourceware.org Subject: Support objcopy changing compression to or from zstd Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745744026657204840?= X-GMAIL-MSGID: =?utf-8?q?1745744026657204840?= Commit 2cac01e3ffff lacked support for objcopy changing compression style. Add that support, which meant a rewrite of bfd_compress_section_contents. In the process I've fixed some memory leaks. * compress.c (bfd_is_section_compressed_info): Rename from bfd_is_section_compressed_with_header and add ch_type param to return compression header ch_type field. Update all callers. (decompress_section_contents): Remove buffer and size params. Rewrite. Update callers. (bfd_init_section_compress_status): Free contents on failure. (bfd_compress_section): Likewise. * elf.c (_bfd_elf_make_section_from_shdr): Support objcopy changing between any of the three compression schemes. Report "unable to compress/decompress" rather than "unable to initialize compress/decompress status" on compress/decompress failures. * bfd-in2.h: Regenerate. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 5c80956c79c..d9b49a8c820 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -7953,11 +7953,12 @@ bool bfd_get_full_section_contents void bfd_cache_section_contents (asection *sec, void *contents); -bool bfd_is_section_compressed_with_header +bool bfd_is_section_compressed_info (bfd *abfd, asection *section, int *compression_header_size_p, bfd_size_type *uncompressed_size_p, - unsigned int *uncompressed_alignment_power_p); + unsigned int *uncompressed_alignment_power_p, + unsigned int *ch_type); bool bfd_is_section_compressed (bfd *abfd, asection *section); diff --git a/bfd/compress.c b/bfd/compress.c index 0e75b687013..364df14142b 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -81,8 +81,7 @@ decompress_contents (bool is_zstd, bfd_byte *compressed_buffer, return inflateEnd (&strm) == Z_OK && rc == Z_OK && strm.avail_out == 0; } -/* Compress data of the size specified in @var{uncompressed_size} - and pointed to by @var{uncompressed_buffer} using zlib/zstd and store +/* Compress section contents using zlib/zstd and store as the contents field. This function assumes the contents field was allocated using bfd_malloc() or equivalent. @@ -90,111 +89,99 @@ decompress_contents (bool is_zstd, bfd_byte *compressed_buffer, compressed successfully. Otherwise return 0. */ static bfd_size_type -bfd_compress_section_contents (bfd *abfd, sec_ptr sec, - bfd_byte *uncompressed_buffer, - bfd_size_type uncompressed_size) +bfd_compress_section_contents (bfd *abfd, sec_ptr sec) { + bfd_byte *input_buffer; uLong compressed_size; bfd_byte *buffer; bfd_size_type buffer_size; - bool decompress; int zlib_size = 0; - int orig_compression_header_size; - bfd_size_type orig_uncompressed_size; - unsigned int orig_uncompressed_alignment_pow; - int header_size = bfd_get_compression_header_size (abfd, NULL); + int orig_header_size; + bfd_size_type uncompressed_size; + unsigned int uncompressed_alignment_pow; + unsigned int ch_type = 0; + int new_header_size = bfd_get_compression_header_size (abfd, NULL); bool compressed - = bfd_is_section_compressed_with_header (abfd, sec, - &orig_compression_header_size, - &orig_uncompressed_size, - &orig_uncompressed_alignment_pow); + = bfd_is_section_compressed_info (abfd, sec, + &orig_header_size, + &uncompressed_size, + &uncompressed_alignment_pow, + &ch_type); + bool update = false; + + /* We shouldn't be trying to decompress unsupported compressed sections. */ + if (compressed && orig_header_size < 0) + abort (); /* Either ELF compression header or the 12-byte, "ZLIB" + 8-byte size, overhead in .zdebug* section. */ - if (!header_size) - header_size = 12; + if (!new_header_size) + new_header_size = 12; + if (ch_type == 0) + orig_header_size = 12; + input_buffer = sec->contents; if (compressed) { - /* We shouldn't decompress unsupported compressed section. */ - if (orig_compression_header_size < 0) - abort (); - - /* Different compression schemes. Just move the compressed section - contents to the right position. */ - if (orig_compression_header_size == 0) - { - /* Convert it from .zdebug* section. Get the uncompressed - size first. We need to subtract the 12-byte overhead in - .zdebug* section. Set orig_compression_header_size to - the 12-bye overhead. */ - orig_compression_header_size = 12; - zlib_size = uncompressed_size - 12; - } - else - { - /* Convert it to .zdebug* section. */ - zlib_size = uncompressed_size - orig_compression_header_size; - } - - /* Add the header size. */ - compressed_size = zlib_size + header_size; - } - else - compressed_size = compressBound (uncompressed_size) + header_size; + zlib_size = sec->size - orig_header_size; + compressed_size = zlib_size + new_header_size; - /* Uncompress if it leads to smaller size. */ - if (compressed && compressed_size > orig_uncompressed_size) - { - decompress = true; - buffer_size = orig_uncompressed_size; - } - else - { - decompress = false; - buffer_size = compressed_size; - } - buffer = (bfd_byte *) bfd_alloc (abfd, buffer_size); - if (buffer == NULL) - return 0; + /* If we are converting between zlib-gnu and zlib-gabi then the + compressed contents just need to be moved. */ + update = (ch_type < ELFCOMPRESS_ZSTD + && (abfd->flags & BFD_COMPRESS_ZSTD) == 0); - if (compressed) - { - sec->size = orig_uncompressed_size; - if (decompress) + /* Uncompress when not just moving contents or when compressed + is not smaller than uncompressed. */ + if (!update || compressed_size >= uncompressed_size) { - if (!decompress_contents ( - sec->compress_status == DECOMPRESS_SECTION_ZSTD, - uncompressed_buffer + orig_compression_header_size, - zlib_size, buffer, buffer_size)) + buffer_size = uncompressed_size; + buffer = bfd_malloc (buffer_size); + if (buffer == NULL) + return 0; + + if (!decompress_contents (ch_type == ELFCOMPRESS_ZSTD, + input_buffer + orig_header_size, + zlib_size, buffer, buffer_size)) { bfd_set_error (bfd_error_bad_value); - bfd_release (abfd, buffer); + free (buffer); return 0; } - free (uncompressed_buffer); - bfd_set_section_alignment (sec, orig_uncompressed_alignment_pow); - + free (input_buffer); + bfd_set_section_alignment (sec, uncompressed_alignment_pow); sec->contents = buffer; sec->compress_status = COMPRESS_SECTION_DONE; - return orig_uncompressed_size; - } - else - { - bfd_update_compression_header (abfd, buffer, sec); - memmove (buffer + header_size, - uncompressed_buffer + orig_compression_header_size, - zlib_size); + sec->size = uncompressed_size; + input_buffer = buffer; } } + + if (!update) + compressed_size = compressBound (uncompressed_size) + new_header_size; + + buffer_size = compressed_size; + buffer = bfd_alloc (abfd, buffer_size); + if (buffer == NULL) + return 0; + + if (update) + { + if (compressed_size < uncompressed_size) + memcpy (buffer + new_header_size, + input_buffer + orig_header_size, + zlib_size); + } else { if (abfd->flags & BFD_COMPRESS_ZSTD) { #if HAVE_ZSTD - compressed_size = ZSTD_compress ( - buffer + header_size, compressed_size, uncompressed_buffer, - uncompressed_size, ZSTD_CLEVEL_DEFAULT); + compressed_size = ZSTD_compress (buffer + new_header_size, + compressed_size, + input_buffer, + uncompressed_size, + ZSTD_CLEVEL_DEFAULT); if (ZSTD_isError (compressed_size)) { bfd_release (abfd, buffer); @@ -203,8 +190,8 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec, } #endif } - else if (compress ((Bytef *)buffer + header_size, &compressed_size, - (const Bytef *)uncompressed_buffer, uncompressed_size) + else if (compress ((Bytef *) buffer + new_header_size, &compressed_size, + (const Bytef *) input_buffer, uncompressed_size) != Z_OK) { bfd_release (abfd, buffer); @@ -212,27 +199,24 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec, return 0; } - compressed_size += header_size; - /* PR binutils/18087: If compression didn't make the section smaller, - just keep it uncompressed. */ - if (compressed_size < uncompressed_size) - bfd_update_compression_header (abfd, buffer, sec); - else - { - /* NOTE: There is a small memory leak here since - uncompressed_buffer is malloced and won't be freed. */ - bfd_release (abfd, buffer); - sec->contents = uncompressed_buffer; - sec->compress_status = COMPRESS_SECTION_NONE; - return uncompressed_size; - } + compressed_size += new_header_size; } - free (uncompressed_buffer); + /* If compression didn't make the section smaller, keep it uncompressed. */ + if (compressed_size >= uncompressed_size) + { + memcpy (buffer, input_buffer, uncompressed_size); + sec->compress_status = COMPRESS_SECTION_NONE; + } + else + { + sec->size = uncompressed_size; + bfd_update_compression_header (abfd, buffer, sec); + sec->size = compressed_size; + sec->compress_status = COMPRESS_SECTION_DONE; + } sec->contents = buffer; - sec->size = compressed_size; - sec->compress_status = COMPRESS_SECTION_DONE; - + free (input_buffer); return uncompressed_size; } @@ -421,14 +405,15 @@ bfd_cache_section_contents (asection *sec, void *contents) /* FUNCTION - bfd_is_section_compressed_with_header + bfd_is_section_compressed_info SYNOPSIS - bool bfd_is_section_compressed_with_header + bool bfd_is_section_compressed_info (bfd *abfd, asection *section, - int *compression_header_size_p, - bfd_size_type *uncompressed_size_p, - unsigned int *uncompressed_alignment_power_p); + int *compression_header_size_p, + bfd_size_type *uncompressed_size_p, + unsigned int *uncompressed_alignment_power_p, + unsigned int *ch_type); DESCRIPTION Return @code{TRUE} if @var{section} is compressed. Compression @@ -441,16 +426,16 @@ DESCRIPTION */ bool -bfd_is_section_compressed_with_header (bfd *abfd, sec_ptr sec, - int *compression_header_size_p, - bfd_size_type *uncompressed_size_p, - unsigned int *uncompressed_align_pow_p) +bfd_is_section_compressed_info (bfd *abfd, sec_ptr sec, + int *compression_header_size_p, + bfd_size_type *uncompressed_size_p, + unsigned int *uncompressed_align_pow_p, + unsigned int *ch_type) { bfd_byte header[MAX_COMPRESSION_HEADER_SIZE]; int compression_header_size; int header_size; unsigned int saved = sec->compress_status; - unsigned int ch_type; bool compressed; *uncompressed_align_pow_p = 0; @@ -481,7 +466,7 @@ bfd_is_section_compressed_with_header (bfd *abfd, sec_ptr sec, { if (compression_header_size != 0) { - if (!bfd_check_compression_header (abfd, header, sec, &ch_type, + if (!bfd_check_compression_header (abfd, header, sec, ch_type, uncompressed_size_p, uncompressed_align_pow_p)) compression_header_size = -1; @@ -521,10 +506,12 @@ bfd_is_section_compressed (bfd *abfd, sec_ptr sec) int compression_header_size; bfd_size_type uncompressed_size; unsigned int uncompressed_align_power; - return (bfd_is_section_compressed_with_header (abfd, sec, - &compression_header_size, - &uncompressed_size, - &uncompressed_align_power) + unsigned int ch_type; + return (bfd_is_section_compressed_info (abfd, sec, + &compression_header_size, + &uncompressed_size, + &uncompressed_align_power, + &ch_type) && compression_header_size >= 0 && uncompressed_size > 0); } @@ -654,10 +641,14 @@ bfd_init_section_compress_status (bfd *abfd, sec_ptr sec) 0, uncompressed_size)) return false; - uncompressed_size = bfd_compress_section_contents (abfd, sec, - uncompressed_buffer, - uncompressed_size); - return uncompressed_size != 0; + sec->contents = uncompressed_buffer; + if (bfd_compress_section_contents (abfd, sec) == 0) + { + free (sec->contents); + sec->contents = NULL; + return false; + } + return true; } /* @@ -673,7 +664,7 @@ DESCRIPTION compressed size and set compress_status to COMPRESS_SECTION_DONE. Return @code{FALSE} if compression fail. Otherwise, return - @code{TRUE}. + @code{TRUE}. UNCOMPRESSED_BUFFER is freed in both cases. */ bool @@ -693,7 +684,12 @@ bfd_compress_section (bfd *abfd, sec_ptr sec, bfd_byte *uncompressed_buffer) return false; } - /* Compress it. */ - return bfd_compress_section_contents (abfd, sec, uncompressed_buffer, - uncompressed_size) != 0; + sec->contents = uncompressed_buffer; + if (bfd_compress_section_contents (abfd, sec) == 0) + { + free (sec->contents); + sec->contents = NULL; + return false; + } + return true; } diff --git a/bfd/elf.c b/bfd/elf.c index 420b524aae8..fe00e0f9189 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -1209,32 +1209,35 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, int compression_header_size; bfd_size_type uncompressed_size; unsigned int uncompressed_align_power; + unsigned int ch_type = 0; bool compressed - = bfd_is_section_compressed_with_header (abfd, newsect, - &compression_header_size, - &uncompressed_size, - &uncompressed_align_power); - if (compressed) - { - /* Compressed section. Check if we should decompress. */ - if ((abfd->flags & BFD_DECOMPRESS)) - action = decompress; - } - - /* Compress the uncompressed section or convert from/to .zdebug* - section. Check if we should compress. */ - if (action == nothing) - { - if (newsect->size != 0 - && (abfd->flags & BFD_COMPRESS) - && compression_header_size >= 0 - && uncompressed_size > 0 - && (!compressed - || ((compression_header_size > 0) - != ((abfd->flags & BFD_COMPRESS_GABI) != 0)))) + = bfd_is_section_compressed_info (abfd, newsect, + &compression_header_size, + &uncompressed_size, + &uncompressed_align_power, + &ch_type); + + /* Should we decompress? */ + if ((abfd->flags & BFD_DECOMPRESS) != 0 && compressed) + action = decompress; + + /* Should we compress? Or convert to a different compression? */ + else if ((abfd->flags & BFD_COMPRESS) != 0 + && newsect->size != 0 + && compression_header_size >= 0 + && uncompressed_size > 0) + { + if (!compressed) action = compress; else - return true; + { + unsigned int new_ch_type = 0; + if ((abfd->flags & BFD_COMPRESS_GABI) != 0) + new_ch_type = ((abfd->flags & BFD_COMPRESS_ZSTD) != 0 + ? ELFCOMPRESS_ZSTD : ELFCOMPRESS_ZLIB); + if (new_ch_type != ch_type) + action = compress; + } } if (action == compress) @@ -1243,20 +1246,17 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, { _bfd_error_handler /* xgettext:c-format */ - (_("%pB: unable to initialize compress status for section %s"), - abfd, name); + (_("%pB: unable to compress section %s"), abfd, name); return false; } } - else + else if (action == decompress) { if (!bfd_init_section_decompress_status (abfd, newsect)) { _bfd_error_handler /* xgettext:c-format */ - (_("%pB: unable to initialize decompress status" - " for section %s"), - abfd, name); + (_("%pB: unable to decompress section %s"), abfd, name); return false; } #ifndef HAVE_ZSTD @@ -1273,26 +1273,29 @@ _bfd_elf_make_section_from_shdr (bfd *abfd, #endif } - if (abfd->is_linker_input) + if (action != nothing) { - if (name[1] == 'z' - && (action == decompress - || (action == compress - && (abfd->flags & BFD_COMPRESS_GABI) != 0))) + if (abfd->is_linker_input) { - /* Convert section name from .zdebug_* to .debug_* so - that linker will consider this section as a debug - section. */ - char *new_name = convert_zdebug_to_debug (abfd, name); - if (new_name == NULL) - return false; - bfd_rename_section (newsect, new_name); + if (name[1] == 'z' + && (action == decompress + || (action == compress + && (abfd->flags & BFD_COMPRESS_GABI) != 0))) + { + /* Convert section name from .zdebug_* to .debug_* so + that linker will consider this section as a debug + section. */ + char *new_name = convert_zdebug_to_debug (abfd, name); + if (new_name == NULL) + return false; + bfd_rename_section (newsect, new_name); + } } + else + /* For objdump, don't rename the section. For objcopy, delay + section rename to elf_fake_sections. */ + newsect->flags |= SEC_ELF_RENAME; } - else - /* For objdump, don't rename the section. For objcopy, delay - section rename to elf_fake_sections. */ - newsect->flags |= SEC_ELF_RENAME; } /* GCC uses .gnu.lto_.lto. as a LTO bytecode information