From patchwork Mon Dec 26 20:47:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 36701 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1085209wrt; Mon, 26 Dec 2022 12:48:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXtoxJr25Ea8+1gc41HCF7Ldh7BKosCznI5qrzXLm44gjKJ8uMUKKRXK5NZkyuBr1DWRzzya X-Received: by 2002:a17:907:c71b:b0:7c1:67ca:56f5 with SMTP id ty27-20020a170907c71b00b007c167ca56f5mr21655265ejc.15.1672087691547; Mon, 26 Dec 2022 12:48:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672087691; cv=none; d=google.com; s=arc-20160816; b=QxSFhMm3tpqUz9mf3VWUHHlOqIDhl1rSsefzQX795BSoIHPWF1T4TqWAMCoKHe3Eno jcbS17TuCfj7pC0C4CKXyPZEiZUfFyEB7TW6S7Fwpy+L7xH8/7gs7O6Xf82lAcQZ4/vM b813W5hn4bSrJsGh9W24LDUBv3DGBlv+fYbobQmFVfT8kfpj5zHqIy5QYGPCpyCI/CkS xsg6WCixvlglpwu8oRrMGJoKeI3MxoUDdZzvoVvgRtFkLnXMG+UXm1YCGwYx0y2TTqZS yEf1BADgamvERhWIeyTGLgkMq2mHrzeJPvGvp7ncFcVwK7N9TTdBPh2p1k0yQ4Ama5YF s/Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:dmarc-filter:delivered-to; bh=x14oDZx3bPGPkP3IdMksXmlczuJQvFFovOG/jaAn+ok=; b=si47+ipJadUtkXLJ80EwfDbNF4VJHjm/dm/zSDQa4qdHKgEePqvNr1Taozk6PxtZBh txFoRNP46lJY02PJ5QmqUl4gD2qgQpNWiQ9h61ouB7OcdaeWxaySsgYa7xD0KCyFxFrA bLVTvPCVjy6A+UQwfoqk9GxdejOnGr+89I2zOvWF3k39YF6WsdgSvU6qw++8mCAX0Sst DmQl0AoMYz4ovKKSjswAXEF04WjMBsQ68G1+5+hpA5M7GdodzRPsN6Tjj1KmKBsVjCTk cpx5xJe/hz6GBgPhc6Bxh+2TljlFRnKp4cydnS77d+mOQChdFGIzY3nWz5Cu6NF2uLlE fz6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=JtzZHFqQ; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hv15-20020a17090760cf00b007ae1e635ea3si9783458ejc.754.2022.12.26.12.48.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Dec 2022 12:48:11 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=JtzZHFqQ; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8270F3858C2D for ; Mon, 26 Dec 2022 20:48:06 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by sourceware.org (Postfix) with ESMTPS id 9E3B63858D37 for ; Mon, 26 Dec 2022 20:47:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9E3B63858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=harmstone.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-x334.google.com with SMTP id m8-20020a05600c3b0800b003d96f801c48so5706196wms.0 for ; Mon, 26 Dec 2022 12:47:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=x14oDZx3bPGPkP3IdMksXmlczuJQvFFovOG/jaAn+ok=; b=JtzZHFqQfvfceJxMKgx4/iHm0ebPEoRA3uFdMHIC2+H49IkRFtu+4t1w4/zLJkkBQq lN73FAPDerZwpBlR41q09aP1N63JOK5MpwfoQePlsqtl6GWHgmp0ZBpXIGxoy750346m NuK/exmXXHmLGzfluT7ULmfamB+nlXKvNkRGpR2k03v3lb1XwYtaCICq/hFuNbbLTmOU QuhI1UFHGqQEKmEClYAJrr/dWB7O9M67HKNBIkCT5gg9gx2W/Cea0mZIdxBJJ4EP9Dh+ VpeR9HWIRDY5qERGazUIRCyzGPBCobIZezyp/b9cvJQza9TW2TO196I0KtpPbRWWjcA7 VIUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=x14oDZx3bPGPkP3IdMksXmlczuJQvFFovOG/jaAn+ok=; b=QfZteyJtSgoBT8TAtPTo2f13lMLS/8ScnoJJQ7wkdAxAz7iYuDCXIlCCrSkGqCddS2 jDbTC++T1fYmK9LDTahupVCqk6m7Ds3hDoN2cGZdZVmlasNdzOnqGfmzDOeJu0dxjaE8 t+vIq8cHdt+RK9dKQ85+C4BCrWqwfNsFNyH2ouCrE1hy5ky6o6e5DTKpGMvUzJOJ58Ot 8rhbZ6HK8d+VOuy9MsKGJAUaHqa4XAUnWNRMmAd6Yp7gTMpQ8UIvKgUVgJ+vdFPAOYNK lpiQRodfl0r8c6KY+jSAR7AguDUg2AQS1KzHte0qSHGFP6sP2NbmIXO+oK9vnZWZ2rQ8 qe8Q== X-Gm-Message-State: AFqh2kqETeZaDKy3iiPdj5GGOXM6CcOem5I5tkO2jIpamYvDAEsedbFG NM7BTKCAiFLA0d7x0NdnPlagSspFpDs= X-Received: by 2002:a05:600c:35ca:b0:3d1:f2de:195a with SMTP id r10-20020a05600c35ca00b003d1f2de195amr16579207wmq.32.1672087676192; Mon, 26 Dec 2022 12:47:56 -0800 (PST) Received: from beren.harmstone.com ([2a02:8010:64ea:0:8eb8:7eff:fe53:9d5f]) by smtp.gmail.com with ESMTPSA id e27-20020adf9bdb000000b00272c0767b4asm10384990wrc.109.2022.12.26.12.47.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Dec 2022 12:47:55 -0800 (PST) From: Mark Harmstone To: binutils@sourceware.org Cc: Mark Harmstone Subject: [PATCH 2/3] ld: Handle LF_VFTABLE types in PDBs Date: Mon, 26 Dec 2022 20:47:50 +0000 Message-Id: <20221226204751.23761-2-mark@harmstone.com> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221226204751.23761-1-mark@harmstone.com> References: <20221226204751.23761-1-mark@harmstone.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753311023248600210?= X-GMAIL-MSGID: =?utf-8?q?1753311023248600210?= --- ld/pdb.c | 20 +++++++++++++++ ld/pdb.h | 13 ++++++++++ ld/testsuite/ld-pe/pdb-types1-hashlist.d | 2 +- ld/testsuite/ld-pe/pdb-types1-typelist.d | 8 +++++- ld/testsuite/ld-pe/pdb-types1b.s | 32 +++++++++++++++++++++++- ld/testsuite/ld-pe/pdb.exp | 2 +- 6 files changed, 73 insertions(+), 4 deletions(-) diff --git a/ld/pdb.c b/ld/pdb.c index 5467a9efc12..4f0efa828f0 100644 --- a/ld/pdb.c +++ b/ld/pdb.c @@ -3306,6 +3306,26 @@ handle_type (uint8_t *data, struct type_entry **map, uint32_t type_num, /* Does not reference any types, nothing to be done. */ break; + case LF_VFTABLE: + { + struct lf_vftable *vft = (struct lf_vftable *) data; + + if (size < offsetof (struct lf_vftable, names)) + { + einfo (_("%P: warning: truncated CodeView type record" + " LF_VFTABLE\n")); + return false; + } + + if (!remap_type (&vft->type, map, type_num, num_types)) + return false; + + if (!remap_type (&vft->base_vftable, map, type_num, num_types)) + return false; + + break; + } + case LF_STRING_ID: { struct lf_string_id *str = (struct lf_string_id *) data; diff --git a/ld/pdb.h b/ld/pdb.h index ddf731b99c9..2efaa466efb 100644 --- a/ld/pdb.h +++ b/ld/pdb.h @@ -54,6 +54,7 @@ #define LF_METHOD 0x150f #define LF_NESTTYPE 0x1510 #define LF_ONEMETHOD 0x1511 +#define LF_VFTABLE 0x151d #define LF_FUNC_ID 0x1601 #define LF_MFUNC_ID 0x1602 #define LF_BUILDINFO 0x1603 @@ -578,6 +579,18 @@ struct lf_udt_mod_src_line uint16_t module_no; } ATTRIBUTE_PACKED; +/* lfVftable in cvinfo.h */ +struct lf_vftable +{ + uint16_t size; + uint16_t kind; + uint32_t type; + uint32_t base_vftable; + uint32_t offset; + uint32_t names_len; + char names[]; +} ATTRIBUTE_PACKED; + /* DATASYM32 in cvinfo.h */ struct datasym { diff --git a/ld/testsuite/ld-pe/pdb-types1-hashlist.d b/ld/testsuite/ld-pe/pdb-types1-hashlist.d index aa00aaf7593..7d314edb670 100644 --- a/ld/testsuite/ld-pe/pdb-types1-hashlist.d +++ b/ld/testsuite/ld-pe/pdb-types1-hashlist.d @@ -12,4 +12,4 @@ Contents of section .data: 0070 4d5e0200 8a940200 4b710300 6aa90300 * 0080 0a2c0300 67e10300 4a3d0300 fa460300 * 0090 db020200 ec4e0100 131e0300 fb120300 * - 00a0 aece0200 1db70100 * \ No newline at end of file + 00a0 aece0200 1db70100 99a30000 a8010100 * \ No newline at end of file diff --git a/ld/testsuite/ld-pe/pdb-types1-typelist.d b/ld/testsuite/ld-pe/pdb-types1-typelist.d index df862c3f837..248dda50d2d 100644 --- a/ld/testsuite/ld-pe/pdb-types1-typelist.d +++ b/ld/testsuite/ld-pe/pdb-types1-typelist.d @@ -71,4 +71,10 @@ Contents of section .data: 0420 25100000 0480c0d4 0100f2f1 0d150300 %............... 0430 23100000 00006400 26000312 01140000 #.....d.&....... 0440 25100000 00000000 028060ea 0480c0d4 %.........`..... - 0450 0100f2f1 0d150300 23100000 00006400 ........#.....d. \ No newline at end of file + 0450 0100f2f1 0d150300 23100000 00006400 ........#.....d. + 0460 1e000515 00008000 00000000 00000000 ................ + 0470 00000000 00004955 6e6b6e6f 776e00f1 ......IUnknown.. + 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.. \ No newline at end of file diff --git a/ld/testsuite/ld-pe/pdb-types1b.s b/ld/testsuite/ld-pe/pdb-types1b.s index 544b338c251..bd227b12ebc 100644 --- a/ld/testsuite/ld-pe/pdb-types1b.s +++ b/ld/testsuite/ld-pe/pdb-types1b.s @@ -30,6 +30,7 @@ .equ LF_METHOD, 0x150f .equ LF_NESTTYPE, 0x1510 .equ LF_ONEMETHOD, 0x1511 +.equ LF_VFTABLE, 0x151d .equ LF_USHORT, 0x8002 .equ LF_LONG, 0x8003 @@ -559,7 +560,7 @@ # Type 1028, field list with virtual base class longstruct .fieldlist11: -.short .types_end - .fieldlist11 - 2 +.short .struct6 - .fieldlist11 - 2 .short LF_FIELDLIST .short LF_VBCLASS .short 0 # attributes @@ -577,4 +578,33 @@ .short 0 # offset .asciz "d" +# Type 1029, forward declaration of struct IUnknown +.struct6: +.short .vftable1 - .struct6 - 2 +.short LF_STRUCTURE +.short 0 # no. members +.short 0x80 # property (forward declaration) +.long 0 # field list +.long 0 # type derived from +.long 0 # type of vshape table +.short 0 # size +.asciz "IUnknown" # name +.byte 0xf1 # padding + +# Type 102a, virtual function table +.vftable1: +.short .types_end - .vftable1 - 2 +.short LF_VFTABLE +.long 0x1029 # type +.long 0 # base vftable +.long 0 # offset +.long .vftable1_names_end - .vftable1_names # length of names array +.vftable1_names: +.asciz "IUnknown" +.asciz "QueryInterface" +.asciz "AddRef" +.asciz "Release" +.vftable1_names_end: +.byte 0xf1 # padding + .types_end: diff --git a/ld/testsuite/ld-pe/pdb.exp b/ld/testsuite/ld-pe/pdb.exp index fbc0cf949f1..b2016313e96 100644 --- a/ld/testsuite/ld-pe/pdb.exp +++ b/ld/testsuite/ld-pe/pdb.exp @@ -1029,7 +1029,7 @@ proc test5 { } { binary scan $data i end_type # end_type is one greater than the last type in the stream - if { $end_type != 0x102a } { + if { $end_type != 0x102c } { fail "Incorrect end type value in TPI stream." } else { pass "Correct end type value in TPI stream."