From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 7D54D3864866 for ; Fri, 30 Jul 2021 20:12:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7D54D3864866 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16UKBZQd030302 for ; Fri, 30 Jul 2021 20:12:54 GMT Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 3a488da4j4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 30 Jul 2021 20:12:53 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 16UK9fpS121026 for ; Fri, 30 Jul 2021 20:12:53 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by aserp3020.oracle.com with ESMTP id 3a234eta0t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 30 Jul 2021 20:12:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N4Q2HJVtCJqYhlodFeZG5ZLahF5xhPRphsY7g3wsuomxRJkDwpGUPUdLsauMBBxCI7og6ySNPCczUwyBnjgH61YIqyqQMQaHu/kn9anuCrjs1l1B+KfiHzTUX1YAfcSuCFSC9jmTq++MiwFPoBtAVoVNUKHAb5WUkp9m2ONbnKpqx9kFTOxrEHzgyeshOMehzfkNzdw8jNbalawowkYeBaXoGgpge/3o8oE1k9tAEKXTsyz2ie4brbE8KIyVMwfevjdtd4hTniLenXCKPghueC7+HXjl3nxNGlTVG7QY6GjxW/Kgh56w4Fai0ozunJt7NZeAOOqQYOftBjdZ2oXrwg== 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=KezdGtI5Aclq2+VTxKza/3eYYtigjKSRJcWUK7haAG4=; b=ctqVPUQ/y6Z3X9N1c22oYjj/u6crHaoPklTm3YHbWjQfVLLz5vEqFWF510z+LxA41Vfkww2f/vepYiDwxj2HsdFWyKEgVlFml++Ika9FuAR5+TDrQkE9YRUQXSYX4abnGhVp3+J+VU5BNgUpOCK+dELLimTHgMFONSJ8cQMwDMMq7p45OBqd9FlrtwnFIYxdqVQ8wfsRQ8oqu2fP6utREXh6d9NNMkls3gtC+JdvU30vlpAVunaE3LYr446tlJ6nBYV1rPh6gqCqxk6c9tHmauyue9v5XYtDtey2SiR/U6KSb5JckonNogsolaBbMd4+uQnpHBRwyJNfXpU3w2pVMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by CO1PR10MB4402.namprd10.prod.outlook.com (2603:10b6:303:99::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.17; Fri, 30 Jul 2021 20:12:51 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::c9ba:5127:fa3f:45cb]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::c9ba:5127:fa3f:45cb%4]) with mapi id 15.20.4352.033; Fri, 30 Jul 2021 20:12:51 +0000 From: Indu Bhagat To: gcc-patches@gcc.gnu.org Subject: [PATCH 3/3] dwarf2out: Emit BTF in dwarf2out_finish for BPF CO-RE usecase Date: Fri, 30 Jul 2021 13:12:39 -0700 Message-Id: <1627675959-17662-4-git-send-email-indu.bhagat@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1627675959-17662-1-git-send-email-indu.bhagat@oracle.com> References: <1627675959-17662-1-git-send-email-indu.bhagat@oracle.com> Content-Type: text/plain X-ClientProxiedBy: MWHPR08CA0042.namprd08.prod.outlook.com (2603:10b6:300:c0::16) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ibhagatpc.hitronhub.home (24.80.24.133) by MWHPR08CA0042.namprd08.prod.outlook.com (2603:10b6:300:c0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20 via Frontend Transport; Fri, 30 Jul 2021 20:12:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d229e78d-808e-4f0e-e327-08d953966854 X-MS-TrafficTypeDiagnostic: CO1PR10MB4402: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AI/gvRkmzqYu0a7BAyREEB+SRc4lsESWmQXn4LEAptkVcVJOuG+br3GpYEbjUICytbEHGtfj1F3hjx7mv/lyNH2JvkMFuTup9Cr4HDEOhtmtAfG8euf/faHFo6RnK81lM9L/Zr4JKjS6GrvOcFhE1RdhsnUSDqOBJ53V6vCpaqKWAWbDkE3zdh3yexItqPMkLK17IO1aqp3oaWlBkz36S8d9yBHnQnlXvKviC8lY56oAWY2un9QNUyxYSuolKl1YeWcLdF4rT5cbO2LzIRGqu6SCyKe7/+NdadLiI3xDbyRzkl94aJaq6a6fxt60lBr8KLwxd+x6Z7GLqj+GLSoG3hsTRMMRiin2v6qAcTi3E5KyYfIFSoh5DDspFvs1KTh9RdlYBKVP1ims6Lui9b0E8fSFZqJo0IMQeCqReV9XuoMDn/ttWtPMYTBoazcLcG8ZyMNnkaNbQNRriFvWefHkJCrXw0iQZBeGIau00tJokr2l0Ber+dM3B8oa2BYlfHEL7Y/DS1orLjD8NmU3nqdgV9YCIkHmZmWsEAW5VDhsL5I9eFXRb4YCc5SXPXIsl+nJdAcpNbn0hjA4QQ3vbY3omqatTg4hH7nm6V4OY86rJD0tGoXaTvUEogqPdIHDiAa8DFxufixFg9aACQ8OYvAg+yVhHpBpVGr/Oxm+EPJTuPBl7YUQ5xZ0GKIywqdNzgn/IgrapTEjQqjLapBdlJNtgQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MWHPR1001MB2158.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(376002)(346002)(39860400002)(136003)(396003)(66946007)(6916009)(66556008)(6486002)(66476007)(6666004)(316002)(44832011)(6506007)(8676002)(186003)(38350700002)(38100700002)(83380400001)(6512007)(2616005)(36756003)(86362001)(8936002)(52116002)(478600001)(2906002)(956004)(5660300002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?2jPoUuI9dehajzY+PO9J49vPZr1HcQl3QhoY//lF+TB60W1RyD1rqdRLqVRP?= =?us-ascii?Q?lyZrxTrXX52MKMP84EvWZjTV44D+25Im7QZrUVwn5RzlLURlNHxrCwP1t8tR?= =?us-ascii?Q?NmANXc2WtnqYYOZFasW1eRTbYHI9fjResAWAATbN/x28pksN+8GsZ6xinIIy?= =?us-ascii?Q?O735pf2FjTyI9Sdvv1Tk1dUSdqOxzBqPlJ6W/VRRg+xHVp9sQcUYGueVwcm3?= =?us-ascii?Q?YCXC46kDdPjm+T/QWVB38iU4hP6winIuXhM9h5X9pihmfqTfXc39eAbXQx+B?=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RTlpQMEM6lImA+F?= =?us-ascii?Q?5pmkj5iRQ8bBOnWwFdLO8/eo75PXYvV+HLPFybB88l9XPgGD5LunYKxdBZeZ?= =?us-ascii?Q?ofniclVh4AMfNyVdRL2V6ZEvY7KUovhJdqHH1w9EFPANl7YMGSRPzicO87zT?= =?us-ascii?Q?fz2ILcD9/aPy0aITstDeJK0R?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d229e78d-808e-4f0e-e327-08d953966854 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2021 20:12:51.1948 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: a20BLEr5fxN7pSEGMfoUYVNgkJ37mzCVMYBZ7Q0kB+lEKjl4Eq8w+7io2Rl2iRehpy3Z1LM6px3tyzjahUPAyw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4402 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=10061 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 adultscore=0 suspectscore=0 malwarescore=0 spamscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2107300137 X-Proofpoint-GUID: jJB9SwpykLLOfWBLWcoEET2TnVUSss_D X-Proofpoint-ORIG-GUID: jJB9SwpykLLOfWBLWcoEET2TnVUSss_D X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, 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 20:12:57 -0000 DWARF generation is split between early and late phases when LTO is in effect. This poses challenges for CTF/BTF generation especially if late debug info generation is desirable, as turns out to be the case for BPF CO-RE. In case of BPF CO-RE, the BPF backend adds information about CO-RE relocations to the CTF container. This information is what needs to be emitted as a separate .BTF.ext section when -more is in effect. Further, each CO-RE relocation record holds an offset to a string specifying the access to the structure's field. This means that .BTF string table needs to be modified "late" in the compilation process. In other words, this implies that the BTF sections cannot be finalized in dwarf2out_early_finish when -mcore for the BPF backend is in effect. Now, the emission of CTF/BTF debug info cannot be moved unconditionally to dwarf2out_finish because dwarf2out_finish is not invoked at all for the LTO compile phase for slim LTO objects, thus breaking CTF/BTF generation for other targets when used with LTO. The approach taken here in this patch is that - 1. LTO is disabled for BPF CO-RE The reason to disable LTO for BPF CO-RE is that if LTO is in effect, BPF CO-RE relocations need to be generated in the LTO link phase _after_ the optimizations are done. This means we need to devise way to combine early and late BTF. At this time, in absence of linker support for BTF sections, it makes sense to steer clear of LTO for BPF CO-RE and bypass the issue. 2. Use a target hook to allow BPF backend to cleanly convey the case when late finalization of the CTF container is desirable. So, in other words, dwarf2out_early_finish - Always emit CTF here. - if (BTF && ctfc_debuginfo_early_finish_p), emit BTF now. dwarf2out_finish - if (BTF && !ctfc_debuginfo_early_finish_p && !in_lto_p) emit BTF now. - Use of in_lto_p to make sure LTO link phase does not affect BTF sections for other targets. gcc/ChangeLog: * dwarf2ctf.c (ctf_debug_finalize): Make it static. (ctf_debug_early_finish): New definition. (ctf_debug_finish): Likewise. * dwarf2ctf.h (ctf_debug_finalize): Remove declaration. (ctf_debug_early_finish): New declaration. (ctf_debug_finish): Likewise. * dwarf2out.c (dwarf2out_finish): Invoke ctf_debug_finish. (dwarf2out_early_finish): Invoke ctf_debug_early_finish. --- gcc/dwarf2ctf.c | 55 +++++++++++++++++++++++++++++++++++++++++++------------ gcc/dwarf2ctf.h | 4 +++- gcc/dwarf2out.c | 9 +++++++-- 3 files changed, 53 insertions(+), 15 deletions(-) diff --git a/gcc/dwarf2ctf.c b/gcc/dwarf2ctf.c index 5e8a725..0fa429c 100644 --- a/gcc/dwarf2ctf.c +++ b/gcc/dwarf2ctf.c @@ -917,6 +917,27 @@ gen_ctf_type (ctf_container_ref ctfc, dw_die_ref die) return type_id; } +/* Prepare for output and write out the CTF debug information. */ + +static void +ctf_debug_finalize (const char *filename, bool btf) +{ + if (btf) + { + btf_output (filename); + btf_finalize (); + } + + else + { + /* Emit the collected CTF information. */ + ctf_output (filename); + + /* Reset the CTF state. */ + ctf_finalize (); + } +} + bool ctf_do_die (dw_die_ref die) { @@ -966,25 +987,35 @@ ctf_debug_init_postprocess (bool btf) btf_init_postprocess (); } -/* Prepare for output and write out the CTF debug information. */ +/* Early finish CTF/BTF debug info. */ void -ctf_debug_finalize (const char *filename, bool btf) +ctf_debug_early_finish (const char * filename) { - if (btf) + /* Emit CTF debug info early always. */ + if (ctf_debug_info_level > CTFINFO_LEVEL_NONE + /* Emit BTF debug info early if the target does not require late + emission. */ + || (btf_debuginfo_p () + && targetm.ctfc_debuginfo_early_finish_p ())) { - btf_output (filename); - btf_finalize (); + /* Emit CTF/BTF debug info. */ + ctf_debug_finalize (filename, btf_debuginfo_p ()); } +} - else - { - /* Emit the collected CTF information. */ - ctf_output (filename); +/* Finish CTF/BTF debug info emission. */ - /* Reset the CTF state. */ - ctf_finalize (); - } +void +ctf_debug_finish (const char * filename) +{ + /* Emit BTF debug info here when the target needs to update the CTF container + (ctfc) in the backend. An example of this, at this time is the BPF CO-RE + usecase. */ + if (btf_debuginfo_p () + && (!in_lto_p && !targetm.ctfc_debuginfo_early_finish_p ())) + /* Emit BTF debug info. */ + ctf_debug_finalize (filename, btf_debuginfo_p ()); } #include "gt-dwarf2ctf.h" diff --git a/gcc/dwarf2ctf.h b/gcc/dwarf2ctf.h index a3cf567..9edbde0 100644 --- a/gcc/dwarf2ctf.h +++ b/gcc/dwarf2ctf.h @@ -24,13 +24,15 @@ along with GCC; see the file COPYING3. If not see #define GCC_DWARF2CTF_H 1 #include "dwarf2out.h" +#include "flags.h" /* Debug Format Interface. Used in dwarf2out.c. */ extern void ctf_debug_init (void); extern void ctf_debug_init_postprocess (bool); extern bool ctf_do_die (dw_die_ref); -extern void ctf_debug_finalize (const char *, bool); +extern void ctf_debug_early_finish (const char *); +extern void ctf_debug_finish (const char *); /* Wrappers for CTF/BTF to fetch information from GCC DWARF DIE. Used in ctfc.c. diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 884f1e1..4d7b707 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -31976,6 +31976,11 @@ dwarf2out_finish (const char *filename) print_die (comp_unit_die (), dump_file); } + /* Generate CTF/BTF debug info. */ + if ((ctf_debug_info_level > CTFINFO_LEVEL_NONE + || btf_debuginfo_p ()) && lang_GNU_C ()) + ctf_debug_finish (filename); + /* Initialize sections and labels used for actual assembler output. */ unsigned generation = init_sections_and_labels (false); @@ -32788,8 +32793,8 @@ dwarf2out_early_finish (const char *filename) ctf_debug_do_cu (node->die); /* Post process the debug data in the CTF container if necessary. */ ctf_debug_init_postprocess (btf_debuginfo_p ()); - /* Emit CTF/BTF debug info. */ - ctf_debug_finalize (filename, btf_debuginfo_p ()); + + ctf_debug_early_finish (filename); } /* Do not generate DWARF assembler now when not producing LTO bytecode. */ -- 1.8.3.1