From patchwork Tue Jun 18 00:17:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 1948909 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=harmstone.com header.i=@harmstone.com header.a=rsa-sha256 header.s=mail header.b=xwGqHIL8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W36qp4Y6kz20KL for ; Tue, 18 Jun 2024 10:21:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2D573882176 for ; Tue, 18 Jun 2024 00:21:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.burntcomma.com (mail.burntcomma.com [IPv6:2a02:8012:8cf0:250::6d61:696c]) by sourceware.org (Postfix) with ESMTPS id 4D4FF3882107 for ; Tue, 18 Jun 2024 00:17:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D4FF3882107 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 4D4FF3882107 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=ctIaJX6uQK5oN3+Ls4rYtEKBKFP682hJJTSqX/Cxgo2iVmgUO/uglp+NxkLcLcdUKIZpVucsWQSUjfGEr1gHM7iIeZAgS9r2fgOEybGmx9IIlj2pemMBc9Y9nZ4BV8p+vNgEJYj1XBG390julaWZivc9KRjwTgJopJF4lgCjR1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718669923; c=relaxed/simple; bh=V/226VF+qSdvoUPm6Adm8R6pCtSQVQsKDop9Qb6gUu0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=IOW5+RAhAeFsf0Qv9y0dfycKOcU1cXb++lDiIbB8qUKJ10sPU6NH7MK/oi7tyok6WUMx7WwFadL121rkP19qNOMzbOvK/gRUQfL/gU69+hrzwZQxL2lT6OvFSblKTVW1PBNE6Q/W/3XXis2cRQ65Z3k3OyCH7JbtROBdOeRzGRU= 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 41EEB3CF002A; 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=odhfeU67v+2hI5TrMZnNkJifJx9z47AOXIYyr2xgAf0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xwGqHIL8ojZtrxK5OZh52K3ceCmKIW+3ztgFzhI9mauISDfX2E8rSB6Bdaqa7M8HN +TYDe0j86VbGC3bzsH3k8iaoEmm15wvy37woUxP85FJY7/F6043SOrRWLIKWJ8vzdS EJrV/qwn82+5+DPYeLqqrtnhDijWSlw8DDMV2TZ4= From: Mark Harmstone To: gcc-patches@gcc.gnu.org Cc: Mark Harmstone Subject: [PATCH 10/11] Handle bitfields for CodeView Date: Tue, 18 Jun 2024 01:17:12 +0100 Message-ID: <20240618001713.24034-11-mark@harmstone.com> In-Reply-To: <20240618001713.24034-1-mark@harmstone.com> References: <20240618001713.24034-1-mark@harmstone.com> Mime-Version: 1.0 X-Spam-Status: No, score=-12.6 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Translates structure members with DW_AT_data_bit_offset set in DWARF into LF_BITFIELD symbols. gcc/ * dwarf2codeview.cc (struct codeview_custom_type): Add lf_bitfield to union. (write_lf_bitfield): New function. (write_custom_types): Call write_lf_bitfield. (create_bitfield): New function. (get_type_num_struct): Handle bitfields. * dwarf2codeview.h (LF_BITFIELD): Define. --- gcc/dwarf2codeview.cc | 89 ++++++++++++++++++++++++++++++++++++++++++- gcc/dwarf2codeview.h | 1 + 2 files changed, 88 insertions(+), 2 deletions(-) diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc index 3f1ce5577fc..06267639169 100644 --- a/gcc/dwarf2codeview.cc +++ b/gcc/dwarf2codeview.cc @@ -256,6 +256,12 @@ struct codeview_custom_type uint32_t index_type; codeview_integer length_in_bytes; } lf_array; + struct + { + uint32_t base_type; + uint8_t length; + uint8_t position; + } lf_bitfield; }; }; @@ -1573,6 +1579,50 @@ write_lf_array (codeview_custom_type *t) asm_fprintf (asm_out_file, "%LLcv_type%x_end:\n", t->num); } +/* Write an LF_BITFIELD type. */ + +static void +write_lf_bitfield (codeview_custom_type *t) +{ + /* This is lf_bitfield in binutils and lfBitfield in Microsoft's cvinfo.h: + + struct lf_bitfield + { + uint16_t size; + uint16_t kind; + uint32_t base_type; + uint8_t length; + uint8_t position; + } 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 (4, false), asm_out_file); + fprint_whex (asm_out_file, t->lf_bitfield.base_type); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (1, false), asm_out_file); + fprint_whex (asm_out_file, t->lf_bitfield.length); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (1, false), asm_out_file); + fprint_whex (asm_out_file, t->lf_bitfield.position); + putc ('\n', asm_out_file); + + write_cv_padding (2); + + 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. */ @@ -1619,6 +1669,10 @@ write_custom_types (void) case LF_ARRAY: write_lf_array (custom_types); break; + + case LF_BITFIELD: + write_lf_bitfield (custom_types); + break; } free (custom_types); @@ -2199,6 +2253,33 @@ add_struct_forward_def (dw_die_ref type) return ct->num; } +/* Add an LF_BITFIELD type, returning its number. DWARF represents bitfields + as members in a struct with a DW_AT_data_bit_offset attribute, whereas in + CodeView they're a distinct type. */ + +static uint32_t +create_bitfield (dw_die_ref c) +{ + codeview_custom_type *ct; + uint32_t base_type; + + base_type = get_type_num (get_AT_ref (c, DW_AT_type), true, false); + if (base_type == 0) + return 0; + + ct = (codeview_custom_type *) xmalloc (sizeof (codeview_custom_type)); + + ct->next = NULL; + ct->kind = LF_BITFIELD; + ct->lf_bitfield.base_type = base_type; + ct->lf_bitfield.length = get_AT_unsigned (c, DW_AT_bit_size); + ct->lf_bitfield.position = get_AT_unsigned (c, DW_AT_data_bit_offset); + + add_custom_type (ct); + + return ct->num; +} + /* 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. */ @@ -2279,8 +2360,12 @@ get_type_num_struct (dw_die_ref type, bool in_struct, bool *is_fwd_ref) break; } - el->lf_member.type = get_type_num (get_AT_ref (c, DW_AT_type), true, - false); + if (get_AT (c, DW_AT_data_bit_offset)) + el->lf_member.type = create_bitfield (c); + else + el->lf_member.type = get_type_num (get_AT_ref (c, DW_AT_type), + true, false); + el->lf_member.offset.neg = false; el->lf_member.offset.num = get_AT_unsigned (c, DW_AT_data_member_location); diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h index 70eed6bf2aa..70eae554b80 100644 --- a/gcc/dwarf2codeview.h +++ b/gcc/dwarf2codeview.h @@ -64,6 +64,7 @@ along with GCC; see the file COPYING3. If not see #define LF_MODIFIER 0x1001 #define LF_POINTER 0x1002 #define LF_FIELDLIST 0x1203 +#define LF_BITFIELD 0x1205 #define LF_INDEX 0x1404 #define LF_ENUMERATE 0x1502 #define LF_ARRAY 0x1503