From patchwork Wed Jun 23 10:06:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1496041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=xDibRmhd; dkim-atps=neutral Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G8zTY4d5Bz9sRK for ; Wed, 23 Jun 2021 20:07:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AC6F73984008 for ; Wed, 23 Jun 2021 10:07:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 9CA623983C37 for ; Wed, 23 Jun 2021 10:06:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9CA623983C37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wr1-x42f.google.com with SMTP id j2so1928950wrs.12 for ; Wed, 23 Jun 2021 03:06:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=byK3JMwFE7DimYRS+R9z4kesfTOWrdPSPHXbqIk/2SI=; b=xDibRmhdZuqEQvLdFVmXRyd1oEseQu6m2tbPJJ9Ay/xONum5bLMp/f6vp4IpleK1Py qdnKhac44qPLJpOyRZFjqRHCly+gvcO+jJ1xZ2caItzTCEeUCjDxu+NgA5gi2PszEzEP j6rJaOUCWjk5vc+3mDsTKe4bDxwXETVRp21awWYJKNPsUWlANmvp3G3Cjlx5lN/5jn3e ITy5CQDbX5Soh9OUDSvx8Dsul+sILfniCnfSTVbQ/ymb9WQnU1wOC7ehOtRjNWnfTggv 0oW1rmEOCUWL/DQnKaCeGPBrU7UGPCNWtFNNJsYoX2WNtL+94zD7686bwHfPItH94VXH jlKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=byK3JMwFE7DimYRS+R9z4kesfTOWrdPSPHXbqIk/2SI=; b=NNOb8F8E4gM0KjxvJlvkN5s16qdcnyadyHXVt7WHutbMVviLmuDduFuRbYVLuO9pvc +dfrTYBlpzQtuYJY0Ir+UGYcL25kr5YfDlpbewBqQyvvWlf1vvshFYcDRJOss813wtcp HHpBepizDZdsxVEB1ozxXGgu2WwKnK9nGexsD+UWpf9RhbDTHLL0hWzdzK61M9Gsex42 6vJYlPokbNTIrgruP9lOxw5DRemgDGneD4Jfe+ZXbbdW7y2xkLUPzTyOlf51NVo2/RFe Vo/NfwqiJQ1xf/GU3VVTqTDjCsWMYCJoj9tRGWido6WlNtr75FVu4vGHYaRzs7NRmz/J pgzg== X-Gm-Message-State: AOAM530r1wFkdzNHHKSWBRcay1vJRWwm/UFldi2tKhCpoH2xU4jYLQpx azorQZXV1/xoknLjwLPKXnyI0wr++prSiEoE X-Google-Smtp-Source: ABdhPJzL4oiEk34P0ulZwWQU63okLI/zYCioTwLffeO2C9sNRFEfzoG8S4MGe4s/nnL1SWfpUuT0AQ== X-Received: by 2002:adf:f808:: with SMTP id s8mr10258100wrp.270.1624442798567; Wed, 23 Jun 2021 03:06:38 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:41b:84f0:cf71:f5e0:b050:bede]) by smtp.gmail.com with ESMTPSA id l5sm1646733wmq.9.2021.06.23.03.06.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 03:06:38 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Emit .file 0 marker earlier in DWARF 5 Date: Wed, 23 Jun 2021 12:06:27 +0200 Message-ID: <3430317.R56niFO833@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 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 Sender: "Gcc-patches" Hi, when the assembler supports it, the compiler automatically passes --gdwarf-5 to it, which has an interesting side effect: any assembly instruction prior to the first .file directive defines a new line associated with .file 0 in the .debug_line section and, of course, the numbering of these implicit lines has nothing to do with that of the source code. This can be problematic in Ada where we do not generate .file/.loc directives for some compiled-generated functions to avoid too jumpy a debugging experience. The attached patch moves the .file 0 marker from the .debug_line section to the beginning of the file (next to the .cfi_sections marker). Tested on x86-64/Linux and x86[-64]/Windows, OK for mainline and 11 branch? 2021-06-23 Eric Botcazou * dwarf2out.c (dwarf2out_assembly_start): Emit .file 0 marker here... (dwarf2out_finish): ...instead of here. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 88eb3f9c455..9a91981acb0 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -29363,6 +29363,30 @@ dwarf2out_assembly_start (void) && dwarf2out_do_cfi_asm () && !dwarf2out_do_eh_frame ()) fprintf (asm_out_file, "\t.cfi_sections\t.debug_frame\n"); + +#if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG) + if (output_asm_line_debug_info () && dwarf_version >= 5) + { + /* When gas outputs DWARF5 .debug_line[_str] then we have to + tell it the comp_dir and main file name for the zero entry + line table. */ + const char *comp_dir, *filename0; + + comp_dir = comp_dir_string (); + if (comp_dir == NULL) + comp_dir = ""; + + filename0 = get_AT_string (comp_unit_die (), DW_AT_name); + if (filename0 == NULL) + filename0 = ""; + + fprintf (asm_out_file, "\t.file 0 "); + output_quoted_string (asm_out_file, remap_debug_filename (comp_dir)); + fputc (' ', asm_out_file); + output_quoted_string (asm_out_file, remap_debug_filename (filename0)); + fputc ('\n', asm_out_file); + } +#endif } /* A helper function for dwarf2out_finish called through @@ -32315,27 +32339,6 @@ dwarf2out_finish (const char *filename) ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); if (! output_asm_line_debug_info ()) output_line_info (false); - else if (asm_outputs_debug_line_str ()) - { - /* When gas outputs DWARF5 .debug_line[_str] then we have to - tell it the comp_dir and main file name for the zero entry - line table. */ - const char *comp_dir, *filename0; - - comp_dir = comp_dir_string (); - if (comp_dir == NULL) - comp_dir = ""; - - filename0 = get_AT_string (comp_unit_die (), DW_AT_name); - if (filename0 == NULL) - filename0 = ""; - - fprintf (asm_out_file, "\t.file 0 "); - output_quoted_string (asm_out_file, remap_debug_filename (comp_dir)); - fputc (' ', asm_out_file); - output_quoted_string (asm_out_file, remap_debug_filename (filename0)); - fputc ('\n', asm_out_file); - } if (dwarf_split_debug_info && info_section_emitted) {