From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.burntcomma.com (mail.burntcomma.com [IPv6:2a02:8012:8cf0:250::6d61:696c]) by sourceware.org (Postfix) with ESMTPS id 38D9F386103B for ; Tue, 18 Jun 2024 00:17:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 38D9F386103B 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 38D9F386103B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a02:8012:8cf0:250::6d61:696c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718669923; cv=none; b=baE1TGSMuDehaDHmkL8u7GkOTloe67ksIZ/wcqc96XQCsPMtAkVeoKx5Wi+JqLcpG74sAqwm/MGsJWvRKs2/93Xy49Cm1P5X2b72K6H5sxpGANqKq6yXFs1t+xwguoWFlWhzJIWE49BGZcYkDaA3WPYiPe1lrrIfMdXuojq+sNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718669923; c=relaxed/simple; bh=6gMBbS0NuY+YVFFXV2qHG+FFcmqnz60DAijoncAVWDU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=ecvvPrkemVNxhjzkYNcTevMBJjrdsE7u+yCv6KctdIyNzJ3Brv6JHRJkmYMupxVdRT6RktPDokpmdYRD3IltLkQzsMF+LJr6plTdgLE0ioVwXkkZnpydnd3pre0vnQu3wygEVRxT8981vn3uwyDEejaxqsr0aHpy0wf3Fha45F4= 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 0E7F63CF0024; Tue, 18 Jun 2024 01:17:22 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmstone.com; s=mail; t=1718669842; bh=tYZkqT33MYDHUCprh9UbHDAJTSPMZeKPbGpKqkdex3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fqlui8EuWByTbyhz9k+tJS3211nK4YMpbvfc033QDr1pq3hQU9O2DquFW4jQfcRzw ilFWL/hL1e3x6KBEYm4g8oJ7Fzc0/8eLCLFk6Vn0r4aA/8v+kjUxYQEtZdejf3awbR zIeZFqwGfeK8Em7E8pyHIkloOCjcfGaQlHYXentQ= From: Mark Harmstone To: gcc-patches@gcc.gnu.org Cc: Mark Harmstone Subject: [PATCH 08/11] Handle unions for CodeView. Date: Tue, 18 Jun 2024 01:17:10 +0100 Message-ID: <20240618001713.24034-9-mark@harmstone.com> In-Reply-To: <20240618001713.24034-1-mark@harmstone.com> References: <20240618001713.24034-1-mark@harmstone.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE 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: Translates DW_TAG_union_type DIEs into LF_UNION symbols. gcc/ * dwarf2codeview.cc (write_lf_union): New function. (write_custom_types): Call write_lf_union. (add_struct_forward_def): Handle DW_TAG_union_type DIEs. (get_type_num_struct): Handle unions. (get_type_num): Handle DW_TAG_union_type DIEs. * dwarf2codeview.h (LF_UNION): Define. --- gcc/dwarf2codeview.cc | 91 ++++++++++++++++++++++++++++++++++++++++--- gcc/dwarf2codeview.h | 1 + 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc index 9c6614f6297..9e3b64522b2 100644 --- a/gcc/dwarf2codeview.cc +++ b/gcc/dwarf2codeview.cc @@ -1454,6 +1454,72 @@ write_lf_structure (codeview_custom_type *t) asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num); } +/* Write an LF_UNION type. */ + +static void +write_lf_union (codeview_custom_type *t) +{ + size_t name_len, leaf_len; + + /* This is lf_union in binutils and lfUnion in Microsoft's cvinfo.h: + + struct lf_union + { + uint16_t size; + uint16_t kind; + uint16_t num_members; + uint16_t properties; + uint32_t field_list; + uint16_t length; + char name[]; + } ATTRIBUTE_PACKED; + */ + + fputs (integer_asm_op (2, false), asm_out_file); + asm_fprintf (asm_out_file, "%LLcv_type%x_end - %LLcv_type%x_start\n", + t->num, t->num); + + asm_fprintf (asm_out_file, "%LLcv_type%x_start:\n", t->num); + + fputs (integer_asm_op (2, false), asm_out_file); + fprint_whex (asm_out_file, t->kind); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (2, false), asm_out_file); + fprint_whex (asm_out_file, t->lf_structure.num_members); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (2, false), asm_out_file); + fprint_whex (asm_out_file, t->lf_structure.properties); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, t->lf_structure.field_list); + putc ('\n', asm_out_file); + + leaf_len = 12 + write_cv_integer (&t->lf_structure.length); + + if (t->lf_structure.name) + { + name_len = strlen (t->lf_structure.name) + 1; + ASM_OUTPUT_ASCII (asm_out_file, t->lf_structure.name, name_len); + } + else + { + static const char unnamed_struct[] = ""; + + name_len = sizeof (unnamed_struct); + ASM_OUTPUT_ASCII (asm_out_file, unnamed_struct, name_len); + } + + leaf_len += name_len; + write_cv_padding (4 - (leaf_len % 4)); + + free (t->lf_structure.name); + + asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num); +} + /* Write the .debug$T section, which contains all of our custom type definitions. */ @@ -1492,6 +1558,10 @@ write_custom_types (void) case LF_CLASS: write_lf_structure (custom_types); break; + + case LF_UNION: + write_lf_union (custom_types); + break; } free (custom_types); @@ -2026,7 +2096,7 @@ flush_deferred_types (void) last_deferred_type = NULL; } -/* Add a forward definition for a struct or class. */ +/* Add a forward definition for a struct, class, or union. */ static uint32_t add_struct_forward_def (dw_die_ref type) @@ -2047,6 +2117,10 @@ add_struct_forward_def (dw_die_ref type) ct->kind = LF_STRUCTURE; break; + case DW_TAG_union_type: + ct->kind = LF_UNION; + break; + default: break; } @@ -2068,9 +2142,9 @@ add_struct_forward_def (dw_die_ref type) return ct->num; } -/* Process a DW_TAG_structure_type or DW_TAG_class_type DIE, add an - LF_FIELDLIST and an LF_STRUCTURE / LF_CLASS type, and return the number of - the latter. */ +/* Process a DW_TAG_structure_type, DW_TAG_class_type, or DW_TAG_union_type + DIE, add an LF_FIELDLIST and an LF_STRUCTURE / LF_CLASS / LF_UNION type, + and return the number of the latter. */ static uint32_t get_type_num_struct (dw_die_ref type, bool in_struct, bool *is_fwd_ref) @@ -2227,8 +2301,8 @@ get_type_num_struct (dw_die_ref type, bool in_struct, bool *is_fwd_ref) ct = ct2; } - /* Now add an LF_STRUCTURE / LF_CLASS, pointing to the LF_FIELDLIST we just - added. */ + /* Now add an LF_STRUCTURE / LF_CLASS / LF_UNION, pointing to the + LF_FIELDLIST we just added. */ ct = (codeview_custom_type *) xmalloc (sizeof (codeview_custom_type)); @@ -2244,6 +2318,10 @@ get_type_num_struct (dw_die_ref type, bool in_struct, bool *is_fwd_ref) ct->kind = LF_STRUCTURE; break; + case DW_TAG_union_type: + ct->kind = LF_UNION; + break; + default: break; } @@ -2325,6 +2403,7 @@ get_type_num (dw_die_ref type, bool in_struct, bool no_fwd_ref) case DW_TAG_structure_type: case DW_TAG_class_type: + case DW_TAG_union_type: num = get_type_num_struct (type, in_struct, &is_fwd_ref); break; diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h index d4740247d93..e60fe86e673 100644 --- a/gcc/dwarf2codeview.h +++ b/gcc/dwarf2codeview.h @@ -68,6 +68,7 @@ along with GCC; see the file COPYING3. If not see #define LF_ENUMERATE 0x1502 #define LF_CLASS 0x1504 #define LF_STRUCTURE 0x1505 +#define LF_UNION 0x1506 #define LF_ENUM 0x1507 #define LF_MEMBER 0x150d #define LF_CHAR 0x8000 -- 2.44.2