From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 499B13858C83 for ; Fri, 14 Oct 2022 12:09:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 499B13858C83 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x436.google.com with SMTP id d10so4731732pfh.6 for ; Fri, 14 Oct 2022 05:09:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=S4VkUcLS8bDh+iJhNJksNMBZ31PS1f1LfQL46sHh/Ro=; b=POkrncVKZfYLkjqykweaoKEyPug7oFI7fCNwjN+hbEU9SQuznPEFIRbuVnN+sqUelS PRPJApzvGN+wjdWyLorNtSOeSOV/k+mX/sKOBo9SJVPAKcfxNaTMs/HEcgM4JK0Aeu1B N3OnF2fERQn+N7qVbjBWtdbwZrNUlCCZR+onJfdn7KGTpGkWPuS790BvaZqyx6miwKRt ftv6N5M1JeZno7Zs14sYzquvreTUuMrMWhDcqIXrxqlwH+Fsg4sbE6ii80HNv0+xspdh zacj4TXg0r2iEde7kHeWbY5hZ3f9zvEQGAxgx4+19pCXI4hJ+o6RiZkCLohWRkNpwUzG xENQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=S4VkUcLS8bDh+iJhNJksNMBZ31PS1f1LfQL46sHh/Ro=; b=pafi1gdSQOL6lQ8TRMFKLRF5V8xjKiQ7y9AjiKz0iQ+TRWdJddRhxz5XcB6jdSErSB D6z5ZNQD1KwYmUWysbZGKwUQ3cgjdb/MAH8f3X/3/sszMNXsr5SM4pqfVRasqbZC6YYN s2YGxOuu3/6d6nr9h3cO5sfnMiQ6UjlF8F0cjzi1dqEZg6Iai8AwWlhQQjVyomEXnCuV +ZQ4a3iM1SPERRRS7bX+a316Xk1Br2itKfkdvXNobMtXp5wRwzE5brs6lu/6JyfD8A+C CLYZPm/mRXm1RNvP2tSqEhLpvSI7ao4N2rPHcFqfS+NMqEydgQtxT/ZIPi9p6WAH9TQb 4JUw== X-Gm-Message-State: ACrzQf1g4yboiu0HmgOgjTHctAgGP3OXEwddG1be5o29h4FQHgRnZUDU IBGz7RTi6L4WgTbdLxFwzk0= X-Google-Smtp-Source: AMsMyM7xR/njp9OSqeTmkJt0Cgu/ZlKVvCyLIvwZk8WN7HlPmL16Q6fyespHPaTfqwvatNoArJHNtQ== X-Received: by 2002:a62:5e81:0:b0:563:1f18:62ab with SMTP id s123-20020a625e81000000b005631f1862abmr5085613pfb.76.1665749361336; Fri, 14 Oct 2022 05:09:21 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id m10-20020a1709026bca00b00181a0e61ce4sm1605586plt.6.2022.10.14.05.09.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 05:09:20 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id D1C791142DD0; Fri, 14 Oct 2022 22:39:17 +1030 (ACDT) Date: Fri, 14 Oct 2022 22:39:17 +1030 From: Alan Modra To: Martin =?utf-8?B?TGnFoWth?= Cc: Fangrui Song , binutils@sourceware.org Subject: Re: [PATCH] readelf: support zstd compressed debug sections [PR 29640] Message-ID: References: <20221001062057.681440-1-maskray@google.com> <45fca661-a0e8-f0f8-78d6-8d90783de6d7@suse.cz> <20221014033511.vqanebcqikmi5k37@google.com> <56a23340-a416-0ac9-dc17-4be601edacf7@suse.cz> <5eeed442-a153-5805-eae9-44b006506fd1@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3036.3 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 List-Id: On Fri, Oct 14, 2022 at 09:58:41PM +1030, Alan Modra wrote: > So we have a zlib-gabi .debug_info section that increases in size with > zstd, so much so that it's better to leave the section uncompressed. > Things go horribly wrong due to leaving compress_status as > COMPRESS_SECTION_NONE. The section is read again off disk using the > uncompressed size. So you get the zlib section again with some > garbage at the end. > > Also, if the section is to be left uncompressed, the input > SHF_COMPRESSED flag needs to be reset otherwise it is copied to > output. > > I'm not ready to commit this, just thought I'd post the results of a > bit of debugging. And if I'd run the testsuite before posting, I may have posted a better patch.. Using COMPRESS_SECTION_DONE led to .debug -> .zdebug renaming of sections, so it appears we want another compress_status that says the final section contents are in sec->contents. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 25e1806e689..4f4658021c6 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -974,11 +974,12 @@ typedef struct bfd_section unsigned int gc_mark : 1; /* Section compression status. */ - unsigned int compress_status : 2; + unsigned int compress_status : 3; #define COMPRESS_SECTION_NONE 0 #define COMPRESS_SECTION_DONE 1 #define DECOMPRESS_SECTION_ZLIB 2 #define DECOMPRESS_SECTION_ZSTD 3 +#define DECOMPRESS_SECTION_DONE 4 /* The following flags are used by the ELF linker. */ diff --git a/bfd/compress.c b/bfd/compress.c index 364df14142b..94bc5412a89 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -151,7 +151,7 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec) free (input_buffer); bfd_set_section_alignment (sec, uncompressed_alignment_pow); sec->contents = buffer; - sec->compress_status = COMPRESS_SECTION_DONE; + sec->compress_status = DECOMPRESS_SECTION_DONE; sec->size = uncompressed_size; input_buffer = buffer; } @@ -206,7 +206,8 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec) if (compressed_size >= uncompressed_size) { memcpy (buffer, input_buffer, uncompressed_size); - sec->compress_status = COMPRESS_SECTION_NONE; + elf_section_flags (sec) &= ~SHF_COMPRESSED; + sec->compress_status = DECOMPRESS_SECTION_DONE; } else { @@ -361,6 +362,7 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr) return true; case COMPRESS_SECTION_DONE: + case DECOMPRESS_SECTION_DONE: if (sec->contents == NULL) return false; if (p == NULL) diff --git a/bfd/section.c b/bfd/section.c index 614570e976e..52cf7e042cd 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -389,11 +389,12 @@ CODE_FRAGMENT . unsigned int gc_mark : 1; . . {* Section compression status. *} -. unsigned int compress_status : 2; +. unsigned int compress_status : 3; .#define COMPRESS_SECTION_NONE 0 .#define COMPRESS_SECTION_DONE 1 .#define DECOMPRESS_SECTION_ZLIB 2 .#define DECOMPRESS_SECTION_ZSTD 3 +.#define DECOMPRESS_SECTION_DONE 4 . . {* The following flags are used by the ELF linker. *} . -- Alan Modra Australia Development Lab, IBM