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 3B3AF385E45C for ; Tue, 11 Jun 2024 19:03:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3B3AF385E45C Authentication-Results: sourceware.org; dmarc=pass (p=reject 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 3B3AF385E45C Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132590; cv=pass; b=OhiaPVI83CC+muN/lqNafgDwfSgt16xJM32tLwZkCi/mpnBaQVJG01nR7h7/mmGM8MvTHNfmVCE5MHZwP+2xg3qWN5EylwydFTK32Ge++PBhmaOZkmkDdOW2+rbjrf8zLCqp0MHu3b3kTFBorO5nSIMtmyS7nDYqEmtHu+uIwNM= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1718132590; c=relaxed/simple; bh=fzpROpME1gmSvvvRXT5pXX79p5GtZx3Prf28yAAgGbU=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=XNEijB/W/vV8dk6u691+nKdKzeZWo0mx1R/OIkF05eLG7BjdBtQrradDUu1ZBKSYCE4y9jXQtqMNxM8tMU7Kvnxcnl7OPU+0tIKHouxj0rLzKOmYkSR/vwEPCGkwRGSTI96f40oqHmb4b1QcVb9AyDS8XNq0tFBHGreab5LegOU= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45BFxBnT026893 for ; Tue, 11 Jun 2024 19:03:05 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=87N8nwXH6w0o9I+RVBuxQd1jUwdrvqXvM8+kLYF63pk=; b= osYMBOkX9wTcTUzkKEGHlP8SydgIiLh7p3YPS2sl5e3Xiq7mSUAGokGxgtLO45gc F6iJCRIYUv9PeqgII4Cez0dn5dsfTyH5AHf5HdIR7gsyldaN6udIXBsf+y0Yq2lN zA1eiKmREiKYu6CM7Y+io0mW0cGHCdsuE/E/3DVQC9ijL0xKFoiyN6Iz11xBC2mX wux4vYclCaY+U29dhnZLo6lRmWFGGTVZ0lSIdQCAqEZArnqwjVGivnTbJbLdq23F 7p3230sUurvkaRz+FnHgZFdTMApn98XTKVD95bkaeDPJTos5hymnmY8DAEe0rQS2 LPWGMEXAvWBanbv6CD8JTA== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3ymh1gdmwn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:05 +0000 (GMT) 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 45BIk50b012608 for ; Tue, 11 Jun 2024 19:03:04 GMT Received: from nam04-dm6-obe.outbound.protection.outlook.com (mail-dm6nam04lp2041.outbound.protection.outlook.com [104.47.73.41]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3ync9xaqh2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 11 Jun 2024 19:03:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GL1BGpsoxBFl+sqDpuGiOfFXg1gzi2b7Gae2z2MbvA4EoQS00fUuz8NiOfienVluSul6EpDW0cO6sx7XS9AqOgsZM33hM+IlQuhIQ0H5K2K/W3tGKTUDXjYgV03acaFrdEkyArf+g/no3g6YiKgkiiaQrW6Kafs6TMU0hmS+kck0VNmR8uNm4KKGBRj0gbPHMl+JBEofxSaPH7yB2H6+MKtOZFwVuwCl+69l4rvNeFupj9Meb1Qf+1ciUYwDLGk+TMLGTbFW4mpSBc9iuXfJgFYov0hbzEGdk6WXCvLDmSxKqyYsiokSuStBYQvDETBiXWNc43H8juJ3tFa2PKcC8w== 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=87N8nwXH6w0o9I+RVBuxQd1jUwdrvqXvM8+kLYF63pk=; b=nQ2X466TlqTS+kGoX9T3Sn6R6wXMMczjPr9F/yxoiYy0BMBeOKRxyNL+JnFZSG4XV3+cRwFjxFhfL9kUvRF5Op4n1vG4/IqqjdNeZkHN+T9RUzdFSj8Z7bCAL8qTGCSWmab0xvLsCwIv1kiPjIaFZQBsp2YW0yDE+4gWj3CENYAaKpyJri3X8Z+kBRTygKbnFd5fnVBoPLWgx5GganVkkTZVos32ZRzBgJ0pwQzlD3GE+1VfYcdQme3TDiSW5YkvE2OrlNHdJUL2YrxEhJukKLYK5VNjyeVDo3NOUMdhXCb6qZ/MNwpCypyLdGeYD4HDbPZKA536JupM1SE9kSM5MQ== 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=87N8nwXH6w0o9I+RVBuxQd1jUwdrvqXvM8+kLYF63pk=; b=AkYFa/Jmlk+8B5IFvo2IlD+EW0nJu4ywgRK2EI3wfyDOIOZ71liwFfq2H769fsNS2BoJM9sET4rdVSEveJUn2iZMTcnWrkIQA0OK+raqJJ0Mg4nPAE9Y6pYQ8TcWUXRN1yZTk6h3G+rfvtEKsgoMok4uZuE3k5aJ/hI5lGx82ls= Received: from DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) by CH2PR10MB4134.namprd10.prod.outlook.com (2603:10b6:610:a7::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7633.39; Tue, 11 Jun 2024 19:03:02 +0000 Received: from DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84]) by DS0PR10MB7953.namprd10.prod.outlook.com ([fe80::5b2d:d28c:8773:c84%5]) with mapi id 15.20.7633.036; Tue, 11 Jun 2024 19:03:02 +0000 From: David Faust To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com, cupertino.miranda@oracle.com Subject: [PATCH v4 5/6] bpf,btf: enable BTF pruning by default for BPF Date: Tue, 11 Jun 2024 12:01:44 -0700 Message-ID: <20240611190145.115887-6-david.faust@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240611190145.115887-1-david.faust@oracle.com> References: <20240611190145.115887-1-david.faust@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4PR04CA0056.namprd04.prod.outlook.com (2603:10b6:303:6a::31) To DS0PR10MB7953.namprd10.prod.outlook.com (2603:10b6:8:1a1::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7953:EE_|CH2PR10MB4134:EE_ X-MS-Office365-Filtering-Correlation-Id: 8ba4e342-2c3a-4aca-3706-08dc8a491e0f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230032|1800799016|366008|376006; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?wYA8ecObkWuqcpkZHDVMBLDQKBCqgbtB3gtX84gCJ1x+ZLaW5O50ap1zRT1v?= =?us-ascii?Q?69LgDe8zzLDGkwpeV7C6o+Kcahy+JU2hqSFsVT45H1MGf32XiTTz13X0dT5D?= =?us-ascii?Q?1Drzqu6WbDBGeRunnyHHzvaaHkd66ZdDj/BG3H09fziYCU/Au3/rP+oK44Am?= =?us-ascii?Q?fIjzrJmySw0gwy1FPlaaOvdAXZBzzk4UvadKFTvyZByVrAVKMJViF8Rwiwdu?= =?us-ascii?Q?LaHU9oKoXdxDHumD/vGDilaPWQFrDrr4fedyxlhTZ3D9PGRds/9xQxwguxQ9?= =?us-ascii?Q?H+C6+cZxc6wQg625v2p9eZ9USb4ZFb2CEFl3fcw0H4HrM8U2WMxG1Qi/ydiS?= =?us-ascii?Q?Nm9Zmegyy/6xy2XYMpyfi52eNYSWGsV+5hOIblsJYug3D8HzbVXjd64cq468?= =?us-ascii?Q?vBSCqVMj9/rXSuyN5Fhq4K+wIi3Oe2jtI+/pFj0bG/uWQtBC9fgLDsslsqxw?= =?us-ascii?Q?i5v7MkKfIgwuhynFfnjiFZuEbSfEvptnVryZSXiZ3gpW5zfd/IFcA76ZzBn6?= =?us-ascii?Q?AcHJaC82UvSFHCTRcNJVfiYmYR0JjdONcVRT4FMCshASln6mV1DbkljHX00/?= =?us-ascii?Q?a20w+1HojCyRg+WYrz+ZDKvesHARDEu7Rz5DbtUG1LeRlvEIT5OEznv9kI98?= =?us-ascii?Q?YsmyGXok303V52YuVT5dZ0CBfiReZx/egYtU+BCiQe/W53CkL14z5VCwARWF?= =?us-ascii?Q?M/PZAoOK7i1WsAaPoWyFFVYi88yzL3ygUS2++PEnh2EaTNtFIgYVoSIqrb8y?= =?us-ascii?Q?wrACIJd3J1fPXgepvl2M25vDHsaE3HK6NwjYvSGxztsCu2tyRuglG0V95QhP?= =?us-ascii?Q?GTAdcRAs7/Vm8irPwSf+zb6cx8WeM372LDmTBrQooBY7n54FVlN+Vx8q+o6K?= =?us-ascii?Q?TbaHAQgdE06WLny4X/T1ktB6a4MER+Y765eFqWd8/j0J3btj2de3FPnb6nwh?= =?us-ascii?Q?RbDzf8xsm7n/JrkMc+WnZyRfkFY+zD6LkRgfSyWs68CnmlWEqTPNcmV0hP2p?= =?us-ascii?Q?IICp18iSodxqhKMFRi9/RWZpOaiQhJy4+JAMdOLVs6BOumZRrZWAuXnzv9vO?= =?us-ascii?Q?QrGSUIgC+hCbomxj+104DN7dPGuntkmAm8DIPftIa7tYoEz3n40ur7A/ssUJ?= =?us-ascii?Q?S9PAmoO1yHCm21gh5d3kcJ8neDlsW3qK0KGoFZDEo2ekjR49mJLkWM85MjBg?= =?us-ascii?Q?KlzfhW27RpzUmkNEYMhq2VMA5a7l2/vi01OTyAGLCgV534CMgjUvety8FrbZ?= =?us-ascii?Q?St92JRzoN/A9Wj3uCsHR?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR10MB7953.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230032)(1800799016)(366008)(376006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?PDGvEBK9bhF71WVqAqCMtNt/d0hfrSvkyC4lL9JbAn5CjRKVzI3V/TxE7TNs?= =?us-ascii?Q?24TUPn50H/GxFcQ2hSF2rU5S9ktXVtSiLsF+mRh9mL4ep9032uotoBXi/e5J?= =?us-ascii?Q?rhoLFAfPv/FBQwBkV1UAnL7mTlHfv6DTels1H9ThE+te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qs6i+Ilae+5BfPQE5ga5Wc5brOY50NLtgJkyumxSbBag2ab2F/eVTfqTLnrgq43hnhl6Th8/gXgiTtujTkkps1NWtWaJJppehkD4trfBdLPC/Dwf2CgjKAUYihokB0ggUBvlEkR40fVNh4zhleRALzaCfevatFGhpWunozzWmHlBJsLHTFxC77deiLU6x7DrHcgv8d237avyeY96PstxzYe3GuQmKWCDBqoFyyXdQZB8r3T0nUsr7RSgyL++020zndsWgeEP5ncqalOGGQWTHGIW+UJATJQlpWjw/dPIslpjZQw0lSV0mbFB4d3czKvHseathF6iiEQcyKlENi3N4wJ8OMfcLlCMPH3+9GIrfK2PmsVNPkdmo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8ba4e342-2c3a-4aca-3706-08dc8a491e0f X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7953.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jun 2024 19:03:02.2505 (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: v121RkDuPulXRe4I3qvP4cj2CLYgx0lyD5m2Xdt1Z9v5NmF6oSKo8FQVTPBXfpipBAuv6cq3jQymbhZcxnuuJw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4134 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-11_09,2024-06-11_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 malwarescore=0 mlxscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2405010000 definitions=main-2406110130 X-Proofpoint-ORIG-GUID: 2F7gETvaCeKtJ2NwSBQOUSgtVdCY1K9a X-Proofpoint-GUID: 2F7gETvaCeKtJ2NwSBQOUSgtVdCY1K9a X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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 enables -gprune-btf by default in the BPF backend when generating BTF information, and fixes BPF CO-RE generation when using -gprune-btf. When generating BPF CO-RE information, we must ensure that types used in CO-RE relocations always have sufficient BTF information emited so that the CO-RE relocations can be processed by a BPF loader. The BTF pruning algorithm on its own does not have sufficient information to determine which types are used in a BPF CO-RE relocation, so this information must be supplied by the BPF backend, using a new btf_mark_type_used function. Co-authored-by: Cupertino Miranda gcc/ * btfout.cc (btf_mark_type_used): New. * ctfc.h (btf_mark_type_used): Declare it here. * config/bpf/bpf.cc (bpf_option_override): Enable -gprune-btf by default if -gbtf is enabled. * config/bpf/core-builtins.cc (extra_fn): New typedef. (compute_field_expr): Add callback parameter, and call it if supplied. Fix computation for MEM_REF. (mark_component_type_as_used): New. (bpf_mark_types_as_used): Likewise. (bpf_expand_core_builtin): Call here. * doc/invoke.texi (Debugging Options): Note that -gprune-btf is enabled by default for BPF target when generating BTF. gcc/testsuite/ * gcc.dg/debug/btf/btf-variables-5.c: Adjust one test for bpf-*-* target. --- gcc/btfout.cc | 22 ++++++ gcc/config/bpf/bpf.cc | 5 ++ gcc/config/bpf/core-builtins.cc | 71 +++++++++++++++++-- gcc/ctfc.h | 1 + gcc/doc/invoke.texi | 3 + .../gcc.dg/debug/btf/btf-variables-5.c | 6 +- 6 files changed, 100 insertions(+), 8 deletions(-) diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 34d8cec0a2e3..083ca48d6279 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -1503,6 +1503,28 @@ btf_assign_datasec_ids (ctf_container_ref ctfc) } } + +/* Manually mark that type T is used to ensure it will not be pruned. + Used by the BPF backend when generating BPF CO-RE to mark types used + in CO-RE relocations. */ + +void +btf_mark_type_used (tree t) +{ + /* If we are not going to prune anyway, this is a no-op. */ + if (!debug_prune_btf) + return; + + gcc_assert (TYPE_P (t)); + ctf_container_ref ctfc = ctf_get_tu_ctfc (); + ctf_dtdef_ref dtd = ctf_lookup_tree_type (ctfc, t); + + if (!dtd) + return; + + btf_add_used_type (ctfc, dtd, false, false, true); +} + /* Callback used for assembling the only-used-types list. Note that this is the same as btf_type_list_cb above, but the hash_set traverse requires a different function signature. */ diff --git a/gcc/config/bpf/bpf.cc b/gcc/config/bpf/bpf.cc index dd1bfe38d29b..c62af7a6efa7 100644 --- a/gcc/config/bpf/bpf.cc +++ b/gcc/config/bpf/bpf.cc @@ -221,6 +221,11 @@ bpf_option_override (void) && !(target_flags_explicit & MASK_BPF_CORE)) target_flags |= MASK_BPF_CORE; + /* -gbtf implies -gprune-btf for BPF target. */ + if (btf_debuginfo_p ()) + SET_OPTION_IF_UNSET (&global_options, &global_options_set, + debug_prune_btf, true); + /* Determine available features from ISA setting (-mcpu=). */ if (bpf_has_jmpext == -1) bpf_has_jmpext = (bpf_isa >= ISA_V2); diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc index 232bebcadbd5..86e2e9d6e39f 100644 --- a/gcc/config/bpf/core-builtins.cc +++ b/gcc/config/bpf/core-builtins.cc @@ -624,13 +624,20 @@ bpf_core_get_index (const tree node, bool *valid) ALLOW_ENTRY_CAST is an input arguments and specifies if the function should consider as valid expressions in which NODE entry is a cast expression (or - tree code nop_expr). */ + tree code nop_expr). + + EXTRA_FN is a callback function to allow extra functionality with this + function traversal. Currently used for marking used type during expand + pass. */ + +typedef void (*extra_fn) (tree); static unsigned char compute_field_expr (tree node, unsigned int *accessors, bool *valid, tree *access_node, - bool allow_entry_cast = true) + bool allow_entry_cast = true, + extra_fn callback = NULL) { unsigned char n = 0; unsigned int fake_accessors[MAX_NR_ACCESSORS]; @@ -647,6 +654,9 @@ compute_field_expr (tree node, unsigned int *accessors, *access_node = node; + if (callback != NULL) + callback (node); + switch (TREE_CODE (node)) { case INDIRECT_REF: @@ -664,17 +674,19 @@ compute_field_expr (tree node, unsigned int *accessors, case COMPONENT_REF: n = compute_field_expr (TREE_OPERAND (node, 0), accessors, valid, - access_node, false); + access_node, false, callback); accessors[n] = bpf_core_get_index (TREE_OPERAND (node, 1), valid); return n + 1; case ARRAY_REF: case ARRAY_RANGE_REF: - case MEM_REF: n = compute_field_expr (TREE_OPERAND (node, 0), accessors, valid, - access_node, false); + access_node, false, callback); accessors[n++] = bpf_core_get_index (node, valid); return n; + case MEM_REF: + accessors[0] = bpf_core_get_index (node, valid); + return 1; case NOP_EXPR: if (allow_entry_cast == true) { @@ -683,7 +695,7 @@ compute_field_expr (tree node, unsigned int *accessors, } n = compute_field_expr (TREE_OPERAND (node, 0), accessors, valid, - access_node, false); + access_node, false, callback); return n; case ADDR_EXPR: @@ -1549,6 +1561,51 @@ bpf_resolve_overloaded_core_builtin (location_t loc, tree fndecl, return construct_builtin_core_reloc (loc, fndecl, args, argsvec->length ()); } +/* Callback function for bpf_mark_field_expr_types_as_used. */ + +static void +mark_component_type_as_used (tree node) +{ + if (TREE_CODE (node) == COMPONENT_REF) + btf_mark_type_used (TREE_TYPE (TREE_OPERAND (node, 0))); +} + +/* Mark types needed for BPF CO-RE relocations as used. Doing so ensures that + these types do not get pruned from the BTF information. */ + +static void +bpf_mark_types_as_used (struct cr_builtins *data) +{ + tree expr = data->expr; + switch (data->kind) + { + case BPF_RELO_FIELD_BYTE_OFFSET: + case BPF_RELO_FIELD_BYTE_SIZE: + case BPF_RELO_FIELD_EXISTS: + case BPF_RELO_FIELD_SIGNED: + case BPF_RELO_FIELD_LSHIFT_U64: + case BPF_RELO_FIELD_RSHIFT_U64: + if (TREE_CODE (expr) == ADDR_EXPR) + expr = TREE_OPERAND (expr, 0); + + expr = root_for_core_field_info (expr); + compute_field_expr (data->expr, NULL, NULL, NULL, false, + mark_component_type_as_used); + break; + case BPF_RELO_TYPE_ID_LOCAL: + case BPF_RELO_TYPE_ID_TARGET: + case BPF_RELO_TYPE_EXISTS: + case BPF_RELO_TYPE_SIZE: + case BPF_RELO_ENUMVAL_EXISTS: + case BPF_RELO_ENUMVAL_VALUE: + case BPF_RELO_TYPE_MATCHES: + btf_mark_type_used (data->type); + break; + default: + gcc_unreachable (); + } +} + /* Used in bpf_expand_builtin. This function is called in RTL expand stage to convert the internal __builtin_core_reloc in unspec:UNSPEC_CORE_RELOC RTL, which will contain a third argument that is the index in the vec collected @@ -1567,6 +1624,8 @@ bpf_expand_core_builtin (tree exp, enum bpf_builtins code) tree index = CALL_EXPR_ARG (exp, 0); struct cr_builtins *data = get_builtin_data (TREE_INT_CST_LOW (index)); + bpf_mark_types_as_used (data); + rtx v = expand_normal (data->default_value); rtx i = expand_normal (index); return gen_rtx_UNSPEC (DImode, diff --git a/gcc/ctfc.h b/gcc/ctfc.h index 29267dc036d1..41e1169f271d 100644 --- a/gcc/ctfc.h +++ b/gcc/ctfc.h @@ -457,6 +457,7 @@ extern ctf_dtdef_ref ctf_lookup_tree_type (ctf_container_ref, const tree); typedef bool (*funcs_traverse_callback) (ctf_dtdef_ref, void *); bool traverse_btf_func_types (funcs_traverse_callback, void *); +extern void btf_mark_type_used (tree); /* CTF section does not emit location information; at this time, location information is needed for BTF CO-RE use-cases. */ diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 8479fd5cf2b8..0afd686733d0 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -12023,6 +12023,9 @@ It is primarily useful when compiling for the BPF target, to minimize the size of the resulting object, and to eliminate BTF information which is not immediately relevant to the BPF program loading process. +This option is enabled by default for the BPF target when generating +BTF information. + @opindex gctf @item -gctf @itemx -gctf@var{level} diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c b/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c index 8aae76cacabd..a08130cfc072 100644 --- a/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c @@ -11,9 +11,11 @@ /* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t \]+\[^\n\]*btv_info" 1 } } */ /* { dg-final { scan-assembler-times "\[\t \]0x1\[\t \]+\[^\n\]*btv_linkage" 1 } } */ -/* Expect 2 array types, one of which is unsized. */ +/* Expect 2 array types, one of which is unsized. For BPF target, -gprune-btf + is the default and will remove the unsized array type. */ /* { dg-final { scan-assembler-times "\[\t \]0x4\[\t \]+\[^\n\]*bta_nelems" 1 } } */ -/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*bta_nelems" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*bta_nelems" 1 { target { !bpf-*-* } } } } */ +/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*bta_nelems" 0 { target { bpf-*-* } } } } */ extern const char FOO[]; const char FOO[] = "foo"; -- 2.43.0