From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id CC08A3858C83 for ; Fri, 14 Oct 2022 11:28:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CC08A3858C83 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-x62a.google.com with SMTP id i6so4430875pli.12 for ; Fri, 14 Oct 2022 04:28:46 -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=jlyGIHpMW51MppdlmWb4xb12uHO9cb1qaAsE248SKE0=; b=ht8EKUSHQjlYd1rdFhfUAagLgwUTVbeRwbNYWnYQ9dEes8q0NI+I+ivta5QmhXInQl a73RosLpXAlM6bjSE+KBWF0Gh566Ltd3WEJufhONe6+X9mXl6yclH51moJDXLSJdbv6T OPRJpB8bQ3FaFnG34FUZxVSJL5kQwjaVpbsNpIzzFENYLCbjFXK7TXEV53xsXheh2iwQ ArkeeoinM5ntkqqj7Xem7LCzmEReuzLWQKa3jVm0d5eiqqQnJ+bfsEOemAKhTPS+VIvo jw7wUrg/pvT6X+k/SzxW1mxBXHzh+EzyuIAM3AOzSjNnxl+BTwXzYlIafo4REKpbLfS/ 8qCg== 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=jlyGIHpMW51MppdlmWb4xb12uHO9cb1qaAsE248SKE0=; b=f8TpNOlU9Dnok5sp7NFPtBWzzg2GKdWcDYBqmVIHYvkObaMpGomDIf1P2IVZxLKS9v xUHpDLvLBR7VI0SRIBkWUtlgABOBiC3/RfUUaNasucTsVSPXTvvxUtm0iJ0Am3T54g34 +gLtkHMVIzVbwHiOiK3WgaxSrq0BUFXtTfuIdKMNnKbQ1auDKPsnWdaOlkn/o7A7xMyR bwU5ZsBesxkEPYjhjh3qvWIo8tR6M/6PpC6hVbD3iBNxvDs92N+3wq1IQ22eqXoGG9vJ kPuUC69uw3HsF63zzE/Wrgoc3EOTguFk74J0sbYo0evJR8IzIih3ozbRgwqLxEuKu7dU vMPg== X-Gm-Message-State: ACrzQf1kAsyvA4lW+aaMro9DkiDbn2lhRqiPLYwuydixhA192aB5zuLA lG/5AyFNi8ctbFSluSCdsEWTTuzQ0o4= X-Google-Smtp-Source: AMsMyM4c65HlGNHzKVSRvGSTQLC4s9LW3GUMzZUGZs6SfLokPnEGgmCGqO/lCgDze98SNJJZjmPaDA== X-Received: by 2002:a17:90b:254c:b0:20a:8a92:ea5b with SMTP id nw12-20020a17090b254c00b0020a8a92ea5bmr5278286pjb.81.1665746925846; Fri, 14 Oct 2022 04:28:45 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:16f7:73a:410:46e6]) by smtp.gmail.com with ESMTPSA id d18-20020a170902ced200b0017eea4a3979sm1501833plg.154.2022.10.14.04.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Oct 2022 04:28:45 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 9927F1142DD0; Fri, 14 Oct 2022 21:58:41 +1030 (ACDT) Date: Fri, 14 Oct 2022 21:58:41 +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: <5eeed442-a153-5805-eae9-44b006506fd1@suse.cz> 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 List-Id: 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. diff --git a/bfd/compress.c b/bfd/compress.c index 364df14142b..5eef38bd50a 100644 --- a/bfd/compress.c +++ b/bfd/compress.c @@ -206,15 +206,15 @@ 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; } else { sec->size = uncompressed_size; bfd_update_compression_header (abfd, buffer, sec); sec->size = compressed_size; - sec->compress_status = COMPRESS_SECTION_DONE; } + sec->compress_status = COMPRESS_SECTION_DONE; sec->contents = buffer; free (input_buffer); return uncompressed_size; -- Alan Modra Australia Development Lab, IBM