From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073103.outbound.protection.outlook.com [40.92.73.103]) by sourceware.org (Postfix) with ESMTPS id 4C4D3393F828 for ; Fri, 30 Jul 2021 11:09:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C4D3393F828 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=hotmail.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hotmail.de ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HTi9jUuCgTjR7sSgivGubJYFc0jVWiMPMRjsfy+pC9vHf4ymCgJE5yazFALx2/5FXJXbr+0EBOwfwdEdaPSFuSQvCduxA3BKQ1WcM65xmhM4gZrdPRMUtt1P5c+o6+QVNL4y3azVMrqdzIBphmjM9iOU+IvzsXQmVzoHyFqPujBU7kOWwdGoSIAinWbNxvsQxMPRrv5OZq271BI3uA2fBull9I1/0TBoba+Upv/+R8Cd5KD0sVwhK0CZSquWHXBa3y/thStVegtF7S2Ae7FqW/1shQFgnjdB0JC69KnkhSQI4s1T1CxdVG8we5jYJM9hMH27cc7AVjT0bbNYGLbYrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Kz4ff1Ve2rLffHYcuaEQbVD4d6XxJwm3RMghflhCXKs=; b=bI16ndXykMFWnEetV3MdE4rOl/0uaVMhmDszDaghu1GgCkIB0zH5Pn7h3iZGE/FnAI4oyh5C4Uz5LyKFMsjvD/XV/n6oPR6eA9PtdGSG1qwTuaNdJY99XvQaAnuEM9QzKnMyjp4NMytJbbffBmNx5srNpVnMlP9QqknHuUB8AF+x4kGH0eanRTyDN2bS2EUUE3sCjNGbZpJK4+yzdBr1VLai4zQ8P82T5zV4ZsAXOCQMPtIy47qKqCw/XXMhsCpqc9u9CNJ6hxDAYcYQYXkCN7QBROjKn0WI9zVfeNDvqQ0ofrYa9z/MF+s1csYImA8o7gkycEgs4uyLK9ItzapVgQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none Received: from HE1EUR04FT032.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0d::4f) by HE1EUR04HT031.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0d::313) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18; Fri, 30 Jul 2021 11:09:09 +0000 Received: from AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM (2a01:111:e400:7e0d::42) by HE1EUR04FT032.mail.protection.outlook.com (2a01:111:e400:7e0d::291) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.18 via Frontend Transport; Fri, 30 Jul 2021 11:09:09 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:35EFEC7FF555A1794F88613D9DFC28F4F5CA91E44968D78118A722F1D5E52CAA; UpperCasedChecksum:764A1F1B5D76E839F61173D00B2ED4F64373E0325C03A0FE15FB656081C182B5; SizeAsReceived:8170; Count:47 Received: from AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM ([fe80::3d30:d151:570a:8a16]) by AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM ([fe80::3d30:d151:570a:8a16%9]) with mapi id 15.20.4373.025; Fri, 30 Jul 2021 11:09:09 +0000 Subject: Re: [PATCH 1/2] Fix debug info for ignored decls at start of assembly To: Richard Biener Cc: "gcc-patches@gcc.gnu.org" , Eric Botcazou , Arnaud Charlet References: From: Bernd Edlinger Message-ID: Date: Fri, 30 Jul 2021 13:09:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 In-Reply-To: Content-Type: multipart/mixed; boundary="------------A125DCBE5C8140A154AB20B1" Content-Language: en-US X-TMN: [wXgcasanNAcFPqY9qxOc6RrpVYWIw7Z+] X-ClientProxiedBy: AM0PR01CA0103.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::44) To AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:364::23) X-Microsoft-Original-Message-ID: <763a4a7d-be13-edf3-8136-19a8074d03a6@hotmail.de> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [192.168.1.101] (88.76.118.196) by AM0PR01CA0103.eurprd01.prod.exchangelabs.com (2603:10a6:208:10e::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.17 via Frontend Transport; Fri, 30 Jul 2021 11:09:07 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 47 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: ddef5039-c3d2-4b1f-0750-08d9534a73f3 X-MS-TrafficTypeDiagnostic: HE1EUR04HT031: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BiImwClVGn+hqpxSrXIvo2sie2XN5K93f32sbOhAtQkW3Jy2Gn2dPCz0OtmGn+s8qRLnuFcrgPcyY02bKVXYc6YEi8uFsZEdc19MdlF6oWSz6C1qhFSrcMF5PdPCfexnmD9WDxYjWDX/91aMva4Ya/fqEM70VPzOh96x2FLFGOf6m8yefonozlwfL59DjUIpVOlXp41anQkOt2BctRjik5mlp4opgfxarP+XxoXZb24sK9lLWEwtioGTTvqHja1nYuLhf+6cSmJYAPuUhYwZjjzwesecr7ISPSLo+8UMWK66HmSrEb2lffnk1LdOCK0Plme5LtfvKww9FjT3MBi/VehUwFZtdLyfhWKr/sP4yJ8qQ3q1YAv+sw94yStYSPH+pH3WH7MHFjGBU1l/J5eJDno25SsER8EPtTw7KbuD/ZR0F7xAB8yIR4LvBuqKi+DxeHl2RR2ktofSw+elPmhyAk6T210QcNW+RAuxdUsGOT4= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: k5ByOG2Tbvhr3CVW+NPJce1RVy99SSM/dxIgZtSfFqP7yVqwZUM4dQZ+/ualVXdj00bt9BI0kT8CSFxTCM3B5K1q99eQoGnoaTCT8ydPQdP2hGjQus+v3UY9AR3jsK6P3X2Et5xhqNSAhBNA83qFkA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ddef5039-c3d2-4b1f-0750-08d9534a73f3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2021 11:09:09.2685 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: HE1EUR04FT032.eop-eur04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR04HT031 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, FORGED_MUA_MOZILLA, FREEMAIL_FROM, GIT_PATCH_0, KAM_DMARC_STATUS, MSGID_FROM_MTA_HEADER, NICE_REPLY_A, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , X-List-Received-Date: Fri, 30 Jul 2021 11:09:13 -0000 --------------A125DCBE5C8140A154AB20B1 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 7/29/21 9:23 AM, Richard Biener wrote: > On Wed, 28 Jul 2021, Bernd Edlinger wrote: > >> On 7/28/21 2:51 PM, Richard Biener wrote: >>> On Mon, 26 Jul 2021, Bernd Edlinger wrote: >>> >>>> Ignored functions decls that are compiled at the start of >>>> the assembly have bogus line numbers until the first .file >>>> directive, as reported in PR101575. >>>> >>>> The work around for this issue is to emit a dummy .file >>>> directive when the first function is DECL_IGNORED_P, when >>>> that is not already done, mostly for -fdwarf-4. >>> >>> I wonder if it makes sense to unconditionally announce the >>> TU with a .file directive at the beginning. ISTR this is >>> what we now do with -gdwarf-5. >>> >> >> Yes, that would work, even when the file name is not guessed >> correctly. >> >> Initially I had "" unconditionally here, and it did >> not really hurt, except that it is visible with readelf. > > I think I'd prefer that, since if we don't announce a .file > before the first assembler statement but ask gas to produce > line info it might be tempted to create line info referencing > the possibly temporary filename of the assembler file which > is undesirable from a build reproducability point. > Yeah, I understand. Meanwhile I found a simple C test case without ignored functions $ cat test1.c asm("nop"); int main () { return 0; } $ gcc -g test1.c $ readelf --debug-dump=decodedline a.out Contents of the .debug_line section: CU: ./test1.c: File name Line number Starting address View Stmt test1.c 5 0x401106 x test1.c 3 0x401107 x test1.c 4 0x40110b x test1.c 5 0x401110 x test1.c - 0x401112 even with the proposed patch, so I agree it is incomplete. I tried the gdb test case and compile it with different LTO options, but the gen_AT_string was always valid, in some cases a lto debug section together with a couple .file directives was output before the .file 0. So I'd like to use the file name from gen_AT_string, since it's most of the time accurate, and avoids unnecessary confusion on the readers of the produced debug info. So I'd propose the attached patch instead. Is it OK for trunk? > Richard. > >>> Note get_AT_string (comp_unit_die (), DW_AT_name) doesn't >>> work with LTO, you'll get then. >>> >> >> Yeah, that's why I wanted to restrict that to the case where >> it's absolutely necessary. >> >>> Is the dwarf assembler bug reported/fixed? Can you include >>> a reference please? >>> >> >> I've just added a bug report, it's unlikely to be fixed IMHO: >> https://sourceware.org/bugzilla/show_bug.cgi?id=28149 >> >> I will add that to the patch description: >> >> Ignored functions decls that are compiled at the start of >> the assembly have bogus line numbers until the first .file >> directive, as reported in PR101575. >> >> The corresponding binutils bug report is >> https://sourceware.org/bugzilla/show_bug.cgi?id=28149 >> >> The work around for this issue is to emit a dummy .file >> directive when the first function is DECL_IGNORED_P, when >> that is not already done, mostly for -fdwarf-4. >> >> >> Thanks >> Bernd. >> >>> Thanks, >>> Richard. >>> >>>> 2021-07-24 Bernd Edlinger >>>> >>>> PR ada/101575 >>>> * dwarf2out.c (dwarf2out_begin_prologue): Move init >>>> of fde->ignored_debug to dwarf2out_set_ignored_loc. >>>> (dwarf2out_set_ignored_loc): This is now also called >>>> when no .loc statement is to be generated, in that case >>>> we emit a dummy .file statement when needed. >>>> * final.c (final_start_function_1, >>>> final_scan_insn_1): Call debug_hooks->set_ignored_loc >>>> for all DECL_IGNORED_P functions. >>>> --- >>>> gcc/dwarf2out.c | 29 +++++++++++++++++++++++++---- >>>> gcc/final.c | 5 ++--- >>>> 2 files changed, 27 insertions(+), 7 deletions(-) >>>> >>>> diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c >>>> index 884f1e1..8de0d6f 100644 >>>> --- a/gcc/dwarf2out.c >>>> +++ b/gcc/dwarf2out.c >>>> @@ -1115,7 +1115,6 @@ dwarf2out_begin_prologue (unsigned int line ATTRIBUTE_UNUSED, >>>> fde->dw_fde_current_label = dup_label; >>>> fde->in_std_section = (fnsec == text_section >>>> || (cold_text_section && fnsec == cold_text_section)); >>>> - fde->ignored_debug = DECL_IGNORED_P (current_function_decl); >>>> in_text_section_p = fnsec == text_section; >>>> >>>> /* We only want to output line number information for the genuine dwarf2 >>>> @@ -28546,10 +28545,32 @@ dwarf2out_set_ignored_loc (unsigned int line, unsigned int column, >>>> { >>>> dw_fde_ref fde = cfun->fde; >>>> >>>> - fde->ignored_debug = false; >>>> - set_cur_line_info_table (function_section (fde->decl)); >>>> + if (filename) >>>> + { >>>> + set_cur_line_info_table (function_section (fde->decl)); >>>> + >>>> + dwarf2out_source_line (line, column, filename, 0, true); >>>> + } >>>> + else >>>> + { >>>> + fde->ignored_debug = true; >>>> + >>>> + /* Work around for PR101575: output a dummy .file directive. */ >>>> + if (in_first_function_p >>>> + && debug_info_level >= DINFO_LEVEL_TERSE >>>> + && dwarf_debuginfo_p () >>>> +#if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG) >>>> + && dwarf_version <= 4 >>>> +#endif >>>> + && output_asm_line_debug_info ()) >>>> + { >>>> + const char *filename0 = get_AT_string (comp_unit_die (), DW_AT_name); >>>> >>>> - dwarf2out_source_line (line, column, filename, 0, true); >>>> + if (filename0 == NULL) >>>> + filename0 = ""; >>>> + maybe_emit_file (lookup_filename (filename0)); >>>> + } >>>> + } >>>> } >>>> >>>> /* Record the beginning of a new source file. */ >>>> diff --git a/gcc/final.c b/gcc/final.c >>>> index ac6892d..82a5767 100644 >>>> --- a/gcc/final.c >>>> +++ b/gcc/final.c >>>> @@ -1725,7 +1725,7 @@ final_start_function_1 (rtx_insn **firstp, FILE *file, int *seen, >>>> if (!dwarf2_debug_info_emitted_p (current_function_decl)) >>>> dwarf2out_begin_prologue (0, 0, NULL); >>>> >>>> - if (DECL_IGNORED_P (current_function_decl) && last_linenum && last_filename) >>>> + if (DECL_IGNORED_P (current_function_decl)) >>>> debug_hooks->set_ignored_loc (last_linenum, last_columnnum, last_filename); >>>> >>>> #ifdef LEAF_REG_REMAP >>>> @@ -2205,8 +2205,7 @@ final_scan_insn_1 (rtx_insn *insn, FILE *file, int optimize_p ATTRIBUTE_UNUSED, >>>> } >>>> else if (!DECL_IGNORED_P (current_function_decl)) >>>> debug_hooks->switch_text_section (); >>>> - if (DECL_IGNORED_P (current_function_decl) && last_linenum >>>> - && last_filename) >>>> + if (DECL_IGNORED_P (current_function_decl)) >>>> debug_hooks->set_ignored_loc (last_linenum, last_columnnum, >>>> last_filename); >>>> >>>> >>> >> > --------------A125DCBE5C8140A154AB20B1 Content-Type: text/x-patch; name="0001-Fix-debug-info-for-ignored-decls-at-start-of-assembl.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename*0="0001-Fix-debug-info-for-ignored-decls-at-start-of-assembl.pa"; filename*1="tch" RnJvbSBkZWM0YmU4ZjNlOWUxZTc0MzBlNWM2NWQ2YWFhMTM1MjZlYmM3N2UyIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBCZXJuZCBFZGxpbmdlciA8YmVybmQuZWRsaW5nZXJAaG90bWFp bC5kZT4KRGF0ZTogU2F0LCAyNCBKdWwgMjAyMSAxMjo1MzozOSArMDIwMApTdWJqZWN0OiBbUEFU Q0ggMS8yXSBGaXggZGVidWcgaW5mbyBmb3IgaWdub3JlZCBkZWNscyBhdCBzdGFydCBvZiBhc3Nl bWJseQoKSWdub3JlZCBmdW5jdGlvbnMgZGVjbHMgdGhhdCBhcmUgY29tcGlsZWQgYXQgdGhlIHN0 YXJ0IG9mCnRoZSBhc3NlbWJseSBoYXZlIGJvZ3VzIGxpbmUgbnVtYmVycyB1bnRpbCB0aGUgZmly c3QgLmZpbGUKZGlyZWN0aXZlLCBhcyByZXBvcnRlZCBpbiBQUjEwMTU3NS4KClRoZSBjb3JyZXNw b25kaW5nIGJpbnV0aWxzIGJ1ZyByZXBvcnQgaXMKaHR0cHM6Ly9zb3VyY2V3YXJlLm9yZy9idWd6 aWxsYS9zaG93X2J1Zy5jZ2k/aWQ9MjgxNDkKClRoZSB3b3JrIGFyb3VuZCBmb3IgdGhpcyBpc3N1 ZSBpcyB0byBlbWl0IGEgZHVtbXkgLmZpbGUKZGlyZWN0aXZlIGJlZm9yZSB0aGUgZmlyc3QgZnVu Y3Rpb24gaXMgY29tcGlsZWQsIHVubGVzcwphbm90aGVyIC5maWxlIGRpcmVjdGl2ZSB3YXMgYWxy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