From patchwork Wed Dec 7 20:57:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 31052 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp400736wrr; Wed, 7 Dec 2022 12:59:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf4tUdOyj6QRVnENDowaovYmtvnTqH8w2M/u+LgwY646SOoClqjqCgti8Bnzt/pePErBAE/8 X-Received: by 2002:a05:6402:214f:b0:46d:5e60:5b6 with SMTP id bq15-20020a056402214f00b0046d5e6005b6mr3645972edb.351.1670446789170; Wed, 07 Dec 2022 12:59:49 -0800 (PST) Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ht13-20020a170907608d00b007830e41ed56si18071798ejc.431.2022.12.07.12.59.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Dec 2022 12:59:49 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="g/S8snbE"; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 37C3B388B6B1 for ; Wed, 7 Dec 2022 20:58:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37C3B388B6B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670446729; bh=xjreCkKBcZYiTVOQa1cXI2pH8wTPjIJdKzSOEKV2lXE=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=g/S8snbEYwnpfxKcOCqmV0LpFmy2q+CE7a1C3CZxF5bayuALWPWHACYr4RAIVMAxM F/wV1Rs9ZJdo9zyHRVApppH9IZD62UVHUpN+RIxpQLsSsZtQ5NBmcqppuLYv6KPZXY +muLWygrmGcfxLESn5ysoj4b4Qrz0TdPJ6Etr1C8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 67C99381EC97 for ; Wed, 7 Dec 2022 20:58:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 67C99381EC97 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B7GDnXh010592 for ; Wed, 7 Dec 2022 20:58:00 GMT Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mauf8hc95-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 07 Dec 2022 20:58:00 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B7J7YPj017189 for ; Wed, 7 Dec 2022 20:58:00 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2174.outbound.protection.outlook.com [104.47.55.174]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3maa5yg674-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 07 Dec 2022 20:58:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gZ3F5Y1hSlU+OWHnkE9wllwbYzQRh6vDzulRddTT6PZ2V7V/YnyL9YeDssvxATe4NH0guy0CMzzEmgfS0f1jyjOC+NtmvRPaP3J/B/ykLrCGRG7c3jzaW43wBvGLQy573yXvLoNbsug+VSRBrQzLhbIX/MuNxHYbLUNwX+kSaBlVQZAyGfzsRNY0o6NEbc4050U/XbZ8GFxUWle799sAaDGEZQoml0NQHqvhdY0aZuLDG++KjZFFdm4PvOem6I6yJBDmKirVdfzc4KOx3x2086eYlGjRVdAGmvCi2YRYblK/kSXilznhKjnsIdWbQiISGBD3qq/7BJAXstVDANIliA== 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=xjreCkKBcZYiTVOQa1cXI2pH8wTPjIJdKzSOEKV2lXE=; b=I8O4vdJu9YCvKsv5x2exDCEyIAiog43dz4cvaHa8re0fHXyRaR00iVdonHyBqY/RnsTYBpbJRAGIRPCWATgQWiN38/FxXI5EM9h8fGgUFlan+0f1gsE0vhsAeUqvgSBj+JboYCSdwKR5wRuAX0ZR4p+VTmlgIqO+LGHCvfE/IyapFKdIozcbZDQvC4wC+7klh/AoAsAEGXpBmcR/Mc6fjcd5Gde9EHwykBcoQvSw0lay5KksAd2pwZkM6rKNZYCw3jQ7tNOnRAsH8sR+0M/2eMBH6s2nM/32vmNC9uFD3g75O46cy6QWWP3+tLpHL/E3TqjfgcnVQuFuqBWp6eDnaw== 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 MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) by SA1PR10MB6493.namprd10.prod.outlook.com (2603:10b6:806:29c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Wed, 7 Dec 2022 20:57:58 +0000 Received: from MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::dd41:a422:5763:8848]) by MN2PR10MB3213.namprd10.prod.outlook.com ([fe80::dd41:a422:5763:8848%7]) with mapi id 15.20.5880.014; Wed, 7 Dec 2022 20:57:58 +0000 To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com, jose.marchesi@oracle.com Subject: [PATCH 3/3] btf: correct generation for extern funcs [PR106773] Date: Wed, 7 Dec 2022 12:57:34 -0800 Message-Id: <20221207205734.9287-4-david.faust@oracle.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221207205734.9287-1-david.faust@oracle.com> References: <20221207205734.9287-1-david.faust@oracle.com> X-ClientProxiedBy: SJ0PR13CA0076.namprd13.prod.outlook.com (2603:10b6:a03:2c4::21) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3213:EE_|SA1PR10MB6493:EE_ X-MS-Office365-Filtering-Correlation-Id: c9691ddb-d76b-4fdb-8cd7-08dad895b870 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2aQmMska6jnJJrNIiXtj2YRo9ImS3UHXvlGo0Q7o5R1G2fcU54h13bG7T9JSorSeyWSQHcieD5dS6z9i3digEW+xH/62DqZBi90+5OQ3ra70zf96tP2UIfR1R3MIYzOq/elyDduZRqlbszshBnHgNIpLICtESpkQK3bHwul6LqyQ1UfTHFtoNt6/tE3lEsBrFTecdAFfXi+U2w/hIy39vCuPMCMINmkBVf/bZAp/6OExz5W63hINToyGMoz4mh8MCmpCCq49kHn5otblqQfaHDD1zun6Dm2cMalWSKe6JvbZea2ftZwsKXP9KkB2UqE7R6B2vNaAPz1+9HouM5btdUT67HQhI35y2jkELWD3MlSfg6Ihklu/QQBV1a8UeYBRd7s3DEq26XY5loIsHSPPOKvdGPt6KJ/+jQmyT9vpDH3Ou+FAKc/bQN0VrKZPjUn9xfYwlTZxPYr/lvNEsriU4jyr0X3h8iIMcpOZFJwTPQuAA7YwHRrPfPh5uQ1dQq+bywoVWjRN65tfy8ffKoz5O/Xv0Ew1IFn33ILBJpYIOeWk/X/dyQwBh0bBw726+mDv8bd2MQSxoYx/ciwHG7MFx5SkYRRrZhkK2LJVo56xd7PMQRxYV3jY1lhKHOO2DH0O74yN1OF/JAj2x3kQtZUDzX+wkeXC9GXu+h94V+cyAl86ttDRYHFpyWj9wvqkw5KJgFH1FSa4NhEgfpq0EMMsCQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB3213.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(136003)(39860400002)(346002)(396003)(366004)(376002)(451199015)(4326008)(316002)(6916009)(8676002)(66556008)(66946007)(66476007)(6512007)(478600001)(38100700002)(36756003)(6486002)(107886003)(6666004)(6506007)(186003)(26005)(1076003)(2616005)(41300700001)(86362001)(5660300002)(8936002)(44832011)(2906002)(83380400001)(84970400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CvF6gys05Pgry/keNfb4sg8DNSi7WblqRA/VhS6iOA52dPrjhz2HQ1gyawuvO8UgZwXxASIA8w1TuLoNDbwf4GLA+/APlLQaaN0cP3IRu21kKBaxgVP2R9LYHxovZ1fs49BwRm80TBH+X1cbHFFRFeNGtWIn2Z6Kh206AU/rmtk84565mOs+uqiXKnd5CK1mzNd0foHBcGd6HsXazcsE7NCxA7LK1D1Eg/4fNuNV3EegTnqn5m1MMChpmscj8LnfT6yQjQVtdgFL1lD4/ZbAGsyyMEEyEOI0dyp7tWKRUt6BMab0BTxr4qySkCPxi5eTK2PONckZQm8m8xfQz9AjMgSOJW4SiwqE0vVVwOsRtBdj9n3MJkVps9boffKEjkMBRUcgp/CrK4A7sSxqkzeXqF4VnKGP+p3J5Btf4NiWol2XS66gRNItV160HeigBlVWtz2TfX9Nc17dsslL8A52lL8ffSq8p42dsy5/a5TsE0NT0dRsgKNK9t5IaZZ4q+eq/wFGvvQVpnHdytXz9Z9T4dmEBGsOIjc+wQAD3rvMxA9hFr1xXa546nUQy9sbwUFc+G06CXwD1zGqwBb0b56AuCDkSUsjtCR571bngQcBTaotj5aDj8sudl5pa4CVs8vh27624Fcas4kdnRg/TTU0f7Rp8k4oHlpIdIVsjG38ihJQ4vO63fqzRcG1ih3m06NSDtE4H9iyuu4MFha+MczCIwh/sO5iOBMxZ166ILMlCHeaS62u8RoXjRZVxSMEqA9Cl47uehnsktfJ+ItFD5uXAvywLY79iGh8scXEyTPp/uEOyqrxzkx7tT5rLRPWOjtGSzgp+H26nMtwajuZ3GaoZspACn6qPKwQ/dm+8gLiG3YqdKBTzaaU7h7r+DojsHt5VNOIB41T9wv6KR8cl6ibLns649ntdYaPRanLxV8MGxOrkMAYokf27tDiUMLrUp54jVS6Ui0Vg1sN+rBYNdr4XUF1D1p4FFH4+oDIWxxdDy5w+g8BCSFNi/Xflc7JVC529EjRaIqHGq4da9ZfQkhedPcZBUUpogADmhSO0nIhce401R6g8AudoPCum0qZNb1IY3VeG4vyka/lHNGerAL+69Sq25V/iceR5jOyGnUP2ohNxiJ8uv4NeF5owUmq6cs6vTjGfH3e11yUWq+JbrYsbnp7Dsuvv1dhy1vPBfSLgWMClOrO6gd6qaROzRaB6AnwBPdvTUCGGWl9vdCd6BfphFaUebODmuK6gt+wYLKvhsI3+OqBKILADOmENF5pu6aN1d52vxjghZdtK6e+VoKfa2kHtIhVfvxF3GDz/r3Bv/DIMH7B/EG6+I76zFVtnA9RXFkawP1C6Uy51rVfUN65LMTTCiILxo6w0dznVjumxkfIyN7drIZLzhIHbEOroEGzrDNGrR4Sl+2depVy0NHoQctj1vLdEA9I3zETTXlkazmehnFSbf9W6ScGyjS4DzVfANWvgUW+JBxREpvF22GodgVtD7M/z+zZYsKgTaD96Moz15lYQpMhZcznGXCbPHtDNsONeI9WXR7aTwo8lcc+K0goc0fOX7l6MJO9/llnVjWV1/I7Vlxddcwfji4dP1qo X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c9691ddb-d76b-4fdb-8cd7-08dad895b870 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2022 20:57:58.4956 (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: kM6QiAMwqnTOGdcqN+6gjLWkHzsh1MuXdixU7HxBqwZxwS+kamZrQ07qM4vtB6CYwRYiOjm0f5H74+q+yXQZsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR10MB6493 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-07_09,2022-12-07_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 spamscore=0 bulkscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212070176 X-Proofpoint-ORIG-GUID: X1mVtAIeFZGfsHCforCUp7SsDpdAvwG2 X-Proofpoint-GUID: X1mVtAIeFZGfsHCforCUp7SsDpdAvwG2 X-Spam-Status: No, score=-13.1 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_H2, 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 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-Patchwork-Original-From: David Faust via Gcc-patches From: David Faust Reply-To: David Faust Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751590412828120558?= X-GMAIL-MSGID: =?utf-8?q?1751590412828120558?= The eBPF loader expects to find entries for functions declared as extern in the corresponding BTF_KIND_DATASEC record, but we were not generating these entries. This patch adds support for the 'extern' linkage of function types in BTF, and creates entries for for them BTF_KIND_DATASEC records as needed. PR target/106773 gcc/ * btfout.cc (get_section_name): New function. (btf_collect_datasec): Use it here. Process functions, marking them 'extern' and generating DATASEC entries for them as appropriate. Move creation of BTF_KIND_FUNC records to here... (btf_dtd_emit_preprocess_cb): ... from here. gcc/testsuite/ * gcc.dg/debug/btf/btf-datasec-2.c: New test. * gcc.dg/debug/btf/btf-function-6.c: New test. include/ * btf.h (struct btf_var_secinfo): Update comments with notes about extern functions. --- gcc/btfout.cc | 129 ++++++++++++------ .../gcc.dg/debug/btf/btf-datasec-2.c | 28 ++++ .../gcc.dg/debug/btf/btf-function-6.c | 19 +++ include/btf.h | 9 +- 4 files changed, 139 insertions(+), 46 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-datasec-2.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-function-6.c diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 05f3a3f9b6e..d7ead377ec5 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -294,7 +294,35 @@ btf_datasec_push_entry (ctf_container_ref ctfc, const char *secname, ds.entries.safe_push (info); datasecs.safe_push (ds); - num_types_created++; +} + + +/* Return the section name, as of interest to btf_collect_datasec, for the + given symtab node. Note that this deliberately returns NULL for objects + which do not go in a section btf_collect_datasec cares about. */ +static const char * +get_section_name (symtab_node *node) +{ + const char *section_name = node->get_section (); + + if (section_name == NULL) + { + switch (categorize_decl_for_section (node->decl, 0)) + { + case SECCAT_BSS: + section_name = ".bss"; + break; + case SECCAT_DATA: + section_name = ".data"; + break; + case SECCAT_RODATA: + section_name = ".rodata"; + break; + default:; + } + } + + return section_name; } /* Construct all BTF_KIND_DATASEC records for CTFC. One such record is created @@ -305,7 +333,60 @@ btf_datasec_push_entry (ctf_container_ref ctfc, const char *secname, static void btf_collect_datasec (ctf_container_ref ctfc) { - /* See cgraph.h struct symtab_node, which varpool_node extends. */ + cgraph_node *func; + FOR_EACH_FUNCTION (func) + { + dw_die_ref die = lookup_decl_die (func->decl); + if (die == NULL) + continue; + + ctf_dtdef_ref dtd = ctf_dtd_lookup (ctfc, die); + if (dtd == NULL) + continue; + + /* Functions actually get two types: a BTF_KIND_FUNC_PROTO, and + also a BTF_KIND_FUNC. But the CTF container only allocates one + type per function, which matches closely with BTF_KIND_FUNC_PROTO. + For each such function, also allocate a BTF_KIND_FUNC entry. + These will be output later. */ + ctf_dtdef_ref func_dtd = ggc_cleared_alloc (); + func_dtd->dtd_data = dtd->dtd_data; + func_dtd->dtd_data.ctti_type = dtd->dtd_type; + func_dtd->linkage = dtd->linkage; + func_dtd->dtd_type = num_types_added + num_types_created; + + /* Only the BTF_KIND_FUNC type actually references the name. The + BTF_KIND_FUNC_PROTO is always anonymous. */ + dtd->dtd_data.ctti_name = 0; + + vec_safe_push (funcs, func_dtd); + num_types_created++; + + /* Mark any 'extern' funcs and add DATASEC entries for them. */ + if (DECL_EXTERNAL (func->decl)) + { + func_dtd->linkage = BTF_LINKAGE_EXTERN; + + const char *section_name = get_section_name (func); + /* Note: get_section_name () returns NULL for functions in text + section. This is intentional, since we do not want to generate + DATASEC entries for them. */ + if (section_name == NULL) + continue; + + struct btf_var_secinfo info; + + /* +1 for the sentinel type not in the types map. */ + info.type = func_dtd->dtd_type + 1; + + /* Both zero at compile time. */ + info.size = 0; + info.offset = 0; + + btf_datasec_push_entry (ctfc, section_name, info); + } + } + varpool_node *node; FOR_EACH_VARIABLE (node) { @@ -317,28 +398,13 @@ btf_collect_datasec (ctf_container_ref ctfc) if (dvd == NULL) continue; - const char *section_name = node->get_section (); /* Mark extern variables. */ if (DECL_EXTERNAL (node->decl)) dvd->dvd_visibility = BTF_LINKAGE_EXTERN; + const char *section_name = get_section_name (node); if (section_name == NULL) - { - switch (categorize_decl_for_section (node->decl, 0)) - { - case SECCAT_BSS: - section_name = ".bss"; - break; - case SECCAT_DATA: - section_name = ".data"; - break; - case SECCAT_RODATA: - section_name = ".rodata"; - break; - default: - continue; - } - } + continue; struct btf_var_secinfo info; @@ -363,6 +429,8 @@ btf_collect_datasec (ctf_container_ref ctfc) btf_datasec_push_entry (ctfc, section_name, info); } + + num_types_created += datasecs.length (); } /* Return true if the type ID is that of a type which will not be emitted (for @@ -461,29 +529,6 @@ btf_dtd_emit_preprocess_cb (ctf_container_ref ctfc, ctf_dtdef_ref dtd) if (!btf_emit_id_p (dtd->dtd_type)) return; - uint32_t btf_kind - = get_btf_kind (CTF_V2_INFO_KIND (dtd->dtd_data.ctti_info)); - - if (btf_kind == BTF_KIND_FUNC_PROTO) - { - /* Functions actually get two types: a BTF_KIND_FUNC_PROTO, and - also a BTF_KIND_FUNC. But the CTF container only allocates one - type per function, which matches closely with BTF_KIND_FUNC_PROTO. - For each such function, also allocate a BTF_KIND_FUNC entry. - These will be output later. */ - ctf_dtdef_ref func_dtd = ggc_cleared_alloc (); - func_dtd->dtd_data = dtd->dtd_data; - func_dtd->dtd_data.ctti_type = dtd->dtd_type; - func_dtd->linkage = dtd->linkage; - - vec_safe_push (funcs, func_dtd); - num_types_created++; - - /* Only the BTF_KIND_FUNC type actually references the name. The - BTF_KIND_FUNC_PROTO is always anonymous. */ - dtd->dtd_data.ctti_name = 0; - } - ctfc->ctfc_num_vlen_bytes += btf_calc_num_vbytes (dtd); } diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-datasec-2.c b/gcc/testsuite/gcc.dg/debug/btf/btf-datasec-2.c new file mode 100644 index 00000000000..f4b298cf019 --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-datasec-2.c @@ -0,0 +1,28 @@ +/* Test BTF generation of DATASEC records for extern functions. + + Only functions declared extern should have entries in DATASEC records. */ + +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +/* Expect one DATASEC with vlen=1 (.foo_sec) and one with vlen=2 (.bar_sec) */ +/* { dg-final { scan-assembler-times "0xf000002\[\t \]+\[^\n\]*btt_info" 1 } } */ +/* { dg-final { scan-assembler-times "0xf000001\[\t \]+\[^\n\]*btt_info" 1 } } */ + +/* Function entries should have offset and size of 0 at compile time. */ +/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bts_offset" 3 } } */ +/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bts_size" 3 } } */ + +extern int foo (int a) __attribute__((section(".foo_sec"))); + + +extern int bar (int b) __attribute__((section(".bar_sec"))); +extern void chacha (void) __attribute__((section(".bar_sec"))); + +__attribute__((section(".foo_sec"))) +void baz (int *x) +{ + chacha (); + + *x = foo (bar (*x)); +} diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-function-6.c b/gcc/testsuite/gcc.dg/debug/btf/btf-function-6.c new file mode 100644 index 00000000000..48a946ab14b --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-function-6.c @@ -0,0 +1,19 @@ +/* Test BTF extern linkage for functions. + + We expect to see one BTF_KIND_FUNC type with global linkage (foo), and + one BTF_KIND_FUNC type with extern linkage (extfunc). */ + +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +/* { dg-final { scan-assembler-times "btt_info: kind=12, kflag=0, linkage=2" 1 } } */ +/* { dg-final { scan-assembler-times "btt_info: kind=12, kflag=0, linkage=1" 1 } } */ + +extern int extfunc(int a, int b); + +int foo (int x) { + + int y = extfunc (x, x+1); + + return y; +} diff --git a/include/btf.h b/include/btf.h index 9a757ce5bc9..f41ea94b75f 100644 --- a/include/btf.h +++ b/include/btf.h @@ -186,12 +186,13 @@ struct btf_var }; /* BTF_KIND_DATASEC is followed by VLEN struct btf_var_secinfo entries, - which describe all BTF_KIND_VAR types contained in the section. */ + which describe all BTF_KIND_VAR or extern BTF_KIND_FUNC types contained + in the section. */ struct btf_var_secinfo { - uint32_t type; /* Type of variable. */ - uint32_t offset; /* In-section offset of variable (in bytes). */ - uint32_t size; /* Size (in bytes) of variable. */ + uint32_t type; /* Type of BTF_KIND_VAR or BTF_KIND_FUNC item. */ + uint32_t offset; /* In-section offset (in bytes) of item. */ + uint32_t size; /* Size (in bytes) of item. */ }; /* BTF_KIND_ENUM64 is followed by VLEN struct btf_enum64 entries,