From patchwork Tue Dec 13 18:44:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1715449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=CbxrjoRK; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NWnX065whz23pD for ; Wed, 14 Dec 2022 05:46:24 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C8E25383A0C0 for ; Tue, 13 Dec 2022 18:46:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C8E25383A0C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670957182; bh=Hwjo84G/AdROewj8mnA5ssg4Ew8WTXH4Rt/LXo7nrMc=; 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=CbxrjoRKnF4wauASHPEoNE1mZYoudwRWvtn59hB3yRlUeTLvStLyuVzaFUqO4YgJM IdqqG/nvzBLw8BiZGiSmp+SZn2a1BWAQQw/+LG2czKY6+MWR5n4fdCKCnYRfjIH0ZV EWgvEdFcFgig+TcxyFH7L0Xhvhu8pkTmN+pmSJYs= 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 1FCF2384F715 for ; Tue, 13 Dec 2022 18:45:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1FCF2384F715 Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BDIhqFH004978 for ; Tue, 13 Dec 2022 18:45:04 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 3mcj5bx77g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Dec 2022 18:45:04 +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 2BDHwUIN040184 for ; Tue, 13 Dec 2022 18:45:04 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3mcgjctsre-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Dec 2022 18:45:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ES+oSZsqy3/HawEGDK4XvTsgs30ImJaZXJEdJNWGXDSN1RFEDQIDMXOIheK+kqewJc62jBhNIunDAnD/LiceoRz5czudsjHfZQAQPds6vwYJavaoXPyLK+S8eaug4vepYeCN0qCvbwjIC/40Mvpn0wao0Y1dlUj6ABltuN6PNpyLiXo737N7gLfJlDg2h+ig8aXxKzlkW9lER/KvMboXktBXQbngdi9NvcNXj8Aw0wRmK8n3o/olkKfORxWTghPAMwCCSuzIuLqwOwAbHUmUCVi7dZiWccXSpqEpKIEcNW/CMQI0FxlkW8ROKbqo0R/8i5cQvM3GxKScLfkrq9yrKw== 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=Hwjo84G/AdROewj8mnA5ssg4Ew8WTXH4Rt/LXo7nrMc=; b=X9tJMZ5YIhZMuQZ/eP66WOAOzrUlAVpiDF5Rm+/hZYpnhX3L6svJfbbRzxAJSv0Kic55Q25l5W5UwjMRkSO8yzxm9moUa7F2dxwcKNCesVnPgsnaEPPEUU4Qo1xyAtcHmKSEsav3WYlnGXMben+d+nC5A0jotoLtggz2S4uMplA9FFq3EjTsAj6Xi0Vknuc0M7xA0oIFBAoPPNoOnKtWnEwEANit858l1giRh1WhzfFD3ilkuq8QaEf3r6ji/UISlVxcH0yPyAnN5aYjjOimK8VhwsWuAK8wmXFPHG6yZTqVxuUvjl+5A+27/f49UvZyWb7JsE7iXjIqm8cSri4Tyg== 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 CY8PR10MB6442.namprd10.prod.outlook.com (2603:10b6:930:62::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 18:45:01 +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.019; Tue, 13 Dec 2022 18:45:01 +0000 To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com Subject: [PATCH v2 3/3] btf: correct generation for extern funcs [PR106773] Date: Tue, 13 Dec 2022 10:44:26 -0800 Message-Id: <20221213184426.8861-4-david.faust@oracle.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221213184426.8861-1-david.faust@oracle.com> References: <20221213184426.8861-1-david.faust@oracle.com> X-ClientProxiedBy: BY5PR20CA0004.namprd20.prod.outlook.com (2603:10b6:a03:1f4::17) To MN2PR10MB3213.namprd10.prod.outlook.com (2603:10b6:208:131::33) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3213:EE_|CY8PR10MB6442:EE_ X-MS-Office365-Filtering-Correlation-Id: 94fed067-6bdc-4ba3-6ed1-08dadd3a244a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F7vB7oe1bv+HWafZYDa9V/vf3+SmVB4WngNBQ7ij1bSDcf7XElHjVwTUAj6eR3s5K7uQhiEfmpg8sOQl17GozFofbIpPszfvCqsYY6yYFYly3SnofPf/DEk0d30072yITeKBXQUBEnBoiAXUQMBp0OZgwr1P2wUboVb3f5C583JFimwikyRdgBwYAxtbEbVkx8jJk7qNyg3FuwK8ZKLqw18+W4DIA2hm+WHWYE2OOrCxHS6H9nIebpyzlmahTK5qy/oDD48zVmctwKCXBHrCTuOlZx0JSEtz/8Smxj7cJuNpc2EMLl15gDTXrYScq6I2j2+Nce0dT6Uf7v09LpsSNCapJqmbTMaKHSdg6OKJbS3vGnFo46vUlFCzdVgTWE/VF7dsid0pV7FB/RF0MGcXTGlw5IBAPJq20OviM8tfkIZl4Vq2hSH9xXnNfkBaZF1sz2jUFghv4IGIH+gUlVgJbd4fTSb/jU8xp65CKIOikuHFsFGXbRm111FLvMqk3zfG7iWBkJqqIYkmkSUuuibeUkuXjK0514dqAc8uNNgiLewVLxHX5DWx1d28RTKciwe0bojeza+snA+IeglM6F8rrNHktwKm9MwGUTsTijH67+wPtveY7F+g5BqpZoxlLZaiyLSfSIdJ3Pmf5sar8a0Z4D/tNILQnDngFfwzklOC9+Gt49QeCiZOxtpgtK4V2MQNIMeGeLsz/fSlGhlALvYCvw== 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)(396003)(39860400002)(366004)(346002)(136003)(376002)(451199015)(83380400001)(66476007)(41300700001)(86362001)(8936002)(38100700002)(66556008)(4326008)(5660300002)(66946007)(8676002)(44832011)(316002)(2906002)(107886003)(186003)(26005)(6506007)(6916009)(1076003)(6666004)(2616005)(6512007)(6486002)(478600001)(36756003)(84970400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kDpOPOLHwMt3kT4Of9mX+E3aipETAIlc88TgdqtojYYbQorHM7q/Xb/pByl1KlR+A8Ejf+AzUd4D7CxLoqdF/sH4UTMU9P92ZgvySNa1PX0kduTIz2lVXu4Go11BdY+XY9Xpuby6CczHrUUNAKzsKFq21+ZS5FIiyyFe/w5/RQuX6induxwEbCtkrBX0QGmtxWiMxibPOgtUFHjhuk5pr0uY0ieRxmfHproXf8UN+4cquzk65Eu/YMY8EaT0/eAOn9hXCuHhLcF5ARvJC1WUTiP7qphSqGFxh7XmBKS66yc0IzlisBSHZ5Dd32spcP0+grH7Yz9TiK32MFTn9s2L4YlcOXLdq2RNLZlYSiGSgebjMCvfA9LJpggjtDhEaMV+Rx7z+w+JdoJs6Kb9mOXYOn3SRR9hvL/6l+MYAMW982+XbRnVIfLPii/Y3qn0XVNFn1DW0mpejcA01RhEuv+swSGAIjJe/ooQA/lmUqTbiNef+fd9Zqmgh+jJA8lSiiS8Gsd1M9xB42TdzTe5lb7sD8smdhUbHruvJGBNy0nHbQKhfXs8ip0fLsYvTo6KuLen9YljKI+uLakY9ct3PnyMCSjMdhGTjqRD+e1czqrqSSyx1meqhDXfAzg0wgx4W4zUqPvsCMT6hyheMTC9V7c8lcHTDUxqwqJYOzCHlwhyw1Dc38K6tzRmIUiSlJhHn6NVbfysTkii1+N3tGcrngS6nnNgnHD5xAHNAEiafWXViYyjY+HW4EtSHJxtC7g7ppB4ah+wzqHBmB2M3j37JCApLejPN0lkqOq/qCiNwpKOncQKrTp849gygldfzgrlfPt7VL0+tSDhNbUfeN+v5eqQB8tZSEC6MY6WbKYJd0NXqiurmBSfzjj89WAqtMhDQZygAjFX4RC381Ir1H1j5yEJzh5JfGk1FAjeW869MzgRBSSst2JtLBDU8Kd7JH872nDmNpttpY6TRY3/ns5wQ3Wlk6D5SBGvv1cRH68d/oEGKDjX5iXMaL3hFmAu6TLeHjfhFmKyAzWl8zOX/+VmLAH4AGY4iadgyoQf97E4iPrg0wIiZO6GKAUpoVv8ZZTTxvMlfNlYsR257SHDbiGJoMCGH55IA8s3TnR4XpHZWqPuXKVZ6t4KRf+/29ptJ6pHcMgfBpub8y5VCOXG+cH6pubH0QqTMqmdxL5RfMFIPqspWjVoc5WRrNrgBWaV+62lHJwmUjmZA8yAlHYSW2iSfJn0XOmns+kWtVHbpSfu02p67kRy2NHd3UdqzBarUs0vWHCzqaFZbTWwSXiFUFbaomJLItUwaPxCx2FMQpzXu5YQnlhcJdyUqFcXMpiJ1xsEpqBUJQa8cYjjnXTETdIrjnR77rh7AIfboBbVFV1X1anVlUfQAhpVhWuogM6XjDMxSBWyE7YRPVTf9V6DVlhW81K35+kvZJsMqx0oXDJpT2YNngrj44a8LBwOXSAlzhRkUjdyi7ta26vB4CQI2/Vo2MsFj/TsbydIj0foCs2GgFrdy+7mi2+gnNg1uwHX+JVe9RVqMDD+3Pek09KSeV8RfZq6r7QeF3lRbAVoJuqumgdEGOTYlKBBvzVvrKw3E+CkYFBv0hFWlQTrana7FoXC20G4zQ== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94fed067-6bdc-4ba3-6ed1-08dadd3a244a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3213.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2022 18:45:01.5077 (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: kDRrYuQ2ljtqZBkxHEQG8KLjLk5XkEvIYOahQX0jZEgOkEIcRtX5WcOL6NBtwVV5Vm9jQPcY+1zoakbCsrkgoA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB6442 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-13_03,2022-12-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212130164 X-Proofpoint-GUID: nhMMjatN_zvpNsNzmOo4gJ9-TplV11Fy X-Proofpoint-ORIG-GUID: nhMMjatN_zvpNsNzmOo4gJ9-TplV11Fy X-Spam-Status: No, score=-13.2 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" [Changes from v1: - Add enum btf_func_linkage to include/btf.h and use it. - Minor updates to comments based on review. ] 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 (enum btf_func_linkage): New. (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 | 18 ++- 4 files changed, 148 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 204b11d4e9f..a423fabc0b5 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -290,7 +290,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 @@ -301,7 +329,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_FUNC_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) { @@ -313,28 +394,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_VAR_GLOBAL_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; @@ -359,6 +425,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 @@ -463,29 +531,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 da621353aa1..2f8f6f68b27 100644 --- a/include/btf.h +++ b/include/btf.h @@ -178,6 +178,15 @@ struct btf_param uint32_t type; /* Type of parameter. */ }; +/* BTF_KIND_FUNC records encode linkage information in the VLEN bits + of the type record. These are the supported values. */ +enum btf_func_linkage +{ + BTF_FUNC_STATIC = 0, + BTF_FUNC_GLOBAL = 1, + BTF_FUNC_EXTERN = 2, +}; + /* BTF_KIND_VAR records encode linkage information in a single trailing struct btf_var. These are the supported values. */ enum btf_var_linkage @@ -195,12 +204,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,