From patchwork Mon Jul 29 21:57:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 94745 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D44B4385DDC1 for ; Mon, 29 Jul 2024 21:59:02 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail.burntcomma.com (mail2.burntcomma.com [217.169.27.34]) by sourceware.org (Postfix) with ESMTPS id 21CA73858C78 for ; Mon, 29 Jul 2024 21:58:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 21CA73858C78 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=harmstone.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=harmstone.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 21CA73858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.169.27.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722290315; cv=none; b=Rh+bd8rXlykkmeQm5/uiOcxbDwHL0bsVrTEYbJ02GvvLZTPjIep5gEYxMGDH45r2bwRARQVmR52kAXP73Tjc6rGPdv3IdAGishhlS6ZSbHtCIQKZwNiq/JfaE6RZIrL39dYjWE9B3FdxDB0guZJjM8AdBtYaJmM8TjTQd9pVez4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722290315; c=relaxed/simple; bh=/vrDR1heUHMdKoxyakiPzxMzMWaGvaincvfm/+xgDuo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=UZKhLk4pgczRTpEKjsC8nrjK9IDaWWmKqOiIKzcPgqHnIKIKfWZcVie8VEb5pTXIMekiGerpvNX/QWDvm2126KzAJj5aYDpT5YU+jEJIn9LdZvqHmbkHWHyy2lVAlxmZvYkp/ZbFAz6afYe2DE25SrXmTtsuFclRC+Eg9VgT21Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from localhost.localdomain (beren.burntcomma.com [IPv6:2a02:8012:8cf0:0:b62e:99ff:fee9:ad9f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by mail.burntcomma.com (Postfix) with ESMTPSA id 06D31405BBE4; Mon, 29 Jul 2024 22:58:29 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmstone.com; s=mail; t=1722290310; bh=xse180q1JMHLIONVtJ7U/QZoyMaBwKQFRO9c7FVW/ZA=; h=From:To:Cc:Subject:Date; b=6VDYS17Z89kSyQp3h7Ctic1ZCc5d0TgCP7HVKe8lW8nIT3pEjMjM6b2R9vV4XI8LO Poi/mxUM4ytB0uXlJUgUYOooUsvuHp7cav7cGuyb+DAm1j1mpXZvP+TKqKdYTedhm4 /fRCjgr3fnQ/T3W+IAKGBWIJygqhWAkJodQuufh0= From: Mark Harmstone To: binutils@sourceware.org Cc: Mark Harmstone Subject: [PATCH] ld/PDB: handle empty LF_FIELDLIST types Date: Mon, 29 Jul 2024 22:57:49 +0100 Message-ID: <20240729215826.27870-1-mark@harmstone.com> Mime-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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.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 Empty structs in C++ lead to empty LF_FIELDLIST types in the .debug$T section, but we were mistakenly rejecting these as invalid. Allow CodeView types of two bytes, and add a test for this. --- ld/pdb.c | 2 +- ld/testsuite/ld-pe/pdb-types1-typelist.d | 5 ++++- ld/testsuite/ld-pe/pdb-types1b.s | 20 +++++++++++++++++++- ld/testsuite/ld-pe/pdb.exp | 2 +- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ld/pdb.c b/ld/pdb.c index 7a08ae35e79..fcbe325603c 100644 --- a/ld/pdb.c +++ b/ld/pdb.c @@ -3582,7 +3582,7 @@ handle_debugt_section (asection *s, bfd *mod, struct types *types, size = bfd_getl16 (data + off); off += sizeof (uint16_t); - if (size + off > s->size || size <= sizeof (uint16_t)) + if (size + off > s->size || size < sizeof (uint16_t)) { free (data); bfd_set_error (bfd_error_bad_value); diff --git a/ld/testsuite/ld-pe/pdb-types1-typelist.d b/ld/testsuite/ld-pe/pdb-types1-typelist.d index db08b52859f..1caa074ac56 100644 --- a/ld/testsuite/ld-pe/pdb-types1-typelist.d +++ b/ld/testsuite/ld-pe/pdb-types1-typelist.d @@ -77,4 +77,7 @@ Contents of section .data: 0480 3a001d15 2a100000 00000000 00000000 :...*........... 0490 27000000 49556e6b 6e6f776e 00517565 '...IUnknown.Que 04a0 7279496e 74657266 61636500 41646452 ryInterface.AddR - 04b0 65660052 656c6561 736500f1 ef.Release.. + 04b0 65660052 656c6561 736500f1 02000312 ef.Release...... + 04c0 22000515 00000000 2c100000 00000000 ".......,....... + 04d0 00000000 0100656d 7074795f 73747275 ......empty_stru + 04e0 637400f1 ct.. diff --git a/ld/testsuite/ld-pe/pdb-types1b.s b/ld/testsuite/ld-pe/pdb-types1b.s index e26b190b78f..8bfc973c1c8 100644 --- a/ld/testsuite/ld-pe/pdb-types1b.s +++ b/ld/testsuite/ld-pe/pdb-types1b.s @@ -593,7 +593,7 @@ /* Type 102a, virtual function table */ .vftable1: -.short .types_end - .vftable1 - 2 +.short .fieldlist12 - .vftable1 - 2 .short LF_VFTABLE .long 0x1029 /* type */ .long 0 /* base vftable */ @@ -607,4 +607,22 @@ .vftable1_names_end: .byte 0xf1 /* padding */ +/* Type 102b, empty LF_FIELDLIST */ +.fieldlist12: +.short .struct7 - .fieldlist12 - 2 +.short LF_FIELDLIST + +/* Type 102c, empty struct */ +.struct7: +.short .types_end - .struct7 - 2 +.short LF_STRUCTURE +.short 0 /* no. members */ +.short 0 /* property */ +.long 0x102b /* field list */ +.long 0 /* type derived from */ +.long 0 /* type of vshape table */ +.short 1 /* size */ +.asciz "empty_struct" /* name */ +.byte 0xf1 /* padding */ + .types_end: diff --git a/ld/testsuite/ld-pe/pdb.exp b/ld/testsuite/ld-pe/pdb.exp index 124765109bf..b583e877f01 100644 --- a/ld/testsuite/ld-pe/pdb.exp +++ b/ld/testsuite/ld-pe/pdb.exp @@ -1036,7 +1036,7 @@ proc test5 { } { binary scan $data i end_type # end_type is one greater than the last type in the stream - if { $end_type != 0x102c } { + if { $end_type != 0x102e } { fail "Incorrect end type value in TPI stream." } else { pass "Correct end type value in TPI stream."