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 (); }