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 F41133852202 for ; Fri, 9 Dec 2022 07:36:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F41133852202 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com 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 2B96x3Si002788 for ; Fri, 9 Dec 2022 07:36:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2022-7-12; bh=RhUPC2hvCTSmTGniR1U/0XQz4S7Nm8FYgrHJsPm7yiE=; b=AajPqrEZU9sK8O8K6mJJc6ucDUF1BHjciKbLdz7ie8oK6VsmF6LoVov8SymSv7t6lTeO houzdXArKRC+9AQtpgxdmmqWkBzRnv4nnRXrKeihIfUuI1xdWItTNK0nq9E6A+FXzK9l v6qLRHcpMszfjQP491v7dUTEg1gIIrvXvt1BKMSpU8b17cToqPvtRhQLKsSzhUNzL/sa tR4fcNs+O8BxV53cEcmX6UV722F40lBomLdn0yudLqj+OmKgqln3EcfS0wFV6V7rNI5u zIcHlaEb8TkQ2x3CpGYFuZdN877LugxhRT/0gn1OFmRJAlpsc1KS4gVY3QSFQS8PyQ9S 6g== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mauf8mfks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 09 Dec 2022 07:36:18 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2B96O5d4032787 for ; Fri, 9 Dec 2022 07:36:17 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2168.outbound.protection.outlook.com [104.47.58.168]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3maa7ffstb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 09 Dec 2022 07:36:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A1HRBdePUjedHVwzB8vXN4v1HN2rIKcEncQGEIuQ8pkwSLhlun00AhUcm2+DMcWtPODYmNnmO96ipIWMZL/5FJQk2rG1lqVpzVWtFj4bczRiwgTSKjebmczCg92e5plkh4qL6JmZHE/7ECRbrsH7YugXztgeqiDQJkWz3qZkt5HT/QQBEXBDCA1zQN1SreTiKw8d+a6VPbpVfA5ltcvNaJzLbNujr22AFHEAJtmSt7mfw6IusAarCqKm+1qZJRfo7pSPJUUzIP6L+sMQY4aSQV8uB8bWerja2JEfsvhCcFDneFmVQmyzI+FG2AGH/8SLGxoSdSKN9av7Lvys33iLIg== 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=RhUPC2hvCTSmTGniR1U/0XQz4S7Nm8FYgrHJsPm7yiE=; b=n0hxNf8ox7lunffwiyvoN1VuTnyEo0qzuqKVDgPnjSqEI2kBSAcsWZmSNNW9maTzy4UYOoM4vBjUSA6WQOzUPneHosWN4uEvPrtpoBO8xstOnyGw7txWT/YthK+1DrOGN32ZMLmSlJ0FKa/JM0tpDzQsUY4ShqgFlGChUg/xxvfNsjbjPvwrfTGYHC4Z6jFIzgfeXDwQjmUvI5fUka/xtL/SjlNqw7/VVO395Z9ZT1bz+UvGOGgFnzT1YJic/I5Ta+YLfi1t5D/XmQcD5yJjUr3fTFuW5J8wW6pyrPnpexRWnTlA0vRfgYM4+88B/svXNtsD87ip47CzIQOcx7fteg== 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=RhUPC2hvCTSmTGniR1U/0XQz4S7Nm8FYgrHJsPm7yiE=; b=GBxxnVgvL/i0bOckMhv5SJgwoMVD/OZ3nSBr2byXrICXphsXtOQhRhVTJTLK4S14D53X3yHosVFHWEJ6fstrxMUw+J9Rb82QaeZ7I8LSZaSakoobLINBStnMEX84EXcKTpJ+WLFAXCJduBmnxFv8YhEAG1nIekeJy7GZfhun8pg= Received: from BN6PR1001MB2147.namprd10.prod.outlook.com (2603:10b6:405:2e::26) by BLAPR10MB4835.namprd10.prod.outlook.com (2603:10b6:208:331::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.16; Fri, 9 Dec 2022 07:36:15 +0000 Received: from BN6PR1001MB2147.namprd10.prod.outlook.com ([fe80::a4df:bf4f:569b:7d16]) by BN6PR1001MB2147.namprd10.prod.outlook.com ([fe80::a4df:bf4f:569b:7d16%7]) with mapi id 15.20.5880.016; Fri, 9 Dec 2022 07:36:15 +0000 Message-ID: <5958e0f0-a22c-33d9-c935-7adf0c524b06@oracle.com> Date: Thu, 8 Dec 2022 23:36:12 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Subject: Re: [PATCH 3/3] btf: correct generation for extern funcs [PR106773] Content-Language: en-US To: David Faust , gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com References: <20221207205734.9287-1-david.faust@oracle.com> <20221207205734.9287-4-david.faust@oracle.com> From: Indu Bhagat In-Reply-To: <20221207205734.9287-4-david.faust@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MW2PR2101CA0004.namprd21.prod.outlook.com (2603:10b6:302:1::17) To BN6PR1001MB2147.namprd10.prod.outlook.com (2603:10b6:405:2e::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN6PR1001MB2147:EE_|BLAPR10MB4835:EE_ X-MS-Office365-Filtering-Correlation-Id: 53e8580e-9ddc-43c0-12f3-08dad9b80d80 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8WKU2BtWqZIA9PqmctfYkxpSbYvioqA2XhBT+MoA+1LwS9RbeMPkkKxiCuLsUiVilD3Ov/3oQqVJY2hAnTmLFbr5+9ui8ey1upHUKIn6StNjw8F4ZifvP2R3W35BpsEgBdFRdA7uT/4QcTfkPbSNX06fk8LBcTglA8tcWR1eU9tlis8UxHSB2i3mKP4Q/xZdN0E7vZDhn/9G7U4SlMJQajl78v96PriLfDyO1UZ0SxMVOD78hbTctqDbGYos7nhmilfYYj4jWDbXtFHd3CaPlw2zyFEjhzd0MT/a0hmoPJokGpOX2Mu50AkSrP8Pk1eB+TxXNKMDk4Ern415u08vNRPNGkZjyXr5G0ivLWrd9T9jvyAVe3UPi3HHuG3gE232ylhKjaIsOBPfLBOmvH4wh4gKANsiBTICHi7G8Qy5BWftRzARL95DruZ+a9Uxyo9reQz2zmEMVMP5qleNb37Tchhr+JazXgQp1+/+sijYlgQ+th0ZaTppRlD3cX1wrzhjuvFDqTTEp6awbNhZQT6FFftinUdhsKIyiS7CvwKp9Hi0EVtfc2bAUltd6r/quTS4b8Tv+9i6CUa6lum/KhP4+FMK8CloSPUmSGo5S6pKazYWsBBX5sbEhFuUjcWutjzzsx4Vwtv6fySWpLYj8HmGqZMdbsIgY9JItvpN4PA3YLtDPcTTh92Vou74fS2rXOuJhPjcYGv9nic3xJUV05TjX8Yfttpxx7a11XeK1PgF2Vh8rR0l9F5oHBxRHT3ZjOSA6A7XPDMCKbPIeS87ZTDyUsujdz2U6toDs1nbjQCW58c= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN6PR1001MB2147.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(396003)(366004)(39860400002)(346002)(136003)(376002)(451199015)(44832011)(36756003)(86362001)(66946007)(8676002)(31696002)(2906002)(2616005)(83380400001)(478600001)(107886003)(6506007)(6666004)(6486002)(6512007)(53546011)(186003)(41300700001)(38100700002)(5660300002)(8936002)(4326008)(66556008)(66476007)(316002)(84970400001)(31686004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?bm5tcTVqYXhkOElLa1B6Nnh2OUo4bW1vdjVJL0tqaXc3VGxwd0ppMnVmVHJL?= =?utf-8?B?UDBWejZsdVE4ZVpRL2lub2Z0S0ZHUWl4MUxYU2NSVnVSdDBieXRJalpoTFpI?= =?utf-8?B?UjI2aFByZlhPdnN4aXpLL1BMTkR4Q1RuZDdUWDBqVXN5YTdZbjBrV0xSamNF?= =?utf-8?B?Z3JCRTFnNmJmNHhQMmdmT1RzYTVqVjRNUmNoWEdwZ0YzNWRSSzZYVXoyUkYy?= =?utf-8?B?cU5sTEhxbGtLbWxRd09QY3dOa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TFGVmd0UjgwSHJ0SGtwNVFveWVl?= =?utf-8?B?R0ZhS25iMHlWdWUrcXYvVDN5VkdWUW5lclg2WmF1dW9IblM3NUtiUDJrL1hP?= =?utf-8?B?K1F3SytCanR1UDVqU1JUVE1FRHdod1RFZUJmSWRiczVkb295K1ZNL3BEZGVW?= =?utf-8?Q?5UGqGUXh0CFYkgQnbbMomS4=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 53e8580e-9ddc-43c0-12f3-08dad9b80d80 X-MS-Exchange-CrossTenant-AuthSource: BN6PR1001MB2147.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2022 07:36:15.2553 (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: EA2BXDvbBUNkKKMNxf8XqSmTUkBIIAqtbOoZcRgLA9H/JzBzULkOV66D8h+iuhPJDNKntObRbAmzZseJiZdLGw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4835 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-09_04,2022-12-08_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212090064 X-Proofpoint-ORIG-GUID: Nq5i6BQgAgkHytMUrXGMqomoMbpV433j X-Proofpoint-GUID: Nq5i6BQgAgkHytMUrXGMqomoMbpV433j X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,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 List-Id: On 12/7/22 12:57, David Faust wrote: > 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. */ "Dot, space, space, new sentence." > +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. */ "Dot, space, space, new sentence." > + 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; > + What is the expected BTF when both decl and definition are present: extern int extfunc(int x); int extfunc (int x) { int y = foo (); return y; } > + 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. */ "Dot, space, space, new sentence." > + 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,