From patchwork Mon Oct 23 00:55:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 156616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1010700vqx; Sun, 22 Oct 2023 17:56:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFMy2oN3EF4HKSbfE2nB93A8IV4VVp7gF3OwWESAlrJ78zDkpA0OL14IgwowAxE2ynQKPRs X-Received: by 2002:a05:6214:d64:b0:66d:3690:7c2f with SMTP id 4-20020a0562140d6400b0066d36907c2fmr10369107qvs.51.1698022575004; Sun, 22 Oct 2023 17:56:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698022574; cv=pass; d=google.com; s=arc-20160816; b=MjHV9Ya33Nm9ugXLdBxV9eWZG3d0MN6SFWmpFz/ASuGx2D+GZObMhSf+30qH1J2Kea gG/6hIplsSSedllPrFnyQGR8a+d8NGbrDEwZMBaOFhPn9iBVjqYPb3bL5O6F0HRvFvLN iIwPLeGLcpEG1Ord6B9ZqzFj0puzY/HNl+LE9WfNDIaxN7c05PI5M0ul2NlE1wtQPq7L y1TmmDsHLvkFqb5/UyQ58x5zntvi3hfZQcMOYt4WJfRlnqFU9yRPHHSPth/utE2rFKZQ zE+uZYU8SDsQ+lEshnJmJXTPMLKCb8C9NVyVuyBCVfCAoGHO9YipODp0QkOZsRUgFSPC eZjg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=5TRdKfa2zYTXWTREv7DgMQEiHoy3A74zjqHF6ceYHDE=; fh=ULVDVi0LXJXve4bv6avxt5t1j9fbG672tLMzvs8AGaA=; b=aUJOiAuYG1SmiyXG4tOIk2WRgHqZ0tYpiHCgqpCc2cvDdeCQfmvAuIcPo8mt0hCZ1a AxTtnonzIJGlHDBtbSkdnnmnp9LPi1BnpBkGc93PhLL+m+KNZQqtNsoyo9msJBOtoHZC 0B+5JlJEG8EGt3xWswWuCxhz7nNQ9Q+Ga4UgpxUaZvaWxgw3qpofzO8T1rGRFdjxbdvj GvqPrEZXF5YGFT+XjstnzcRKmV6IcMWOXOURcKCUIyLICu/s8S7uQgDVvddtKTQLSqjg kipbjajI40CcCepByfK6gB9r74jtKwlg9dISs6+wbVVtfByefZdboFUsG4AiWYRrT0B1 PsBQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@harmstone.com header.s=mail header.b=26TnJlTK; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l9-20020a0cd6c9000000b006585a789586si4903366qvi.216.2023.10.22.17.56.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 17:56:14 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@harmstone.com header.s=mail header.b=26TnJlTK; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C30923858423 for ; Mon, 23 Oct 2023 00:56:14 +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 40D133858CDB for ; Mon, 23 Oct 2023 00:55:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40D133858CDB Authentication-Results: sourceware.org; dmarc=none (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 40D133858CDB 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=1698022546; cv=none; b=G6lsebNuYhpWH3rEYpZKeP0CK6FWBTV2hrQ421c9NLlQxd8/d8CoIdNGkJCT5GXHjOYg57hZyDHQHwvw0wKjda55uI3FJUO88yEb6lwNkWk3QzlRrLaH2r05BvlKqO+jkLAa/MYsgwGSp38BCVDz203i4T89jm70k9fFRYlnGi4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698022546; c=relaxed/simple; bh=uubnNE727r2+yvEi1+MhP5bdjyQTwyoKedroeBgwsGA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=wgy83I2zpZ+F8JrHjm7aTtT025pMQgI3RQ7kAlBe0JqUQfooUCV+WGYOTgr9SmQObOvAvxJMK4vQND7mGJAPXQmKbMa5QtLM3xn2+WcjuACLMS2YQIYi+qX6B3BrM0DP4QZh3Qj+43HMHNFwhzTHMkkR9kyL97q8akglpgJsdEI= 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 C49E816B3209D; Mon, 23 Oct 2023 01:55:42 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmstone.com; s=mail; t=1698022542; bh=5TRdKfa2zYTXWTREv7DgMQEiHoy3A74zjqHF6ceYHDE=; h=From:To:Cc:Subject:Date; b=26TnJlTKiSeLZXJjDWt68ue6bkJj0xNzll6n2+5ygl/f+F/1noEDVpVLtPO9DQ6hm w8WuLIRR11QR2s8sA4Vo49wFChuNlzJ7jfpBh2nOPaSuDJet5zkvwqlcmw5vXvRlGt knGaG1hdmjAhOnKb6Zp4x7qU8aP9xp+qRBdgd7QM= From: Mark Harmstone To: gcc-patches@gcc.gnu.org Cc: Mark Harmstone Subject: [PATCH 1/5] Remove obsolete debugging formats from names list Date: Mon, 23 Oct 2023 01:55:27 +0100 Message-ID: <20231023005531.19921-1-mark@harmstone.com> Mime-Version: 1.0 X-Spam-Status: No, score=-14.0 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: 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780505719389539512 X-GMAIL-MSGID: 1780505719389539512 STABS and xcoff have been removed, but are still in debug_type_names, which ought to match debug_type_masks. This results in the following minor bug with GCC 13: $ x86_64-pc-linux-gnu-gcc -gvms -c tmp.c cc1: error: target system does not support the ‘dwarf-2’ debug format --- gcc/opts.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/opts.cc b/gcc/opts.cc index 573dcf8e497..8015cb7556a 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -50,7 +50,7 @@ static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff); const char *const debug_type_names[] = { - "none", "stabs", "dwarf-2", "xcoff", "vms", "ctf", "btf" + "none", "dwarf-2", "vms", "ctf", "btf" }; /* Bitmasks of fundamental debug info formats indexed by enum @@ -65,7 +65,7 @@ static uint32_t debug_type_masks[] = /* Names of the set of debug formats requested by user. Updated and accessed via debug_set_names. */ -static char df_set_names[sizeof "none stabs dwarf-2 xcoff vms ctf btf"]; +static char df_set_names[sizeof "none dwarf-2 vms ctf btf"]; /* Get enum debug_info_type of the specified debug format, for error messages. Can be used only for individual debug format types. */ From patchwork Mon Oct 23 00:55:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 156621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1011011vqx; Sun, 22 Oct 2023 17:57:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IECbWxR4wXRf1sOrH59URnIhnr97HoS1gbfge7rO+eubhEsoBv7oRURcyGFCzdStY6L8ZNU X-Received: by 2002:a05:620a:2550:b0:76a:eeb6:dd7b with SMTP id s16-20020a05620a255000b0076aeeb6dd7bmr9583063qko.75.1698022638330; Sun, 22 Oct 2023 17:57:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698022638; cv=pass; d=google.com; s=arc-20160816; b=bAVRIxMxQ8aofEjDybeYVqOJ/wfLxEflP0bY1bJfycKvt0UfaUD/sKM54o3BUdLltw A4wG2k73DmaAzffKMsp4HTuUjk3IqJ4L/nsLsUehPJLRuad9tZ+w7MK2juTuHd8sEjSb EPW8kI3cjLBanfom9/99NpYHXVysRwF1AeypelTxsHf6LTG1J0hyzLT0X1989Xb0X5ia CM6e0B37w1Gf6bKEsc5q9hNwcYCHIiPsFNLV/AuTWGahPvToAmPV5SoHU1UhbYZgp2Fk zfumQQ2ui6gUFUiDazc8no0xZxXLlgHPJAWa47wXMCgNOmp70ZOXaBafNpfrPE7mZOgR wYNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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:arc-filter:dmarc-filter:delivered-to; bh=N+KZkIcnm6BHU2Ve1gdV+wtnXQiJ/ysoN4jpq6n6sQk=; fh=ULVDVi0LXJXve4bv6avxt5t1j9fbG672tLMzvs8AGaA=; b=cNttBs1RAzkZTbZH1PcuZZ97vBSWpD1VGhpxaxzM1R/YMi08anl2G+i75Qr2utCTJY dhZOc+hHWp92YgaEL7bjM+oKYByxd0tUIQBeOZKVhmzBGFMPRqjNAB2yt+8aUUpLrc7e UDlc6/wsWt2B+yG37iW9hYrLWhOFqoqsIPeEbEiDoEDoufp/F9DvGNApaiNdbqfQ3Adh LFmkGT95dIglogoW8TPu1NUXWhgPYly+KZOilxDnTtHVxWVt3GrJzYgxrN3nwn3yHjwh BsHlp57CKEM4vaaFxhQhnGbSkzsk9p4TXBXU2pYkzYgA3SJDHDFoVioXWX+hB++YjjXa tjRw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@harmstone.com header.s=mail header.b="c/QO9i4y"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id k6-20020a05620a0b8600b00775743d508bsi4542831qkh.441.2023.10.22.17.57.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 17:57:18 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@harmstone.com header.s=mail header.b="c/QO9i4y"; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A2F73858002 for ; Mon, 23 Oct 2023 00:57:18 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.burntcomma.com (mail2.burntcomma.com [217.169.27.34]) by sourceware.org (Postfix) with ESMTPS id 373893858D37 for ; Mon, 23 Oct 2023 00:55:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 373893858D37 Authentication-Results: sourceware.org; dmarc=none (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 373893858D37 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=1698022547; cv=none; b=vGF6uHq05COf/iCeCoKtSryZ8mGYhxx5v9M1fSX9C29sAYhvU9QZD7F4sjOe8iIrjXdCvvLujrafdFUnlPeP5p1J/RHzT50Rv1dHYDALkyRu2vhIcKy1ddDO7S//rc9ExWq5XcCpmSBc8+LhUwCzC00l0hdo7Gzcs5g1w+rrZnY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698022547; c=relaxed/simple; bh=/I92ITRvMxp+yEagxvSzDGxEHCiS3vaUBQ9Ocqan3+4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=R7fShQyFf/3vAWXmv/JLfAVj6kzj0eJj2I2tBPw62D7PDXyJTzP63wagwnfL0pw570wTHm+md2mehrCn0x/9fqsciUKlJh7mrRaBERCqiJ/rHRxSeOx8KJipxWqgq2VPvI8wkTskUrQeN9b+kZH6Ymr4U3uzPj4IHF9He1ekQm8= 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 A88FC16B320A0; Mon, 23 Oct 2023 01:55:43 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmstone.com; s=mail; t=1698022543; bh=N+KZkIcnm6BHU2Ve1gdV+wtnXQiJ/ysoN4jpq6n6sQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=c/QO9i4yAOdjmOqI14DtyCkeqOF9mBdQ2FmBzIxiRnNujgd4o4HlLlqynt2kXkrAD hSSlxHc+oEX76IW4vUm+gJaIbgg1P4g0HpnM+dXQs3OMTJvBpMXG07HUkcB8izZDRM gz6bENHBA8/wkpbTfTw38ikiXM4V3AVyrJ7wDlgs= From: Mark Harmstone To: gcc-patches@gcc.gnu.org Cc: Mark Harmstone Subject: [PATCH 2/5] Support for CodeView debugging format Date: Mon, 23 Oct 2023 01:55:28 +0100 Message-ID: <20231023005531.19921-2-mark@harmstone.com> In-Reply-To: <20231023005531.19921-1-mark@harmstone.com> References: <20231023005531.19921-1-mark@harmstone.com> Mime-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780505785917757696 X-GMAIL-MSGID: 1780505785917757696 This patch and the following add initial support for Microsoft's CodeView debugging format, as used by MSVC, to mingw targets. Note that you will need a recent version of binutils for this to be useful. The best way to view the output is to run Microsoft's cvdump.exe, found in their microsoft-pdb repo on GitHub, against the object files. --- gcc/Makefile.in | 2 + gcc/config/i386/cygming.h | 2 + gcc/dwarf2codeview.cc | 50 +++++++++++++++++++ gcc/dwarf2codeview.h | 30 +++++++++++ gcc/dwarf2out.cc | 4 ++ gcc/flag-types.h | 3 ++ gcc/flags.h | 4 ++ gcc/opts.cc | 23 +++++++-- .../gcc.dg/debug/codeview/codeview-1.c | 6 +++ .../gcc.dg/debug/codeview/codeview.exp | 48 ++++++++++++++++++ gcc/toplev.cc | 4 ++ 11 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 gcc/dwarf2codeview.cc create mode 100644 gcc/dwarf2codeview.h create mode 100644 gcc/testsuite/gcc.dg/debug/codeview/codeview-1.c create mode 100644 gcc/testsuite/gcc.dg/debug/codeview/codeview.exp diff --git a/gcc/Makefile.in b/gcc/Makefile.in index a25a1e32fbc..d011946379d 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1428,6 +1428,7 @@ OBJS = \ dumpfile.o \ dwarf2asm.o \ dwarf2cfi.o \ + dwarf2codeview.o \ dwarf2ctf.o \ dwarf2out.o \ early-remat.o \ @@ -2794,6 +2795,7 @@ GTFILES = $(CPPLIB_H) $(srcdir)/input.h $(srcdir)/coretypes.h \ $(srcdir)/dwarf2out.h \ $(srcdir)/dwarf2asm.cc \ $(srcdir)/dwarf2cfi.cc \ + $(srcdir)/dwarf2codeview.cc \ $(srcdir)/dwarf2ctf.cc \ $(srcdir)/dwarf2out.cc \ $(srcdir)/ctfc.h \ diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h index d539f8d0699..a141462133b 100644 --- a/gcc/config/i386/cygming.h +++ b/gcc/config/i386/cygming.h @@ -20,6 +20,8 @@ along with GCC; see the file COPYING3. If not see #define DWARF2_DEBUGGING_INFO 1 +#define CODEVIEW_DEBUGGING_INFO 1 + #undef PREFERRED_DEBUGGING_TYPE #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc new file mode 100644 index 00000000000..e2bfdf8efeb --- /dev/null +++ b/gcc/dwarf2codeview.cc @@ -0,0 +1,50 @@ +/* Generate CodeView debugging info from the GCC DWARF. + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +/* See gas/codeview.h in binutils for more about the constants and structs + listed below. References to Microsoft files refer to Microsoft's PDB + repository: https://github.com/microsoft/microsoft-pdb. */ + +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "target.h" +#include "output.h" +#include "errors.h" +#include "md5.h" +#include "function.h" +#include "version.h" +#include "tree.h" +#include "langhooks.h" +#include "dwarf2out.h" +#include "dwarf2codeview.h" + +#define CV_SIGNATURE_C13 4 + +/* Finish CodeView debug info emission. */ + +void +codeview_debug_finish (void) +{ + targetm.asm_out.named_section (".debug$S", SECTION_DEBUG, NULL); + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, CV_SIGNATURE_C13); + putc ('\n', asm_out_file); +} diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h new file mode 100644 index 00000000000..efda148eb49 --- /dev/null +++ b/gcc/dwarf2codeview.h @@ -0,0 +1,30 @@ +/* dwarf2codeview.h - DWARF interface for CodeView generation. + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 3, or (at your option) any later +version. + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef GCC_DWARF2CODEVIEW_H +#define GCC_DWARF2CODEVIEW_H 1 + +#include "dwarf2out.h" +#include "flags.h" + +/* Debug Format Interface. Used in dwarf2out.cc. */ + +extern void codeview_debug_finish (void); + +#endif /* GCC_DWARF2CODEVIEW_H */ diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 0ea73bf782e..557464c4c24 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -80,6 +80,7 @@ along with GCC; see the file COPYING3. If not see #include "expr.h" #include "dwarf2out.h" #include "dwarf2ctf.h" +#include "dwarf2codeview.h" #include "dwarf2asm.h" #include "toplev.h" #include "md5.h" @@ -32207,6 +32208,9 @@ dwarf2out_finish (const char *filename) || btf_debuginfo_p ()) && lang_GNU_C ()) ctf_debug_finish (filename); + if (codeview_debuginfo_p ()) + codeview_debug_finish (); + /* Skip emitting DWARF if not required. */ if (!dwarf_debuginfo_p ()) return; diff --git a/gcc/flag-types.h b/gcc/flag-types.h index c1852cd810c..dae1d0a8095 100644 --- a/gcc/flag-types.h +++ b/gcc/flag-types.h @@ -29,6 +29,7 @@ enum debug_info_type DINFO_TYPE_VMS, /* VMS debug info. */ DINFO_TYPE_CTF, /* CTF debug info. */ DINFO_TYPE_BTF, /* BTF debug info. */ + DINFO_TYPE_CODEVIEW, /* CodeView debug info. */ DINFO_TYPE_BTF_WITH_CORE, /* BTF debug info with CO-RE relocations. */ DINFO_TYPE_MAX = DINFO_TYPE_BTF_WITH_CORE /* Marker only. */ }; @@ -42,6 +43,8 @@ enum debug_info_type #define CTF_DEBUG (1U << DINFO_TYPE_CTF) /* Write BTF debug info (using btfout.cc). */ #define BTF_DEBUG (1U << DINFO_TYPE_BTF) +/* Write CodeView debug info (using dwarf2codeview.cc). */ +#define CODEVIEW_DEBUG (1U << DINFO_TYPE_CODEVIEW) /* Write BTF debug info for BPF CO-RE usecase (using btfout.cc). */ #define BTF_WITH_CORE_DEBUG (1U << DINFO_TYPE_BTF_WITH_CORE) diff --git a/gcc/flags.h b/gcc/flags.h index e4bafa310d6..50036459328 100644 --- a/gcc/flags.h +++ b/gcc/flags.h @@ -53,6 +53,10 @@ extern bool btf_with_core_debuginfo_p (); extern bool ctf_debuginfo_p (); +/* Return true iff CodeView debug info is enabled. */ + +extern bool codeview_debuginfo_p (); + /* Return true iff DWARF2 debug info is enabled. */ extern bool dwarf_debuginfo_p (struct gcc_options *opts = &global_options); diff --git a/gcc/opts.cc b/gcc/opts.cc index 8015cb7556a..f02101ceea3 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -50,7 +50,7 @@ static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff); const char *const debug_type_names[] = { - "none", "dwarf-2", "vms", "ctf", "btf" + "none", "dwarf-2", "vms", "ctf", "btf", "codeview" }; /* Bitmasks of fundamental debug info formats indexed by enum @@ -59,13 +59,13 @@ const char *const debug_type_names[] = static uint32_t debug_type_masks[] = { NO_DEBUG, DWARF2_DEBUG, VMS_DEBUG, - CTF_DEBUG, BTF_DEBUG + CTF_DEBUG, BTF_DEBUG, CODEVIEW_DEBUG }; /* Names of the set of debug formats requested by user. Updated and accessed via debug_set_names. */ -static char df_set_names[sizeof "none dwarf-2 vms ctf btf"]; +static char df_set_names[sizeof "none dwarf-2 vms ctf btf codeview"]; /* Get enum debug_info_type of the specified debug format, for error messages. Can be used only for individual debug format types. */ @@ -159,6 +159,14 @@ ctf_debuginfo_p () return (write_symbols & CTF_DEBUG); } +/* Return TRUE iff CodeView debug info is enabled. */ + +bool +codeview_debuginfo_p () +{ + return (write_symbols & CODEVIEW_DEBUG); +} + /* Return TRUE iff dwarf2 debug info is enabled. */ bool @@ -173,7 +181,8 @@ dwarf_debuginfo_p (struct gcc_options *opts) bool dwarf_based_debuginfo_p () { return ((write_symbols & CTF_DEBUG) - || (write_symbols & BTF_DEBUG)); + || (write_symbols & BTF_DEBUG) + || (write_symbols & CODEVIEW_DEBUG)); } /* All flag uses below need to explicitely reference the option sets @@ -3145,6 +3154,9 @@ common_handle_option (struct gcc_options *opts, break; case OPT_gcodeview: + set_debug_level (CODEVIEW_DEBUG, false, arg, opts, opts_set, loc); + if (opts->x_debug_info_level < DINFO_LEVEL_NORMAL) + opts->x_debug_info_level = DINFO_LEVEL_NORMAL; break; case OPT_gbtf: @@ -3419,7 +3431,8 @@ set_debug_level (uint32_t dinfo, int extended, const char *arg, warning_at (loc, 0, "target system does not support debug output"); } else if ((opts->x_write_symbols & CTF_DEBUG) - || (opts->x_write_symbols & BTF_DEBUG)) + || (opts->x_write_symbols & BTF_DEBUG) + || (opts->x_write_symbols & CODEVIEW_DEBUG)) { opts->x_write_symbols |= DWARF2_DEBUG; opts_set->x_write_symbols |= DWARF2_DEBUG; diff --git a/gcc/testsuite/gcc.dg/debug/codeview/codeview-1.c b/gcc/testsuite/gcc.dg/debug/codeview/codeview-1.c new file mode 100644 index 00000000000..eb5f14530dc --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/codeview/codeview-1.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-gcodeview" } */ + +void func(void) +{ +} diff --git a/gcc/testsuite/gcc.dg/debug/codeview/codeview.exp b/gcc/testsuite/gcc.dg/debug/codeview/codeview.exp new file mode 100644 index 00000000000..ff705a4ae78 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/codeview/codeview.exp @@ -0,0 +1,48 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# GCC testsuite that uses the `dg.exp' driver. + +# Load support procs. +load_lib gcc-dg.exp + +if {![istarget i*86-*-mingw*] + && ![istarget x86_64-*-mingw*]} { + return 0 +} + +# If a testcase doesn't have special options, use these. +global DEFAULT_CFLAGS +if ![info exists DEFAULT_CFLAGS] then { + set DEFAULT_CFLAGS " -ansi -pedantic-errors" +} + +# Initialize `dg'. +dg-init + +# Main loop. +set comp_output [gcc_target_compile \ + "$srcdir/$subdir/../trivial.c" "trivial.S" assembly \ + "additional_flags=-gcodeview"] +if { ! [string match "*: target system does not support the * debug format*" \ + $comp_output] } { + remove-build-file "trivial.S" + dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\] ]] \ + "" $DEFAULT_CFLAGS +} + +# All done. +dg-finish diff --git a/gcc/toplev.cc b/gcc/toplev.cc index 8af9bf5090e..862583df0f4 100644 --- a/gcc/toplev.cc +++ b/gcc/toplev.cc @@ -1431,6 +1431,10 @@ process_options (bool no_backend) #ifdef DWARF2_LINENO_DEBUGGING_INFO else if (write_symbols == DWARF2_DEBUG) debug_hooks = &dwarf2_lineno_debug_hooks; +#endif +#ifdef CODEVIEW_DEBUGGING_INFO + else if (codeview_debuginfo_p ()) + debug_hooks = &dwarf2_debug_hooks; #endif else { From patchwork Mon Oct 23 00:55:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 156619 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1010831vqx; Sun, 22 Oct 2023 17:56:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGVy5ef4dJfokXIvBxeNEX2l8hWgjRwo14p//78A6QINzk+jmCQZJRu7yy75v6x2OqAOQT3 X-Received: by 2002:a05:620a:9cd:b0:778:9210:ceb3 with SMTP id y13-20020a05620a09cd00b007789210ceb3mr7481465qky.46.1698022600227; Sun, 22 Oct 2023 17:56:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698022600; cv=pass; d=google.com; s=arc-20160816; b=PHYkn/ts82hDwWNZfX3wTXgBhG5zUeUXI4F27vEII9RwXfEaXkeMiE6exDNO23IDZH Ykf1QntVyYUahMaCNHHI5If4QOHEzoRm0cE/huJP69Pn5+jc6QGPknGeQchEd6oBwsaV btVbcEH5zqN5El0Uq2UPYQpscL6DhJCOlqt9KMQ7+WNThk0Qnndv4FC8GwTc8y56GDhI nP8xGjCIc2P7QIGEe7r9AasFQQRk62XfylA9bY+zjG6gDMsKtTlWvrCjyMKGrcX55Gjd Vz2tk2jaou4E3YIBOD5paq9b+cgJ9BGckm3fdW5wnS09vp2ElQf5KeXj3jg1DmQQWhcF IM+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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:arc-filter:dmarc-filter:delivered-to; bh=tiGDOc2CZogh6wLQyUQIA8hUUKi+ZjzEG4mTVT3qGuI=; fh=ULVDVi0LXJXve4bv6avxt5t1j9fbG672tLMzvs8AGaA=; b=E6a3gJaJhuYf+sfbfoerNIUKI+iXsliAne0Dc53XUACtMLdskAAwZttYaZNXCOoxjZ uas62lLINrPwnuJt0muBQ1KES6RAXcOTruh514gQLVMptM4PiiY2xCqwQjHTuuAFBDpg lrCDWZM2tE9iQcoUfamPRAScTRe8/W8omZJNNA7Amb2KU1qc7Wj4bv9xCHnf4I3jcSvF f820sswJGcHOq7qKacpt+K+/z4CZh6ObvWiaXOtOPhyKWjzdKstog95WkK47xPxOXxlS j5eWPTC0Nt6gmQYgtCJetbw+uyTL4YhfUmlCyPQv30TcHWJ3A7Uv3UT2odDBrjP1fmCp 0LTA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@harmstone.com header.s=mail header.b=TBHL4Otu; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y30-20020a05620a0e1e00b00773b7d9a01esi4461728qkm.72.2023.10.22.17.56.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 17:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@harmstone.com header.s=mail header.b=TBHL4Otu; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 019593858410 for ; Mon, 23 Oct 2023 00:56:40 +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 3E1F43858CDA for ; Mon, 23 Oct 2023 00:55:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3E1F43858CDA Authentication-Results: sourceware.org; dmarc=none (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 3E1F43858CDA 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=1698022547; cv=none; b=eWe5tkvPTMDA1s+FnZgeMEk/Qz9mlq26AOf7iuuiEclBOIliHhq6R7YWPD0KJUevIxAukiggRQG0HLyn4XH95vQ1G6QOBf313QVuSNFeRWKT7HR4Xg2V6QZcUaCP6Q9PzUu2kuB89r5Qw0Xv0tYz3fN3/npYxTnMOMX9mOpiMI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698022547; c=relaxed/simple; bh=EGD5LLpbT5GrHKmqe+viLyfgxsF7YnXAaKbYQ6rw2qk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=wiM81kboLqkliEBfexTnqKTE6hd9XfxjigeGDCB4zLn3t/ml9oYxtqWlzzWl877+4x/J82nBkho3KBk1rtdXM26mElRQSK8Fmyxe0B6SysOv362btW53tVOueRI4zV5uD3ntVximBdNRfRwFk4dLDM9glHCbzCi2CY2aUG4tBLY= 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 BA10A16B320A3; Mon, 23 Oct 2023 01:55:43 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmstone.com; s=mail; t=1698022543; bh=tiGDOc2CZogh6wLQyUQIA8hUUKi+ZjzEG4mTVT3qGuI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TBHL4Oturn4bFgy4898c46GaCZvjT/Bk4RMuHVqzUdekamMzvVK3DO+2R9stuHs22 fg8p+1rgiOQdpEi8lgwLCNCJQydV1GdkO9jb8wzjdgQCX/uaCKciYsbFsJlNpe3uUC iZWi/2VdfWBbEergHToovKzhUKrSdou3fI92BHhU= From: Mark Harmstone To: gcc-patches@gcc.gnu.org Cc: Mark Harmstone Subject: [PATCH 3/5] Output file checksums in CodeView section Date: Mon, 23 Oct 2023 01:55:29 +0100 Message-ID: <20231023005531.19921-3-mark@harmstone.com> In-Reply-To: <20231023005531.19921-1-mark@harmstone.com> References: <20231023005531.19921-1-mark@harmstone.com> Mime-Version: 1.0 X-Spam-Status: No, score=-13.8 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: 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780505746152427298 X-GMAIL-MSGID: 1780505746152427298 Outputs the file name and MD5 hash of the main source file into the CodeView .debug$S section, along with that of any #include'd files. --- gcc/dwarf2codeview.cc | 254 ++++++++++++++++++++++++++++++++++++++++++ gcc/dwarf2codeview.h | 1 + gcc/dwarf2out.cc | 3 + 3 files changed, 258 insertions(+) diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc index e2bfdf8efeb..d93ba1ed668 100644 --- a/gcc/dwarf2codeview.cc +++ b/gcc/dwarf2codeview.cc @@ -37,6 +37,257 @@ along with GCC; see the file COPYING3. If not see #define CV_SIGNATURE_C13 4 +#define DEBUG_S_STRINGTABLE 0xf3 +#define DEBUG_S_FILECHKSMS 0xf4 + +#define CHKSUM_TYPE_MD5 1 + +#define HASH_SIZE 16 + +struct codeview_string +{ + codeview_string *next; + uint32_t offset; + char *string; +}; + +struct string_hasher : free_ptr_hash +{ + typedef const char *compare_type; + + static hashval_t hash (const codeview_string *x) + { + return htab_hash_string (x->string); + } + + static bool equal (const codeview_string *x, const char *y) + { + return !strcmp (x->string, y); + } + + static void mark_empty (codeview_string *x) + { + if (x->string) + { + free (x->string); + x->string = NULL; + } + } + + static void remove (codeview_string *&x) + { + free (x->string); + } +}; + +struct codeview_source_file +{ + codeview_source_file *next; + unsigned int file_num; + uint32_t string_offset; + char *filename; + uint8_t hash[HASH_SIZE]; +}; + +static codeview_source_file *files, *last_file; +static unsigned int num_files; +static uint32_t string_offset = 1; +static hash_table *strings_htab; +static codeview_string *strings, *last_string; + +/* Adds string to the string table, returning its offset. If already present, + this returns the offset of the existing string. */ + +static uint32_t +add_string (const char *string) +{ + codeview_string **slot; + codeview_string *s; + size_t len; + + if (!strings_htab) + strings_htab = new hash_table (10); + + slot = strings_htab->find_slot_with_hash (string, htab_hash_string (string), + INSERT); + + if (*slot) + return (*slot)->offset; + + s = (codeview_string *) xmalloc (sizeof (codeview_string)); + len = strlen (string); + + s->next = NULL; + + s->offset = string_offset; + string_offset += len + 1; + + s->string = xstrdup (string); + + if (last_string) + last_string->next = s; + else + strings = s; + + last_string = s; + + *slot = s; + + return s->offset; +} + +/* A new source file has been encountered - record the details and calculate + its hash. */ + +void +codeview_start_source_file (const char *filename) +{ + codeview_source_file *sf; + char *path; + uint32_t string_offset; + FILE *f; + + path = lrealpath (filename); + string_offset = add_string (path); + free (path); + + sf = files; + while (sf) + { + if (sf->string_offset == string_offset) + return; + + sf = sf->next; + } + + sf = (codeview_source_file *) xmalloc (sizeof (codeview_source_file)); + sf->next = NULL; + sf->file_num = num_files; + sf->string_offset = string_offset; + sf->filename = xstrdup (filename); + + f = fopen (filename, "r"); + if (!f) + internal_error ("could not open %s for reading", filename); + + if (md5_stream (f, sf->hash)) + { + fclose (f); + internal_error ("md5_stream failed"); + } + + fclose (f); + + if (last_file) + last_file->next = sf; + else + files = sf; + + last_file = sf; + num_files++; +} + +/* Write out the strings table into the .debug$S section. The linker will + parse this, and handle the deduplication and hashing for all the object + files. */ + +static void +write_strings_table (void) +{ + codeview_string *string; + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, DEBUG_S_STRINGTABLE); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + asm_fprintf (asm_out_file, "%LLcv_strings_end - %LLcv_strings_start\n"); + + asm_fprintf (asm_out_file, "%LLcv_strings_start:\n"); + + /* The first entry is always an empty string. */ + fputs (integer_asm_op (1, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + + string = strings; + while (string) + { + ASM_OUTPUT_ASCII (asm_out_file, string->string, + strlen (string->string) + 1); + + string = string->next; + } + + delete strings_htab; + + asm_fprintf (asm_out_file, "%LLcv_strings_end:\n"); + + ASM_OUTPUT_ALIGN (asm_out_file, 2); +} + +/* Write out the file checksums data into the .debug$S section. */ + +static void +write_source_files (void) +{ + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, DEBUG_S_FILECHKSMS); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + asm_fprintf (asm_out_file, + "%LLcv_filechksms_end - %LLcv_filechksms_start\n"); + + asm_fprintf (asm_out_file, "%LLcv_filechksms_start:\n"); + + while (files) + { + codeview_source_file *next = files->next; + + /* This is struct file_checksum in binutils, or filedata in Microsoft's + dumpsym7.cpp: + + struct file_checksum + { + uint32_t file_id; + uint8_t checksum_length; + uint8_t checksum_type; + } ATTRIBUTE_PACKED; + + followed then by the bytes of the hash, padded to the next 4 bytes. + file_id here is actually the offset in the strings table. */ + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, files->string_offset); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (1, false), asm_out_file); + fprint_whex (asm_out_file, HASH_SIZE); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (1, false), asm_out_file); + fprint_whex (asm_out_file, CHKSUM_TYPE_MD5); + putc ('\n', asm_out_file); + + for (unsigned int i = 0; i < HASH_SIZE; i++) + { + fputs (integer_asm_op (1, false), asm_out_file); + fprint_whex (asm_out_file, files->hash[i]); + putc ('\n', asm_out_file); + } + + ASM_OUTPUT_ALIGN (asm_out_file, 2); + + free (files->filename); + free (files); + + files = next; + } + + asm_fprintf (asm_out_file, "%LLcv_filechksms_end:\n"); +} + /* Finish CodeView debug info emission. */ void @@ -47,4 +298,7 @@ codeview_debug_finish (void) fputs (integer_asm_op (4, false), asm_out_file); fprint_whex (asm_out_file, CV_SIGNATURE_C13); putc ('\n', asm_out_file); + + write_strings_table (); + write_source_files (); } diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h index efda148eb49..e2d732bb9b6 100644 --- a/gcc/dwarf2codeview.h +++ b/gcc/dwarf2codeview.h @@ -26,5 +26,6 @@ along with GCC; see the file COPYING3. If not see /* Debug Format Interface. Used in dwarf2out.cc. */ extern void codeview_debug_finish (void); +extern void codeview_start_source_file (const char *); #endif /* GCC_DWARF2CODEVIEW_H */ diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 557464c4c24..945176a91bc 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -28823,6 +28823,9 @@ dwarf2out_set_ignored_loc (unsigned int line, unsigned int column, static void dwarf2out_start_source_file (unsigned int lineno, const char *filename) { + if (codeview_debuginfo_p ()) + codeview_start_source_file (filename); + if (debug_info_level >= DINFO_LEVEL_VERBOSE) { macinfo_entry e; From patchwork Mon Oct 23 00:55:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 156620 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1010968vqx; Sun, 22 Oct 2023 17:57:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHXMJSEHGR5/9waFcoePwd9FRb29LXDObvslkV9HB1gDS1IPVUQjNINk3zv0b96klv8Uf9z X-Received: by 2002:a05:620a:84c3:b0:773:c19f:9b9 with SMTP id pq3-20020a05620a84c300b00773c19f09b9mr7436888qkn.46.1698022630747; Sun, 22 Oct 2023 17:57:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698022630; cv=pass; d=google.com; s=arc-20160816; b=uHBsE9VtIakfviNdPCO9zNYZ9p7S8NSV7petK6teDfz1T2g7rTHXX5yzf9ONfNC8eL 2PqZ8uNa9RFM5NbnVefTK14BHM03PyCMLHGkLXIZQCi/ytFn7dCwaWOxt9wu0LwxZ1QS 8I7khUS+6Y2oqFTUck4WMCsjaC9WXBpYKZ+jOCH0+VRY6Tg0pTHi2WTfEb/WvsvFCON3 ZjrjLsaTzprE5fXQ9DZUShtD9JXdH9WCE9+0Pwa3xXsAp6qcfGZyMu3gjz362iqIKsdP ZSt21FxfcmgoWEia5YGpNLxvHVZDoMLgRhco94mowTFxtjfPXqGet6lgBCdq9Y6JF3zy NAxQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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:arc-filter:dmarc-filter:delivered-to; bh=4ME1+U6zxKWw4qftUFo6UCPZbj/CcEcXb9XHDCKNOUY=; fh=ULVDVi0LXJXve4bv6avxt5t1j9fbG672tLMzvs8AGaA=; b=E8pASM+ZUbyvncRQsMWe1/l23+m7DXCRvm18B1Gi3N3KqfB3vNiC0Uo1Q7FOA0GsWR IQgYO1rVmpj0FutVMag0GA6b7ikWoKt5NAa1AkPMoncnMAlVN0lSTsS1qIYWw1rYH9o1 id6YA+DxmXzUrlmZgnxdHYT7qfs5W8u5Dhagr8AYfkZaMNe14e5cOSVVKrYDJ5GS5tdb wntVQuGjJpnbmkFRrQFvFmqkzdtWLreQm4UWWN9bJAUNGlGFT2gWTslQzyCFJKDvG+UP wtPZv9IRpOEOmqZCrssmM8CVgqkr2Ne/gzMF/VpkFdToz8fCMuGRyayawcjBT49wgWXe wrnA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@harmstone.com header.s=mail header.b=z1dDKijI; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k9-20020a05620a0b8900b0076dac93a764si4780621qkh.379.2023.10.22.17.57.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 17:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.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=pass header.i=@harmstone.com header.s=mail header.b=z1dDKijI; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 808AA3858004 for ; Mon, 23 Oct 2023 00:57:10 +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 44DAD3858C41 for ; Mon, 23 Oct 2023 00:55:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44DAD3858C41 Authentication-Results: sourceware.org; dmarc=none (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 44DAD3858C41 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=1698022547; cv=none; b=Aoyxo0zoO0OEFCKzVjTEE01hURFPDWz/NMoQHCwLPy/Kb4D+LKng0Kc4kcO+oJALzvaF3j77D7U68/9Kt4/aFbOjDq+WdLW1oSefF41e/DJv9gTZqIyjv/9zW4OHWJZsRFs4Jm1aOKtJPnpgvsz4eV3T7A7BWWhQE1UAhH2NMB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698022547; c=relaxed/simple; bh=hY65c1jDyHmlDqU5OLZL3n8VgY5ckJX5YibFd8CToFo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=Dkowk16uPiueSj8cmoAfr1Nwuvvb2xUVCjlxtBfpn+UPJdyNF7GAAc+evw7kSnVkd798vMP2SGUoft7wbagqCdEj2YXfQkizW38bWJ55wZy2w1aTTdrNyY9IoV7Nbffw4cH8lk6nFDCia58Xo3+8FGPgx3U1HhoeRel1qwSNdWU= 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 D4F9916B320A6; Mon, 23 Oct 2023 01:55:43 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmstone.com; s=mail; t=1698022543; bh=4ME1+U6zxKWw4qftUFo6UCPZbj/CcEcXb9XHDCKNOUY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=z1dDKijIH8/lEGYYVgTDYw5AX1qx7nyXKQbjnmHD6w/EFriW9B62R0wm9sSfD/Lxr jJGojhHuYhrv2xayPdIet3kzPklfjr3IVV8lIkOHpwhd8JRFWibzd/wgaxGXJn7h22 DAYIyugzTwDZo2PjBR+Z8WMnAtmoeVyS3dVAdly8= From: Mark Harmstone To: gcc-patches@gcc.gnu.org Cc: Mark Harmstone Subject: [PATCH 4/5] Output line numbers in CodeView section Date: Mon, 23 Oct 2023 01:55:30 +0100 Message-ID: <20231023005531.19921-4-mark@harmstone.com> In-Reply-To: <20231023005531.19921-1-mark@harmstone.com> References: <20231023005531.19921-1-mark@harmstone.com> Mime-Version: 1.0 X-Spam-Status: No, score=-13.8 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: 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780505777854000063 X-GMAIL-MSGID: 1780505777854000063 Outputs the DEBUG_S_LINES block in the CodeView .debug$S section, which maps between line numbers and addresses. You'll need a fairly recent version of GAS for the .secidx directive to be recognized. --- gcc/dwarf2codeview.cc | 303 ++++++++++++++++++++++++++++++++++++++++++ gcc/dwarf2codeview.h | 3 + gcc/dwarf2out.cc | 9 ++ gcc/opts.cc | 2 +- 4 files changed, 316 insertions(+), 1 deletion(-) diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc index d93ba1ed668..4dfc0300177 100644 --- a/gcc/dwarf2codeview.cc +++ b/gcc/dwarf2codeview.cc @@ -37,11 +37,15 @@ along with GCC; see the file COPYING3. If not see #define CV_SIGNATURE_C13 4 +#define DEBUG_S_LINES 0xf2 #define DEBUG_S_STRINGTABLE 0xf3 #define DEBUG_S_FILECHKSMS 0xf4 #define CHKSUM_TYPE_MD5 1 +#define LINE_LABEL "Lcvline" +#define END_FUNC_LABEL "Lcvendfunc" + #define HASH_SIZE 16 struct codeview_string @@ -89,11 +93,128 @@ struct codeview_source_file uint8_t hash[HASH_SIZE]; }; +struct codeview_line +{ + codeview_line *next; + unsigned int line_no; + unsigned int label_num; +}; + +struct codeview_line_block +{ + codeview_line_block *next; + uint32_t file_id; + unsigned int num_lines; + codeview_line *lines, *last_line; +}; + +struct codeview_function +{ + codeview_function *next; + function *func; + unsigned int end_label; + codeview_line_block *blocks, *last_block; +}; + +static unsigned int line_label_num; +static unsigned int func_label_num; static codeview_source_file *files, *last_file; static unsigned int num_files; static uint32_t string_offset = 1; static hash_table *strings_htab; static codeview_string *strings, *last_string; +static codeview_function *funcs, *last_func; +static const char* last_filename; +static uint32_t last_file_id; + +/* Record new line number against the current function. */ + +void +codeview_source_line (unsigned int line_no, const char *filename) +{ + codeview_line *l; + uint32_t file_id = last_file_id; + unsigned int label_num = ++line_label_num; + + targetm.asm_out.internal_label (asm_out_file, LINE_LABEL, label_num); + + if (!last_func || last_func->func != cfun) + { + codeview_function *f = (codeview_function *) + xmalloc (sizeof (codeview_function)); + + f->next = NULL; + f->func = cfun; + f->end_label = 0; + f->blocks = f->last_block = NULL; + + if (!funcs) + funcs = f; + else + last_func->next = f; + + last_func = f; + } + + if (filename != last_filename) + { + codeview_source_file *sf = files; + + while (sf) + { + if (!strcmp (sf->filename, filename)) + { + /* 0x18 is the size of the checksum entry for each file. + 0x6 bytes for the header, plus 0x10 bytes for the hash, + then padded to a multiple of 4. */ + + file_id = sf->file_num * 0x18; + last_filename = filename; + last_file_id = file_id; + break; + } + + sf = sf->next; + } + } + + if (!last_func->last_block || last_func->last_block->file_id != file_id) + { + codeview_line_block *b; + + b = (codeview_line_block *) xmalloc (sizeof (codeview_line_block)); + + b->next = NULL; + b->file_id = file_id; + b->num_lines = 0; + b->lines = b->last_line = NULL; + + if (!last_func->blocks) + last_func->blocks = b; + else + last_func->last_block->next = b; + + last_func->last_block = b; + } + + if (last_func->last_block->last_line + && last_func->last_block->last_line->line_no == line_no) + return; + + l = (codeview_line *) xmalloc (sizeof (codeview_line)); + + l->next = NULL; + l->line_no = line_no; + l->label_num = label_num; + + if (!last_func->last_block->lines) + last_func->last_block->lines = l; + else + last_func->last_block->last_line->next = l; + + last_func->last_block->last_line = l; + last_func->last_block->num_lines++; +} /* Adds string to the string table, returning its offset. If already present, this returns the offset of the existing string. */ @@ -288,6 +409,187 @@ write_source_files (void) asm_fprintf (asm_out_file, "%LLcv_filechksms_end:\n"); } +/* Write out the line number information for each function into the + .debug$S section. */ + +static void +write_line_numbers (void) +{ + unsigned int func_num = 0; + + while (funcs) + { + codeview_function *next = funcs->next; + unsigned int first_label_num; + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, DEBUG_S_LINES); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + asm_fprintf (asm_out_file, "%LLcv_lines%u_end - %LLcv_lines%u_start\n", + func_num, func_num); + + asm_fprintf (asm_out_file, "%LLcv_lines%u_start:\n", func_num); + + /* Output the header (struct cv_lines_header in binutils or + CV_DebugSLinesHeader_t in Microsoft's cvinfo.h): + + struct cv_lines_header + { + uint32_t offset; + uint16_t section; + uint16_t flags; + uint32_t length; + }; + */ + + asm_fprintf (asm_out_file, "\t.secrel32\t%L" LINE_LABEL "%u\n", + funcs->blocks->lines->label_num); + asm_fprintf (asm_out_file, "\t.secidx\t%L" LINE_LABEL "%u\n", + funcs->blocks->lines->label_num); + + /* flags */ + fputs (integer_asm_op (2, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + + first_label_num = funcs->blocks->lines->label_num; + + /* length */ + fputs (integer_asm_op (4, false), asm_out_file); + asm_fprintf (asm_out_file, + "%L" END_FUNC_LABEL "%u - %L" LINE_LABEL "%u\n", + funcs->end_label, first_label_num); + + while (funcs->blocks) + { + codeview_line_block *next = funcs->blocks->next; + + /* Next comes the blocks, each block being a part of a function + within the same source file (struct cv_lines_block in binutils or + CV_DebugSLinesFileBlockHeader_t in Microsoft's cvinfo.h): + + struct cv_lines_block + { + uint32_t file_id; + uint32_t num_lines; + uint32_t length; + }; + */ + + /* file ID */ + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, funcs->blocks->file_id); + putc ('\n', asm_out_file); + + /* number of lines */ + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, funcs->blocks->num_lines); + putc ('\n', asm_out_file); + + /* length of code block: (num_lines * sizeof (struct cv_line)) + + sizeof (struct cv_lines_block) */ + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, (funcs->blocks->num_lines * 0x8) + 0xc); + putc ('\n', asm_out_file); + + while (funcs->blocks->lines) + { + codeview_line *next = funcs->blocks->lines->next; + + /* Finally comes the line number information (struct cv_line in + binutils or CV_Line_t in Microsoft's cvinfo.h): + + struct cv_line + { + uint32_t offset; + uint32_t line_no; + }; + + Strictly speaking line_no is a bitfield: the bottom 24 bits + are the line number, and the top bit means "is a statement". + */ + + fputs (integer_asm_op (4, false), asm_out_file); + asm_fprintf (asm_out_file, + "%L" LINE_LABEL "%u - %L" LINE_LABEL "%u\n", + funcs->blocks->lines->label_num, first_label_num); + + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, + 0x80000000 + | (funcs->blocks->lines->line_no & 0xffffff)); + putc ('\n', asm_out_file); + + free (funcs->blocks->lines); + + funcs->blocks->lines = next; + } + + free (funcs->blocks); + + funcs->blocks = next; + } + + free (funcs); + + asm_fprintf (asm_out_file, "%LLcv_lines%u_end:\n", func_num); + func_num++; + + funcs = next; + } +} + +/* Treat cold sections as separate functions, for the purposes of line + numbers. */ + +void +codeview_switch_text_section (void) +{ + codeview_function *f; + + if (last_func && last_func->end_label == 0) + { + unsigned int label_num = ++func_label_num; + + targetm.asm_out.internal_label (asm_out_file, END_FUNC_LABEL, + label_num); + + last_func->end_label = label_num; + } + + f = (codeview_function *) xmalloc (sizeof (codeview_function)); + + f->next = NULL; + f->func = cfun; + f->end_label = 0; + f->blocks = f->last_block = NULL; + + if (!funcs) + funcs = f; + else + last_func->next = f; + + last_func = f; +} + +/* Mark the end of the current function. */ + +void +codeview_end_epilogue (void) +{ + if (last_func && last_func->end_label == 0) + { + unsigned int label_num = ++func_label_num; + + targetm.asm_out.internal_label (asm_out_file, END_FUNC_LABEL, + label_num); + + last_func->end_label = label_num; + } +} + /* Finish CodeView debug info emission. */ void @@ -301,4 +603,5 @@ codeview_debug_finish (void) write_strings_table (); write_source_files (); + write_line_numbers (); } diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h index e2d732bb9b6..b6421b62d2e 100644 --- a/gcc/dwarf2codeview.h +++ b/gcc/dwarf2codeview.h @@ -26,6 +26,9 @@ along with GCC; see the file COPYING3. If not see /* Debug Format Interface. Used in dwarf2out.cc. */ extern void codeview_debug_finish (void); +extern void codeview_source_line (unsigned int, const char *); extern void codeview_start_source_file (const char *); +extern void codeview_switch_text_section (); +extern void codeview_end_epilogue (void); #endif /* GCC_DWARF2CODEVIEW_H */ diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc index 945176a91bc..c0ee99ffd40 100644 --- a/gcc/dwarf2out.cc +++ b/gcc/dwarf2out.cc @@ -1253,6 +1253,9 @@ dwarf2out_end_epilogue (unsigned int line ATTRIBUTE_UNUSED, if (dwarf2out_do_cfi_asm ()) fprintf (asm_out_file, "\t.cfi_endproc\n"); + if (codeview_debuginfo_p ()) + codeview_end_epilogue (); + /* Output a label to mark the endpoint of the code generated for this function. */ ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, @@ -1306,6 +1309,9 @@ dwarf2out_switch_text_section (void) } have_multiple_function_sections = true; + if (codeview_debuginfo_p ()) + codeview_switch_text_section (); + if (dwarf2out_do_cfi_asm ()) fprintf (asm_out_file, "\t.cfi_endproc\n"); @@ -28603,6 +28609,9 @@ dwarf2out_source_line (unsigned int line, unsigned int column, dw_line_info_table *table; static var_loc_view lvugid; + if (codeview_debuginfo_p ()) + codeview_source_line (line, filename); + /* 'line_info_table' information gathering is not needed when the debug info level is set to the lowest value. Also, the current DWARF-based debug formats do not use this info. */ diff --git a/gcc/opts.cc b/gcc/opts.cc index f02101ceea3..6e91b1e0ff9 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -1364,7 +1364,7 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, opts->x_debug_nonbind_markers_p = (opts->x_optimize && opts->x_debug_info_level >= DINFO_LEVEL_NORMAL - && dwarf_debuginfo_p (opts) + && (dwarf_debuginfo_p (opts) || codeview_debuginfo_p ()) && !(opts->x_flag_selective_scheduling || opts->x_flag_selective_scheduling2)); From patchwork Mon Oct 23 00:55:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Harmstone X-Patchwork-Id: 156617 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1010767vqx; Sun, 22 Oct 2023 17:56:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMQNrLgfHOTlAMsz+o49ZTfP5igFTudFzz9qC35XH2rY09/l+rxzWR+OOTzsoK0FIeaJft X-Received: by 2002:a05:6214:19c5:b0:66d:15c3:62cb with SMTP id j5-20020a05621419c500b0066d15c362cbmr10614933qvc.36.1698022588222; Sun, 22 Oct 2023 17:56:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698022588; cv=pass; d=google.com; s=arc-20160816; b=ZFD4aQqFZ4FCZuy3T27R5eMnQJVmoJOgy9DE3Ciw87oHMbgCnfMY8Al1krtwYn0v46 Ehe/mFt7GpBrbxho34yCB42dszfnpjTbeOPbRy588xR8crPjjrVxKJ0hCYr05DlxHlMb 3N1mqKZaFZpplCyXBIOtOU9OB5YQ0SEDB6K6J0zaqnH2KSfGwCdJEy9aBZg9Nj70J+2u ftaTRnTri+AWBEv2UrVL/UNkER9gAlVSUrqEH5V7WLWAjsMXdeisbnKV6suy+8bNh+O1 yJCvq/0iJAShMHh3z09lLZ7Lm8kMvhfwEFl62Iig3U4waQGOgqYt9kHU9mDw9Ezw8slx j4Zw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=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:arc-filter:dmarc-filter:delivered-to; bh=2XD+q9zMopUzwvoF14VWD1NogcvB94gfeiTrm3bzCKo=; fh=ULVDVi0LXJXve4bv6avxt5t1j9fbG672tLMzvs8AGaA=; b=wXVMMXFYJiGg82VEgYqRLEBB0VQq9GJbIfz4CM0WaQEVqn9pzd4jMCLLF1IbXXgW7q S+gf3yY1som6+gWDxhGYLoq1UtbBLMizdVTg9LMsTrdsaqMCVloqwfCiSCM7muAk8kFj ObVv0ieTdzuOKMdz85aIHFfRskbcjgWCbJp5NpsCsEREUNfb5jQHm1xWcsdsKcKSP8yw +VVEJDtSMEHU1Kshq4myGsu3rbr0lYaQcr7EEAqfApgqIth5FnYHua8jzYq6BGXXCBOI qusA8qqtPNFReABuJ213zx6ZKFtnbjEQ6XqCdDq0rb3Xxqd4kaq77ZuRh1bUuCTSwXzs 03+A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@harmstone.com header.s=mail header.b=OXt85iCe; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fc4-20020ad44f24000000b0066d033f15a8si4810815qvb.173.2023.10.22.17.56.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Oct 2023 17:56:28 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@harmstone.com header.s=mail header.b=OXt85iCe; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F11D03857C41 for ; Mon, 23 Oct 2023 00:56:27 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.burntcomma.com (mail2.burntcomma.com [217.169.27.34]) by sourceware.org (Postfix) with ESMTPS id 3A3303858D39 for ; Mon, 23 Oct 2023 00:55:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A3303858D39 Authentication-Results: sourceware.org; dmarc=none (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 3A3303858D39 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=1698022547; cv=none; b=nRq9gzdme47oEH3uJrF8yJQ8mT9kKk/4tG3KF524CSexeOanwZiKEgEkyRcHOG3nv4SvOMCeuxSkavrold4w0N1lHDv6HvOyaSCxXuCZZcDb+ZyESsKpfG505oVtH3ezRLYu5ew6QEuAvOxxrWW+O1EeLdfTg7kO8ky6uVwG4Qk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698022547; c=relaxed/simple; bh=/WZal7cnGWrm/A18Af4C8Uh/kH0gPXZTW3pk6laFQK4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:Mime-Version; b=k4wJ9/PNZ6TbeRqZKnE2lY8lrJylL7hqKYtKM2erJXMwjcfHzRlEyxmQ0BhzWKaL4/in7WQzYicFPgOvuco6Oj7/KZymOtB6MMdgjOZbBD8NLzS7BY6LL5DSeVbqOSdEn+DAJmr+jEpbO3Ve9E1WaOuI8jDuhHEp7+QXZa6L6x4= 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 E771116B320A9; Mon, 23 Oct 2023 01:55:43 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=harmstone.com; s=mail; t=1698022543; bh=2XD+q9zMopUzwvoF14VWD1NogcvB94gfeiTrm3bzCKo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=OXt85iCeSNbxDXz/VbevFoWFAY6Ti9udMSYP6Sknq2ky7Pkgv4Ew6/0WH2oeDnZwu kNYDeTlsD6A3O9SZH/ILgNlQbEykSsEUitPCaspeIDu3mCf1YnMFfhIN8cz5xNRYdX yA+/hX7VOSX6Kc/JwdH2nkeUA238C8hYiOeOqqw8= From: Mark Harmstone To: gcc-patches@gcc.gnu.org Cc: Mark Harmstone Subject: [PATCH 5/5] Output S_COMPILE3 symbol in CodeView debug section Date: Mon, 23 Oct 2023 01:55:31 +0100 Message-ID: <20231023005531.19921-5-mark@harmstone.com> In-Reply-To: <20231023005531.19921-1-mark@harmstone.com> References: <20231023005531.19921-1-mark@harmstone.com> Mime-Version: 1.0 X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_STOCKGEN, 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: 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780505733330502831 X-GMAIL-MSGID: 1780505733330502831 Outputs the S_COMPILE3 symbol in the CodeView .debug$S debug section. The DEBUG_S_SYMBOLS block added here makes up pretty much everything that isn't data structures or line numbers; we add the S_COMPILE3 symbol here to start it off. This is a descriptive bit, the most interesting part of which is the version of the compiler used. --- gcc/dwarf2codeview.cc | 126 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc index 4dfc0300177..a33be036951 100644 --- a/gcc/dwarf2codeview.cc +++ b/gcc/dwarf2codeview.cc @@ -37,14 +37,25 @@ along with GCC; see the file COPYING3. If not see #define CV_SIGNATURE_C13 4 +#define DEBUG_S_SYMBOLS 0xf1 #define DEBUG_S_LINES 0xf2 #define DEBUG_S_STRINGTABLE 0xf3 #define DEBUG_S_FILECHKSMS 0xf4 #define CHKSUM_TYPE_MD5 1 +#define S_COMPILE3 0x113c + +#define CV_CFL_80386 0x03 +#define CV_CFL_X64 0xD0 + +#define CV_CFL_C 0x00 +#define CV_CFL_CXX 0x01 + #define LINE_LABEL "Lcvline" #define END_FUNC_LABEL "Lcvendfunc" +#define SYMBOL_START_LABEL "Lcvsymstart" +#define SYMBOL_END_LABEL "Lcvsymend" #define HASH_SIZE 16 @@ -118,6 +129,7 @@ struct codeview_function static unsigned int line_label_num; static unsigned int func_label_num; +static unsigned int sym_label_num; static codeview_source_file *files, *last_file; static unsigned int num_files; static uint32_t string_offset = 1; @@ -590,6 +602,119 @@ codeview_end_epilogue (void) } } +/* Return the CodeView constant for the selected architecture. */ + +static uint16_t +target_processor (void) +{ + if (TARGET_64BIT) + return CV_CFL_X64; + else + return CV_CFL_80386; +} + +/* Return the CodeView constant for the language being used. */ + +static uint32_t +language_constant (void) +{ + const char *language_string = lang_hooks.name; + + if (startswith (language_string, "GNU C++")) + return CV_CFL_CXX; + else if (startswith (language_string, "GNU C")) + return CV_CFL_C; + + return 0; +} + +/* Write a S_COMPILE3 symbol, which records the details of the compiler + being used. */ + +static void +write_compile3_symbol (void) +{ + unsigned int label_num = ++sym_label_num; + + static const char compiler_name[] = "GCC "; + + /* This is struct COMPILESYM3 in binutils and Microsoft's cvinfo.h: + + struct COMPILESYM3 + { + uint16_t length; + uint16_t type; + uint32_t flags; + uint16_t machine; + uint16_t frontend_major; + uint16_t frontend_minor; + uint16_t frontend_build; + uint16_t frontend_qfe; + uint16_t backend_major; + uint16_t backend_minor; + uint16_t backend_build; + uint16_t backend_qfe; + } ATTRIBUTE_PACKED; + */ + + fputs (integer_asm_op (2, false), asm_out_file); + asm_fprintf (asm_out_file, + "%L" SYMBOL_END_LABEL "%u - %L" SYMBOL_START_LABEL "%u\n", + label_num, label_num); + + targetm.asm_out.internal_label (asm_out_file, SYMBOL_START_LABEL, label_num); + + fputs (integer_asm_op (2, false), asm_out_file); + fprint_whex (asm_out_file, S_COMPILE3); + putc ('\n', asm_out_file); + + /* Microsoft has the flags as a bitfield, with the bottom 8 bits being the + language constant, and the reset being MSVC-specific stuff. */ + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, language_constant ()); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (2, false), asm_out_file); + fprint_whex (asm_out_file, target_processor ()); + putc ('\n', asm_out_file); + + /* Write 8 uint16_ts for the frontend and backend versions. As with GAS, we + zero these, as it's easier to record the version in the compiler + string. */ + for (unsigned int i = 0; i < 8; i++) + { + fputs (integer_asm_op (2, false), asm_out_file); + fprint_whex (asm_out_file, 0); + putc ('\n', asm_out_file); + } + + ASM_OUTPUT_ASCII (asm_out_file, compiler_name, sizeof (compiler_name) - 1); + ASM_OUTPUT_ASCII (asm_out_file, version_string, strlen (version_string) + 1); + + ASM_OUTPUT_ALIGN (asm_out_file, 2); + + targetm.asm_out.internal_label (asm_out_file, SYMBOL_END_LABEL, label_num); +} + +/* Write the CodeView symbols into the .debug$S section. */ + +static void +write_codeview_symbols (void) +{ + fputs (integer_asm_op (4, false), asm_out_file); + fprint_whex (asm_out_file, DEBUG_S_SYMBOLS); + putc ('\n', asm_out_file); + + fputs (integer_asm_op (4, false), asm_out_file); + asm_fprintf (asm_out_file, "%LLcv_syms_end - %LLcv_syms_start\n"); + + asm_fprintf (asm_out_file, "%LLcv_syms_start:\n"); + + write_compile3_symbol (); + + asm_fprintf (asm_out_file, "%LLcv_syms_end:\n"); +} + /* Finish CodeView debug info emission. */ void @@ -604,4 +729,5 @@ codeview_debug_finish (void) write_strings_table (); write_source_files (); write_line_numbers (); + write_codeview_symbols (); }