From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 4840C384AB6D for ; Thu, 11 Apr 2024 11:11:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4840C384AB6D Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4840C384AB6D Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1712833909; cv=pass; b=C5R8Rje8ZUR5inEerP6M/jxwRQ/1R87WeJ3nmCmzyp9W6I8Db9XCLIDUZdAuaVFDxJvIn9+QOS4rrfYQ4lmbLUM7idcuY2cGP+J/C+PICqeISWXbdSdcDGmqcCBQVQNhLum7YD+bUbJvt1MFIiduMJeRirqkvZ+GgETGFfySqWk= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1712833909; c=relaxed/simple; bh=Lzmt8NWA1C5/nXL/Jz1E4Uf7DU4l+mLSQMvviw5qvg0=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=USAPRx9c5jdwXD6k4HNV9po0aaWJBw0QqRch/X59riJeIUGo3dS9qNTuiwtXB/WF1DUOXecNDFmrz1o6OEU3rFzS+TbZWLj+OZy0VcwwT696Vad+RsoVhkHCbW3ZS6+uXN67WT4xK+fTiU9KNoLdodZ4cLfLS81FWDTYIOYGBsU= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43BAU1v7012514 for ; Thu, 11 Apr 2024 11:11:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=D9BnzLYQbPi4VrfcDNh9ASnOmKf9o0iBNce7Yxj71rc=; b=YZjKuqBR9Tt9W7cpv0dIVJx1yGvjRDLDgctV902M15wa+DPQvnkGX7XeXho2l/zKqfag OO6W4LBz79m+KBSL1q8GqlubI4ZFE9V2WzRaD0ZMy/BzfCCwlm0MOlw+xijTko5dkqSd 2R7BxeHmiUnGG+7i4/HHorVwK/j7bb6NlpecFNMFFM06rR1XyNNJuMxSuNhtYZGS722p bnLhdXn048rwvcg74eYBrkDMriO7pnMfzlNLmS/UqXYc1qUf+M+3vcD3/TAr64gtCrpm uBALgBkgc4ITrHFVcLdoDG6nsKk86JFuoxNXuk2Ow3+oOOhKPUIR+3VzJzPmva5HRgmB ew== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xax9b978y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2024 11:11:44 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43BA6MAS032368 for ; Thu, 11 Apr 2024 11:11:43 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xavu9yr7d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2024 11:11:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IV2Cg/eafIBG8kM3R+TvFQcbelpCqbsW1JGaYngZxUjawfo2D3trd3+i+zUnXqtCRVAqeNDIACNBWxxikMNQGqgPM3NMlU4puzX44dR5VCT/O8lThIy1JNBDSaac0F8LYSAqxeuzKCh8lNgzENOW0jyqUTsmmYSGrzevjMEgdq97BPOcGtT8iRvy8oICOI8Xduj9SoyHbx8mBT+27uE1E0hYiCCDGjDiBtADxEjzrXsuhqFReinaB5aMWOQ2Bed2J7qkVPkx/WsKY39g0Q1CEDH4M4b38ncuxx7g7/Kutr6eilgEl3Fi3m5NGd6XCTyO4B5/OjWJwxcWn7zU4gzBog== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=D9BnzLYQbPi4VrfcDNh9ASnOmKf9o0iBNce7Yxj71rc=; b=QOlUZiHHX6+u86wkNZ2vYfYk6AWrTHGsdBnnFndbVfzXSMSGu7r2To2lIx0LvW2tLYpmexWj0ZYzBMGVQNe2+IYXSWzzlMB3DB/Vs/I7xOlFqs84cQe3gB3busRiS898P3IvAC4wVYwDc6QpFP3+wC5BevJEWIw6v8N61EenBvBXtmOZpVOolSM/X4hAypTKanMzLz/zVEvSw9nU4/W7vuyBtLZlOqZkMCKd/oDI9RXAS7T9fuig+6mD28hikw+HOtnaOuDMeNyCTu+Rkq53uemyTVxlxFE14aS0gZPNDaep7FEbx26WwrCOhp/xZYHmQZCrspb9N15OPSQ6QG1XKg== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=D9BnzLYQbPi4VrfcDNh9ASnOmKf9o0iBNce7Yxj71rc=; b=z+OymgzcT5y7PsuPwAal6umCUC+aTP9bWMrhzlkFbvHlQXnGuC/To3TcZyxFWT6MFBuk2jZ0crwWlOzvakD664K7izGBQG0g6GYV8hJrhu7zchQch/rN6SdcBwtgLWVPShpS8h1fp2ErFB7Er9B+NsUj9Tu67/suKZ3NP+IpoFg= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by CH3PR10MB7305.namprd10.prod.outlook.com (2603:10b6:610:12e::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.55; Thu, 11 Apr 2024 11:11:39 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7409.053; Thu, 11 Apr 2024 11:11:39 +0000 From: Cupertino Miranda To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, david.faust@oracle.com, elena.zannoni@oracle.com, Cupertino Miranda Subject: [PATCH 3/3] bpf: add line_info support to BTF.ext section. Date: Thu, 11 Apr 2024 12:11:18 +0100 Message-Id: <20240411111118.215612-3-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240411111118.215612-1-cupertino.miranda@oracle.com> References: <20240411111118.215612-1-cupertino.miranda@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: AM9P250CA0022.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:21c::27) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|CH3PR10MB7305:EE_ X-MS-Office365-Filtering-Correlation-Id: f95960bf-d08d-4b5f-b138-08dc5a1828d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xa7Z4i4tIFNb0NYqTY+Ad87e2fCNkWfCPKIVkwh1FwbIUF4QRnuEFNSJpLig3s6gG48jJWU5kzY8WBiuuvc7lAiXe5+C0Fa3k5l9AE3R7GZpcik7Rxn5AcgN59Awj29DgCc9JKxe34cqbJ5ihmI/Oq6nMfUwrX0rlUVf9z1Nd2rOW9aokKI2tYmWk76kJdT0VHDPTP7n9yQrNb3iSlBmwMtVP+DJURN+Lhu2+oWeUeO5N5QkzYt/WXjXHLZOoo1OK6bIs5DIjXZ3zBjS0dqptzq53OpWzqukp4g4iqxohPWWTTOyN/YSWF8yieIIYIwKbfenmjKYuCehVSPJ1ilGIEjfIDh+zA+Y5hCgM9hUU0DKjBVm8GdmG3d1x4I853E6U/MTzuJr+sX2klI42t/lUvgzljuMGn8hVVKzIpR7bRLGWTkbnktKhP2nkGYfHylyqf3V2LyKlXI19Q0Gtyc8GX7vDQwkwn8PuKZWG2M8PFBGF1vVJyI/MJ+XWAoKVNIcUQ84BIcZr4y3moI3YIqxBp1uEvUQcvnV48XtH8pjRfaRvWjXe39ib92oyBxaZ+Ga3h/zIQGcyKNqy/x7lFhAkWge8njTyovVendI7/e7zUd15d+iJBfwg6bADurwOd65bfir75GHsSjUncZaFshU9o8EyEjTVn8QJE/tHW8CPKM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?J4mDVP3EB34CIub03gwsp2Ia3wDMB9NLnkEq7vPT2/jt21JMZt9jNnKTxA6e?= =?us-ascii?Q?hSsWGA5ximtgfyJWM59H/V1x27pRzCDMTK76t4J6ZWYhN7rnmrDahylFPiNW?= =?us-ascii?Q?Ktv5ywB/qM87W4n8vHMxIhzaI9jamNB53rU6JeMU5OfDWBFw1akwncSCEdFc?= =?us-ascii?Q?3gZcaywntn9aqf1ivFUsUe2/Ce+Rp97GeGHqaiZJ6V6XcksEBSrLHCBQokwf?= =?us-ascii?Q?T3Ij2vMwnTkB5c+Wh6iCsFkV0vpXy5F4cIJlYR9CLJSbeQ9cxVSYkyMzXh1D?= =?us-ascii?Q?IKoj91mfY83+VbFlin8Rw5zHFr6/1zQQ5k/vnJ+G4Gk2FocouNc62PbDYMWY?= =?us-ascii?Q?qlB1NtMV9HQS3T7bbqjiCAosa5UIBIikPjD8oZmE/5wM1Gqll0wwp8Djcqep?= =?us-ascii?Q?WcFPMEKG3R6EWPkuiWW9lXoD7Rc/5SmoSLt8Ia/GgoG65iFe/2NiLGaFiX6O?= =?us-ascii?Q?rQPQBgkoIW+uqT414c8scOT8LXrJeKHrTNrIZpSzXHl0ksM6hv1O75srlHCh?= =?us-ascii?Q?LrlfPkOXABpV6G64n1XKbBQttzqWILiAh6uwHdUPyPoDp74En2NeLukWVPve?= =?us-ascii?Q?aiddoT/VXY1Yp9GF1kKWvBAV+Arc1xbnIwxqM3OYi9jAl52HovX6svZy19CB?= =?us-ascii?Q?jmyNzrXuHxtrqFQ1ewNywPOdHi6RwsYpvu+j/TZzyjgDeKkRTVVnuuWvZNRC?= =?us-ascii?Q?nq3xGFRbAvhk1iRi4qH1kUc1QBEg8FCHRkxUNfsRv14q4r013ClT6AvPl8RS?= =?us-ascii?Q?dwfblFA+ObsIcaxFyRSphKaYcG2uzIGJVG1juK1sjjua2xvBACijOiIMVhHt?= =?us-ascii?Q?S9B3DyHdu2YL3zkMjouwWhciwBpfjJBMXNelLnls1r+8nxQwGu2RhxMXIX91?= =?us-ascii?Q?n8NOXUiGKkr0IagrNsop98Y/1qk0v5V6um0bB+KaZCOXOR3XSJPBDKMzsoEx?= =?us-ascii?Q?7AOEcT2kSwRbeSYqBppXGYpSpHDJLMO9HIb13J7pBjMhZJ9q4XWtjCbxVye6?= =?us-ascii?Q?JsZM3HXE0d5dHDTpnOAk2UDBIcZLKPPZZP+0py/6KgOLgvJcPYm2VpQWnlcg?= =?us-ascii?Q?c3H65OUtql6ht0sgjCuJV8C8Omr4+Jzj48F89XZQ7WQAu6wPzHy2lUnX1Ug6?= =?us-ascii?Q?sxvXAmod5YKjXCcKlnlpeOS3hc9KpQVjp0Ii3/DWzrovgiiLUv03ig3TSsHP?= =?us-ascii?Q?x/OTgH4uU1KFdy4G7l/HcKtwjboW5qowHJPnksA6ajltMCJ0XEV8orY3sZpb?= =?us-ascii?Q?leqHgdItNFrhYtYSWZpgacFhPHjhzzv4zezgoUNpwnYQwwPJlEsm2Z8ekQ9d?= =?us-ascii?Q?DeiEHCZZS3oEPe22CVqgPmIm5swF7yY1nj8+Fs3AevgFUpzdwFysEqQl71GW?= =?us-ascii?Q?7XgBraa7Nn4Hxoep8OZL3+WkSl9Rv5dT6qb/00c1Qcv+yjIUBos5+TyAk/68?= =?us-ascii?Q?Y/T2/LhhW75A4wOv5Tzc5SAVdXTtOYEprmS6IgDSspnb+/aQRYsxwMUl6IZl?= =?us-ascii?Q?+VRIvLEFsh24vxHY7zobxQ3sew0k4ioH/MB1LwMmxtvMY9xqhrxNizxrI7Cg?= =?us-ascii?Q?nP/YCttxrk2vHW9MfdGuUqJdVIZlTYZ6xMvF/McBzR4flyj/LGmw2NV0t7Rw?= =?us-ascii?Q?0wG5lR4sOq4ovjmfcncQfm8=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: gnfTj+msekw46IfVC3MFkZFtuEG2uj+0hltuDguC3waj6ck063e8SG13tY9p0mj/dHq/HimJCU768ufwJn9ndCUFfoD6lG8wxzl9WeiyMh0Muub9fJrq7Rr4GfqGflxP9ndVTwPvAQuExOUg/Ic4ovRlK4lmqk+UxFnYntqdcJCJnKtp0aROKlBZwLHy390gURs7BF9E+S53yCNTOnV8wkqbNSpWBqNo+CwlzI1CdQ2PRCtYKImjxQnFId1Fn+MM8EIkWIoRyW6uydigfcCWD3k4cwDLV/MFPFyAn3FNKXqZvTDYfwcrA5lrNHjkBNGnFyptOBnFeejcRloEQjd8T8BYcocr6yGeeQ9MH1fwQ995my2Xm8DLHFQgeb9acCtQvywFIRp/AsZQR5+mW14Va8L/0kkOvHlQP6EPjpkqP0Q/7CkPOb3xB6IO6NwXxt4wgpm/0V5uu+0RQwoNvCSj0SdSO3S9EaeYWtFYBlvBrq33zX3LzsieAUmnH/hER6oCwepxIbcESADKm8zpeSWZmadp8t2K4KMQFFn6EtGcuZqM52R6y8c9p8Ysy1xmgOhdT/7LRpSRVPK37Xhl8jCUh/ue2Xr1pgWC7qImEClI2g4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f95960bf-d08d-4b5f-b138-08dc5a1828d8 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2024 11:11:39.2834 (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: qEM53h08psNUYh5GVZaUOjxPo02uUyVRYwiZd1u/GbHVIJEu3K2kzHCfB0cAW9vaJJuLNlfGxvMuR2Pi3z8DzGp5/dEXjR+1NsfToFyknzc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR10MB7305 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-11_04,2024-04-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 suspectscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404110080 X-Proofpoint-GUID: cgxgkpJ2KZyJaHP0zoGNNILU7w8v0vWu X-Proofpoint-ORIG-GUID: cgxgkpJ2KZyJaHP0zoGNNILU7w8v0vWu X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: This patch adds line_info debug information support to .BTF.ext sections. Line info information is used by the BPF verifier to improve error reporting and give more precise source core referenced errors. gcc/Changelog: * config/bpf/bpf-protos.h (bpf_output_call): Change prototype. * config/bpf/bpf.cc (bpf_output_call): Change to adapt operands and return the instruction template instead of emmidiatelly emit asm and not allow proper final expected execution flow. (bpf_output_line_info): Add function to introduce line info entries in respective structures (bpf_asm_out_unwind_emit): Add function as hook to TARGET_ASM_UNWIND_EMIT. This hook is called before any instruction is emitted. * config/bpf/bpf.md: Change calls to bpf_output_call. * config/bpf/btfext-out.cc (struct btf_ext_lineinfo): Add fields to struct. (bpf_create_lineinfo, btf_add_line_info_for): Add support function to insert line_info data in respective structures. (output_btfext_line_info): Function to emit line_info data in .BTF.ext section. (btf_ext_output): Call output_btfext_line_info. * config/bpf/btfext-out.h: Add prototype for btf_add_line_info_for. --- gcc/config/bpf/bpf-protos.h | 2 +- gcc/config/bpf/bpf.cc | 103 ++++++++++++++--- gcc/config/bpf/bpf.md | 4 +- gcc/config/bpf/btfext-out.cc | 108 +++++++++++++++++- gcc/config/bpf/btfext-out.h | 4 + .../gcc.target/bpf/btfext-funcinfo.c | 3 +- 6 files changed, 203 insertions(+), 21 deletions(-) diff --git a/gcc/config/bpf/bpf-protos.h b/gcc/config/bpf/bpf-protos.h index b4866d34209..ddaca50af69 100644 --- a/gcc/config/bpf/bpf-protos.h +++ b/gcc/config/bpf/bpf-protos.h @@ -23,7 +23,7 @@ along with GCC; see the file COPYING3. If not see /* Routines implemented in bpf.cc. */ extern HOST_WIDE_INT bpf_initial_elimination_offset (int, int); -extern const char *bpf_output_call (rtx); +extern const char *bpf_output_call (const char *templ, rtx *, int target_index); extern void bpf_target_macros (cpp_reader *); extern void bpf_print_operand (FILE *, rtx, int); extern void bpf_print_operand_address (FILE *, rtx); diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index d9141dd625a..f1a8eb8d62c 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -754,14 +754,12 @@ bpf_output_destructor (rtx symbol, int priority ATTRIBUTE_UNUSED) bpf.md. */ const char * -bpf_output_call (rtx target) +bpf_output_call (const char *templ, rtx *operands, int target_index) { - rtx xops[1]; - + rtx target = operands[target_index]; switch (GET_CODE (target)) { case CONST_INT: - output_asm_insn ("call\t%0", &target); break; case SYMBOL_REF: { @@ -774,26 +772,20 @@ bpf_output_call (rtx target) { tree attr_args = TREE_VALUE (attr); - xops[0] = GEN_INT (TREE_INT_CST_LOW (TREE_VALUE (attr_args))); - output_asm_insn ("call\t%0", xops); - } - else - output_asm_insn ("call\t%0", &target); + operands[target_index] = GEN_INT (TREE_INT_CST_LOW (TREE_VALUE (attr_args))); + } break; } default: - if (TARGET_XBPF) - output_asm_insn ("call\t%0", &target); - else + if (!TARGET_XBPF) { error ("indirect call in function, which are not supported by eBPF"); - output_asm_insn ("call 0", NULL); + operands[target_index] = GEN_INT (0); } break; } - - return ""; + return templ; } const char * @@ -1144,6 +1136,87 @@ bpf_debug_unwind_info () #undef TARGET_DEBUG_UNWIND_INFO #define TARGET_DEBUG_UNWIND_INFO bpf_debug_unwind_info +/* Create a BTF.ext line_info entry. */ + +static void +bpf_output_line_info (FILE *asm_out_file, rtx_insn *insn) +{ + static unsigned int line_info_label = 1; + static tree cfun_decl = NULL_TREE; + static bool func_start_added = false; + const char *label = NULL; + unsigned int loc = 0; + const char *filename = NULL; + unsigned int line = 0; + unsigned int column = 0; + + if(!btf_debuginfo_p ()) + return; + + gcc_assert (insn != NULL_RTX); + + if (current_function_decl != cfun_decl + && GET_CODE (insn) == NOTE) + { + label = current_function_func_begin_label; + loc = DECL_SOURCE_LOCATION (current_function_decl); + filename = LOCATION_FILE (loc); + line = LOCATION_LINE (loc); + column = LOCATION_COLUMN (loc); + func_start_added = true; + } + else + { + if (GET_CODE (insn) == NOTE) + return; + + /* Already added a label for this location. This might not be fully + acurate but it is better then adding 2 entries on the same location, + which is imcompatible with the verifier expectations. */ + if (func_start_added == true) + { + func_start_added = false; + return; + } + + loc = INSN_LOCATION (insn); + filename = LOCATION_FILE (loc); + line = LOCATION_LINE (loc); + column = LOCATION_COLUMN (loc); + + if (filename == NULL || line == 0) + return; + + char tmp_label[25]; + sprintf(tmp_label, "LI%u", line_info_label); + ASM_OUTPUT_LABEL (asm_out_file, tmp_label); + line_info_label += 1; + label = CONST_CAST (char *, ggc_strdup (tmp_label)); + } + + cfun_decl = current_function_decl; + + if (filename != NULL && line != 0) + btf_add_line_info_for (label, filename, line, column); +} + + +/* This hook is defined as a way for BPF target to create a label before each + * emitted instruction and emit line_info information. This data is later output + * in .BTF.ext section. + * This approach expects TARGET_EMIT_BEFORE_INSN to be returing TRUE as + * this function needs to be called before the instruction is emitted. Current + * default behaviour returns TRUE and the hook is left undefined. */ + +static void +bpf_asm_out_unwind_emit (FILE *asm_out_file, rtx_insn *insn) +{ + bpf_output_line_info (asm_out_file, insn); +} + +#undef TARGET_ASM_UNWIND_EMIT +#define TARGET_ASM_UNWIND_EMIT bpf_asm_out_unwind_emit + /* Output assembly directives to assemble data of various sized and alignments. */ diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md index 95859328d25..3fdf81b86a6 100644 --- a/gcc/config/bpf/bpf.md +++ b/gcc/config/bpf/bpf.md @@ -546,7 +546,7 @@ ;; operands[2] is next_arg_register ;; operands[3] is struct_value_size_rtx. "" - { return bpf_output_call (operands[0]); } + { return bpf_output_call ("call\t%0", operands, 0); } [(set_attr "type" "jmp")]) (define_expand "call_value" @@ -569,7 +569,7 @@ ;; operands[3] is next_arg_register ;; operands[4] is struct_value_size_rtx. "" - { return bpf_output_call (operands[1]); } + { return bpf_output_call ("call\t%1", operands, 1); } [(set_attr "type" "jmp")]) (define_insn "sibcall" diff --git a/gcc/config/bpf/btfext-out.cc b/gcc/config/bpf/btfext-out.cc index ff1fd0739f1..42ec48e394e 100644 --- a/gcc/config/bpf/btfext-out.cc +++ b/gcc/config/bpf/btfext-out.cc @@ -32,6 +32,7 @@ #include "rtl.h" #include "tree-pretty-print.h" #include "cgraph.h" +#include "toplev.h" /* get_src_pwd */ #include "btfext-out.h" @@ -124,7 +125,8 @@ struct GTY ((chain_next ("%h.next"))) btf_ext_funcinfo /* A lineinfo record, in the .BTF.ext lineinfo section. */ struct GTY ((chain_next ("%h.next"))) btf_ext_lineinfo { - uint32_t insn_off; /* Offset of the instruction. */ + const char *insn_label; /* Instruction label. */ + const char *file_name; /* Source-code file name. */ uint32_t file_name_off; /* Offset of file name in BTF string table. */ uint32_t line_off; /* Offset of source line in BTF string table. */ uint32_t line_col; /* Line number (bits 31-11) and column (11-0). */ @@ -235,6 +237,26 @@ bpf_create_or_find_funcinfo (const char *fnname, const char *sec_name, return *head; } +/* Function to create a lineinfo node in info. */ + +static struct btf_ext_lineinfo * +bpf_create_lineinfo (const char *sec_name, btf_ext_info_sec **in_sec = NULL) +{ + struct btf_ext_info_sec *sec_elem = + btfext_info_sec_find_or_add (sec_name, true); + + if (in_sec != NULL) + *in_sec = sec_elem; + + struct btf_ext_lineinfo **head = + SEARCH_NODE_AND_RETURN(struct btf_ext_lineinfo, + sec_elem->line_info.head, + false); + *head = ggc_cleared_alloc (); + + return *head; +} + /* Function to create a core_reloc node in info. */ static struct btf_ext_core_reloc * @@ -429,6 +451,47 @@ btf_validate_funcinfo (btf_ext_info_sec *sec) } } +struct btf_ext_lineinfo * +btf_add_line_info_for (const char *label, const char *filename, + unsigned int line, unsigned int column) +{ + const char *sec_name = decl_section_name (current_function_decl); + + if (sec_name == NULL) + sec_name = ".text"; + + struct btf_ext_info_sec *sec = NULL; + struct btf_ext_lineinfo *info = + bpf_create_lineinfo (sec_name, &sec); + + unsigned int line_column = ((0x000fffff & line) << 12) + | (0x00000fff & column); + + info->insn_label = label; + + if (!IS_DIR_SEPARATOR (filename[0])) + { + char full_filename[256]; + + /* Filename is a relative path. */ + const char * cu_pwd = get_src_pwd (); + gcc_assert (strlen (cu_pwd) + strlen (filename) + 2 < 256); + + sprintf(full_filename, "%s%c%s", cu_pwd, DIR_SEPARATOR, filename); + info->file_name = ggc_strdup (full_filename); + } + else + /* Filename is an absolute path. */ + info->file_name = ggc_strdup (filename); + + info->file_name_off = btf_ext_add_string (info->file_name); + info->line_off = 0; + info->line_col = line_column; + + sec->line_info.num_info += 1; + return info; +} + /* Compute the section size in section for func_info, line_info and core_info regions of .BTF.ext. */ @@ -537,6 +600,48 @@ output_btfext_func_info (struct btf_ext_info_sec *sec) } } +/* Outputs line_info region on .BTF.ext. */ + +static void +output_btfext_line_info (struct btf_ext_info_sec *sec) +{ + unsigned int str_aux_off = ctfc_get_strtab_len (ctf_get_tu_ctfc (), + CTF_STRTAB); + bool executed = false; + while (sec != NULL) + { + uint32_t count = 0; + if (sec->line_info.num_info > 0) + { + if (executed == false && (executed = true)) + dw2_asm_output_data (4, 16, "LineInfo entry size"); + dw2_asm_output_data (4, sec->sec_name_off + str_aux_off, + "LineInfo section string for %s", + sec->sec_name); + dw2_asm_output_data (4, sec->line_info.num_info, "Number of entries"); + + struct btf_ext_lineinfo *elem = sec->line_info.head; + while (elem != NULL) + { + count += 1; + dw2_asm_output_offset (4, elem->insn_label, NULL, "insn_label"); + + unsigned int file_name_off = btf_ext_add_string (elem->file_name); + dw2_asm_output_data (4, file_name_off + str_aux_off, + "file_name_off"); + dw2_asm_output_data (4, elem->line_off, "line_off"); + dw2_asm_output_data (4, elem->line_col, "(line, col) (%u, %u)", + elem->line_col >> 12, + elem->line_col & 0x00000fff); + elem = elem->next; + } + } + + gcc_assert (count == sec->line_info.num_info); + sec = sec->next; + } +} + /* Output all CO-RE relocation sections. */ static void @@ -609,6 +714,7 @@ btf_ext_output (void) { output_btfext_header (); output_btfext_func_info (btf_ext); + output_btfext_line_info (btf_ext); if (TARGET_BPF_CORE) output_btfext_core_sections (); diff --git a/gcc/config/bpf/btfext-out.h b/gcc/config/bpf/btfext-out.h index b36309475c9..9c6848324e7 100644 --- a/gcc/config/bpf/btfext-out.h +++ b/gcc/config/bpf/btfext-out.h @@ -99,6 +99,10 @@ extern int bpf_core_get_sou_member_index (ctf_container_ref, const tree); struct btf_ext_funcinfo *btf_add_func_info_for (tree decl, const char *label); +struct btf_ext_lineinfo * +btf_add_line_info_for (const char *label, const char *filename, + unsigned int line, unsigned int column); + unsigned int btf_ext_add_string (const char *str); #ifdef __cplusplus diff --git a/gcc/testsuite/gcc.target/bpf/btfext-funcinfo.c b/gcc/testsuite/gcc.target/bpf/btfext-funcinfo.c index 6fdd14574ec..0f1e0ad1e89 100644 --- a/gcc/testsuite/gcc.target/bpf/btfext-funcinfo.c +++ b/gcc/testsuite/gcc.target/bpf/btfext-funcinfo.c @@ -39,6 +39,5 @@ int bar_func (struct T *t) /* { dg-final { scan-assembler-times "ascii \"bar_sec.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */ /* { dg-final { scan-assembler-times "FuncInfo entry size" 1 } } */ -/* { dg-final { scan-assembler-times ".4byte\t0x1\t# Number of entries" 3 } } */ -/* { dg-final { scan-assembler-times ".4byte\t0x2\t# Number of entries" 1 } } */ +/* { dg-final { scan-assembler-times "FuncInfo section\[^\n\]*\n\[^0\]*0x1\t# Number of entries" 2 } } */ /* { dg-final { scan-assembler-times "Required padding" 1 } } */ -- 2.30.2