From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id EDF9E3858D28 for ; Sun, 16 Oct 2022 04:42:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EDF9E3858D28 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-pl1-x636.google.com with SMTP id i6so8102445pli.12 for ; Sat, 15 Oct 2022 21:42:14 -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=ric59w0hHcBRWH+gNu9yDXYjJYJNLONF2QC7+JC7Wig=; b=Wu1AsFtBWZUoeCbO/WKA53YTqnVI1hsdkh5Ip05dXcvuYzDlMcuGd4y4K0k07QTupL m32Zw7Z2jIyGaDaJvFt9DVij1JEZ/k0MwmbmAVB34gGFdctJh1iZghyIH1uc8KXmjI50 mjol5P2KouDNnuK2HoKB7dcOtonOjDOvGTlFKaM86/Ozp9bmALovWxDMv995n+CT8jxm srfvj8PMIxuxiB44d/BPk/TqilPREu2K7yweEBDivtoxW4HU02dqKhr/CaMcWmFt68AR 1lJW+VOihhB0Ui9l2tKvmisRJnw2HlQjGI1To4ijA4VPcFaVcXki9GaNkIc2JPh5p2eS aKuA== 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=ric59w0hHcBRWH+gNu9yDXYjJYJNLONF2QC7+JC7Wig=; b=wHZ7HfUxbyLt0Bi86Ro1W02Hs8JmIoJlIgNDHzJ10FsSxY1BVWqoe6X0bGCvX8wkcU JzsCPWpmNal5Sd8qHdKjtOc2rQHJbVbDFY20lt4Bpm8K/RZLHEIAhDAwcJxqpwspxO9g qHCKdpkHXFK30IXxCuaTsy5HMXVcr+yH2+4Tcryh/uw69EqMffrFN1UUvSp/FDlMv/mC IFJuESWuJ+45HLrOS4McFgW2QPp528JUKUgqH/Q+FsINY9fZJbj7sK9vbryNsiwjkGXH Rm1R8R0cgkYcm8/4nR5DfUYnERv0zPMWhTFgtesBkwjUPW38qUdWNBFg9p+qz0nq3cc2 kRVw== X-Gm-Message-State: ACrzQf0TPpBAgXyOsk0AZBCUDMOGaZz2he4CpFJOrJi67osMw+46HyZL gScbHww3Xu1sT2Bcuff42J6qrzVIkZI= X-Google-Smtp-Source: AMsMyM7yT48ehDWfyfdkcaOtrRBDVMc51beaKXGymzKHlmaUUFWTXS8bKlcqKaYWxv1GtdFb//UokQ== X-Received: by 2002:a17:902:e982:b0:17f:ca1f:aa44 with SMTP id f2-20020a170902e98200b0017fca1faa44mr5628724plb.76.1665895333925; Sat, 15 Oct 2022 21:42:13 -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 b8-20020a17090a7ac800b00205d70ccfeesm7139987pjl.33.2022.10.15.21.42.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 15 Oct 2022 21:42:12 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 9E74E11403AB; Sun, 16 Oct 2022 15:12:09 +1030 (ACDT) Date: Sun, 16 Oct 2022 15:12:09 +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 10:39:17PM +1030, Alan Modra wrote: > 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. Another compress_status isn't elegant. I'm about to commit this: * bfd.c (bfd_convert_section_contents): Handle zstd. * compress.c (bfd_compress_section_contents): When section contents are uncompressed set SEC_IN_MEMORY flag, compress_status to COMRESS_SECTION_NONE, and clear SHF_COMPRESSED. Set SEC_IN_MEMORY for compressed contents. (bfd_get_full_section_contents): Don't check section size against file size when SEC_IN_MEMORY. (bfd_cache_section_contents): Delete function. * elf32-arm.c (elf32_arm_get_synthetic_symtab): Expand bfd_cache_section_contents here. * bfd-in2.h: Regenerate. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 25e1806e689..534a46439fc 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -7964,9 +7964,6 @@ bfd_byte *bfd_simple_get_relocated_section_contents bool bfd_get_full_section_contents (bfd *abfd, asection *section, bfd_byte **ptr); -void bfd_cache_section_contents - (asection *sec, void *contents); - bool bfd_is_section_compressed_info (bfd *abfd, asection *section, int *compression_header_size_p, diff --git a/bfd/bfd.c b/bfd/bfd.c index 5f2033bee7a..4fca8250082 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -2801,14 +2801,14 @@ bfd_convert_section_contents (bfd *ibfd, sec_ptr isec, bfd *obfd, if (ohdr_size == sizeof (Elf32_External_Chdr)) { Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) contents; - bfd_put_32 (obfd, ELFCOMPRESS_ZLIB, &echdr->ch_type); + bfd_put_32 (obfd, chdr.ch_type, &echdr->ch_type); bfd_put_32 (obfd, chdr.ch_size, &echdr->ch_size); bfd_put_32 (obfd, chdr.ch_addralign, &echdr->ch_addralign); } else { Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) contents; - bfd_put_32 (obfd, ELFCOMPRESS_ZLIB, &echdr->ch_type); + bfd_put_32 (obfd, chdr.ch_type, &echdr->ch_type); bfd_put_32 (obfd, 0, &echdr->ch_reserved); bfd_put_64 (obfd, chdr.ch_size, &echdr->ch_size); bfd_put_64 (obfd, chdr.ch_addralign, &echdr->ch_addralign); diff --git a/bfd/compress.c b/bfd/compress.c index 364df14142b..9608a0a6341 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -151,7 +151,8 @@ 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->flags |= SEC_IN_MEMORY; + sec->compress_status = COMPRESS_SECTION_NONE; sec->size = uncompressed_size; input_buffer = buffer; } @@ -206,6 +207,7 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec) if (compressed_size >= uncompressed_size) { memcpy (buffer, input_buffer, uncompressed_size); + elf_section_flags (sec) &= ~SHF_COMPRESSED; sec->compress_status = COMPRESS_SECTION_NONE; } else @@ -216,6 +218,7 @@ bfd_compress_section_contents (bfd *abfd, sec_ptr sec) sec->compress_status = COMPRESS_SECTION_DONE; } sec->contents = buffer; + sec->flags |= SEC_IN_MEMORY; free (input_buffer); return uncompressed_size; } @@ -268,6 +271,7 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr) ufile_ptr filesize = bfd_get_file_size (abfd); if (filesize > 0 && filesize < sz + && (bfd_section_flags (sec) & SEC_IN_MEMORY) == 0 /* PR 24753: Linker created sections can be larger than the file size, eg if they are being used to hold stubs. */ && (bfd_section_flags (sec) & SEC_LINKER_CREATED) == 0 @@ -380,29 +384,6 @@ bfd_get_full_section_contents (bfd *abfd, sec_ptr sec, bfd_byte **ptr) } } -/* -FUNCTION - bfd_cache_section_contents - -SYNOPSIS - void bfd_cache_section_contents - (asection *sec, void *contents); - -DESCRIPTION - Stash @var(contents) so any following reads of @var(sec) do - not need to decompress again. -*/ - -void -bfd_cache_section_contents (asection *sec, void *contents) -{ - if (sec->compress_status == DECOMPRESS_SECTION_ZLIB - || sec->compress_status == DECOMPRESS_SECTION_ZSTD) - sec->compress_status = COMPRESS_SECTION_DONE; - sec->contents = contents; - sec->flags |= SEC_IN_MEMORY; -} - /* FUNCTION bfd_is_section_compressed_info diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 0852b38ae4c..ec18a8ab362 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -20020,9 +20020,11 @@ elf32_arm_get_synthetic_symtab (bfd *abfd, data = plt->contents; if (data == NULL) { - if (!bfd_get_full_section_contents (abfd, (asection *) plt, &data) || data == NULL) + if (!bfd_get_full_section_contents (abfd, plt, &data) + || data == NULL) return -1; - bfd_cache_section_contents ((asection *) plt, data); + plt->contents = data; + plt->flags |= SEC_IN_MEMORY; } count = relplt->size / hdr->sh_entsize; -- Alan Modra Australia Development Lab, IBM