From patchwork Mon Sep 28 09:01:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Deiminger X-Patchwork-Id: 144773 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A2DA74BA9038 for ; Mon, 28 Sep 2026 09:04:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A2DA74BA9038 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=YD6mXLFf; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=tVNfViVP X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by sourceware.org (Postfix) with ESMTPS id 61EE24BA7981 for ; Mon, 28 Sep 2026 09:02:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61EE24BA7981 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linutronix.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 61EE24BA7981 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a0a:51c0:0:12e:550::1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790586139; cv=none; b=AtWvXx4zkb9ShOl7bisKYxsyI9m2z7VZPg2CfaFglQkCX/s5og5JuSvz7hviUDovxjyNoo25IKWsXa1IJy1w/F3x9iUkCyN1FXg90Zo58BHD9iIxsXiMhrkNBplOy539LKMEWvDzJ3EIaYeqODF3wNV4oVt2t3qgG+kIkIKyQNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790586139; c=relaxed/simple; bh=zvVZH3YpJkBEf82k2iOJUkitenFKBh4pD/oJObLCekM=; h=From:DKIM-Signature:DKIM-Signature:To:Subject:Date:Message-ID: MIME-Version; b=KxjkWsIb9dVa5FYsn4ZjKbUTNHFpY1lB7JVGoTiLK7M/kHHBnQDeUbBxwnnlBTnInu3ndAltMl3WvlzpHM+h0cj7DdBaPlIvyuM6Jog0RTd4Q4Fvw46+N9BdG4l4r9WOz4YQkLrGamdMVTZ9OhT84J2vad5S/Av3ZM3O22MqgIM= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=YD6mXLFf; dkim=pass header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=tVNfViVP DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61EE24BA7981 From: Tobias Deiminger DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1790586132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lp+OVrBh6QsUWzMHOcAeYuhhaYkWKfeE5oO+X6n4LdA=; b=YD6mXLFfypxVqw9lSWFqSf4YszmCZZeICgOR05jjy2cqmUlYAQVjIaiwCdbmfd7/LD0vGi 6QX6z7Xc7mQsFTLNo/YVbmx4Qu8VtuFRC+xgJTFaXPdk+n1DY+RB7Eu2pgXIN0FEzPzK+x By/MUKPU0mMEqYj/utfp8eBwnP4dAPwJvksbYoKZ+YjASfAjR4qVucaCNDE6DQB53RJsxz jD/z073cGrTGkTmMwDaqX8sVGh8txPBq8uGfrpHIWlY6CqUTc/lkyd6UEUCBFZhBlEUsJs Kk3B90p9VLvcWhz8StplW75HgbnMm/bg9iNFUxaPff8qb83B/p+/baSFJtVU9g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1790586132; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lp+OVrBh6QsUWzMHOcAeYuhhaYkWKfeE5oO+X6n4LdA=; b=tVNfViVPSXz+KBl/dHimO9mnw4RxQgXEAtlq383BAX/TTLTe+bVx1W1fGFUuX/vWwpDYM1 mC3rKUqUIrm0+2BA== To: binutils@sourceware.org Cc: Tobias Deiminger Subject: [PATCH 1/3] bfd/PE: fix debug section compression for pei-* Date: Mon, 28 Sep 2026 11:01:44 +0200 Message-ID: <20260928090146.4016188-2-tobias.deiminger@linutronix.de> In-Reply-To: <20260928090146.4016188-1-tobias.deiminger@linutronix.de> References: <20260928090146.4016188-1-tobias.deiminger@linutronix.de> MIME-Version: 1.0 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org bfd supports compressing debug sections for PE/Coff since a29a8af823af ("ChangeLog bfd"). It works for pe, but never worked for pei in a full round trip. For example: $ x86_64-w64-mingw32-gcc -g -o testprog testprog.c $ objcopy --compress-debug-sections testprog.exe testprog_z.exe $ gdb --batch -ex "break fn" -ex "info line fn" testprog_z.exe warning: Can't read data for section '.zdebug_info' in file '/.../testprog_z.exe' [...] No line number information available for address 0x140001490 PE objects use SizeOfRawData to store the compressed size. PE images can't, because SizeOfRawData must be file aligned per specification. PE images could instead fall back to VirtualSize, but this was not implemented correctly. When BFD opened a compressed file for decompression, peicode.h:coff_swap_scnhdr_in set the lesser of VirtualSize and SizeOfRawData as s_size, which was later used for decompression verification. This was wrong in any case. VirtualSize held the uncompressed size and SizeOfRawData the padded size. Instead we need the *compressed* size to let zlib verification conclude it successfully consumed all bytes. Fix it by storing the compressed size rather than the uncompressed size in VirtualSize. As an important detail, defer osec->virt_size assignment to coff_compute_section_file_positions when a size change due to (de)compression is expected. Otherwise, a successful decompression would not update from compressed size to decompressed size. Signed-off-by: Tobias Deiminger --- bfd/peXXigen.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index 17a94c461fe..199ee048bec 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -3196,8 +3196,9 @@ _bfd_XX_bfd_copy_private_section_data (bfd *ibfd, return false; } - pei_section_data (obfd, osec)->virt_size = - pei_section_data (ibfd, isec)->virt_size; + if (isec->compress_status == COMPRESS_SECTION_NONE) + pei_section_data (obfd, osec)->virt_size = + pei_section_data (ibfd, isec)->virt_size; pei_section_data (obfd, osec)->pe_flags = pei_section_data (ibfd, isec)->pe_flags; }