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 632AE38537AE for ; Tue, 13 Dec 2022 06:12:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 632AE38537AE 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 (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BD0j2vY013151 for ; Tue, 13 Dec 2022 06:12:38 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=H0OMN8htGplrxAb0lm0r/BnQLLATfQBj23nQGvrozDU=; b=zdK/MIoXdgjXxSxccgLreqhvAFe+zU2OUBIY84+46eKPBxnO1BfWsN+MpQ1Add0QJoMY uzKWFPZ0Qn5mB7KiF04kipGuupfsjdNIwfYqqcFR575LqUExje44hJx7mvwsARbbL9Z8 wm95OZor3P2s3ZD3Qpw603yWImI9NvrO7L333sYtnkJaIZy+spQ1tH18Bf2x7baoDMY3 MgdtlAVyZfQ2ScQKLeTqxEzdFqu1GkgcLSduHhU1v6Y/9z0tsRdEGdsn8UOWbPe+zXLX M0ApowQDJtGD2uQzNyJekDwa6rXuYAYU/OwKZ9ewmUi9xEkBBM7ZIQ5iKZSrTDXVnEYD ew== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mch1a4nfs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Dec 2022 06:12:38 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2BD5nwsT017829 for ; Tue, 13 Dec 2022 06:12:36 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3mcgjbe220-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Dec 2022 06:12:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K7vZOPItU7fgX/Mj1ckTJXubyw0OFsWgTMS3Xb1IbWT2Yq7/jFBR3pDQQgADoCgSQ7RGvh9T4giGdzVy99EN1zel5HIkk0MZ7NSdhonpaPfWawbBzGTNJHWcZRl/extrFU44NTA176J2LwgDj1ssNLHy3gYuPRtY1jJruW/BS3jcOozwAeamW+9dYNxugzL5b1/FqiYMIiCpmfdC/2Zsdr9p4E0YgqPISGDa1wqKmK/AqVpdIk6efFaHGVb+BDmaeuWGWdWhJ8qPzF//TprZBS2PbvUlcEMChKV7T5E4RwyrqeHxs+e5UY1LDODvW5EdYgSG+LI3FIkNFsicnw0UOA== 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=H0OMN8htGplrxAb0lm0r/BnQLLATfQBj23nQGvrozDU=; b=WIWnLnmPoQ1BwRP6N9J/0evhw5EbpZucItG/PGDMmLSpw1f8Zho4c1pSsT1jl+JX8fG1Pa0qL7d641fQonlfNYeObqezx4osgYoH1b8iOjtwrcqxyyItOxOfENi4iKJxGnZjZj+hAUvksSrXPT6TPxBa1+6dAyzMiFD1vej0f0KCxISbzd9EfGxEbbSCH3zLRKdph4uZiGdh/9ATVM5KRFhoZlHeij8SQFyEwEaSzNItLpoSjIb+u6Tt+pEknqfk2IwJPNvdxYdzXjdHeHPmmDkuj7lQNHfuXBBSXuNOQ9MNSxFNS6PDY0sukWwx162XbYxrnS0S+fU0RZPK273B0w== 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=H0OMN8htGplrxAb0lm0r/BnQLLATfQBj23nQGvrozDU=; b=twn/qxsN35M0s8GXmkjKSg0dDmEaLx14efV+Pkq6MzeKV29klDs/6Fseof4NyBIs12ULr0NLOT9nkWMIvBNOWSoTf2Qp95MLnt8CREB1zINrApv85XiNBNGTFACNpaIME+7ktWRyGMOJHnZZ6bm4PO5DDQwkxpMCDGxDcQygjHc= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by BN0PR10MB4918.namprd10.prod.outlook.com (2603:10b6:408:12e::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 06:12:34 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ee70:1952:4416:1bdc]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ee70:1952:4416:1bdc%5]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 06:12:33 +0000 Message-ID: Date: Mon, 12 Dec 2022 22:12:30 -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 Cc: jose.marchesi@oracle.com, gcc-patches@gcc.gnu.org References: <20221207205734.9287-1-david.faust@oracle.com> <20221207205734.9287-4-david.faust@oracle.com> <5958e0f0-a22c-33d9-c935-7adf0c524b06@oracle.com> <565b04a6-b495-a78f-8318-d178fc849e2d@oracle.com> From: Indu Bhagat In-Reply-To: <565b04a6-b495-a78f-8318-d178fc849e2d@oracle.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: MW4P223CA0029.NAMP223.PROD.OUTLOOK.COM (2603:10b6:303:80::34) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|BN0PR10MB4918:EE_ X-MS-Office365-Filtering-Correlation-Id: 71403207-be48-417a-4851-08dadcd10630 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q78YAMhjNIPwVGLGOPtVhfhg7lOqeJF+o1hb/DsznhBnWiCru4P09vzhB2YW76sAgHV8VStuwk68I71wILc86FOLj3fdaDBkoZqrsCM7QSQ8pECZaTiRcd5+4hDp/K8IGm21AbpGbkzzJpYtQOxlDSMA+JyzwtZv0WNT7I+4p3nEaEb5tFHoZhuB59nDqPXV/m3gqA6yyoWAXVKHChMsXWEId6jQIVaZhCO+ZaNVftSj9Gt6LNVbnpN5YznmvYUoNKS6WqhC8c2VCSiyPZOr32l+FMW8vtM5qQQ9s2C22i0Z9LbRATfeG+NO/vyb4+owX0Jp1xhC4TJ/UsTJKkjANGgsLI/J5VlQ46kohNq+Z9iiT+8WG8DuLO1Bk/0YKSoqX73PahxuiBzWJnLVPavaw1fUvv14zMxtlwVDXi+v7Tj0+GyNBWh4BTcYw2r2rxiwlCfcs3AO4ZOS9flo7I9sew7OJqw1997ayQyv4GmEq7N53Gs7CV8Oy6m5OEYO+CpxWlK3qbc7ghAsFS6g0gtHO5b9dkjE4qQSq2Srsk4frrhBk+JlBa+NAt6DjYnPIy6jW9vzylpC3xLn5ahaUKEKnghYMABS9aQ2/i43TL/oMiZN/BTswq6sdZH4qMp7NvA1uzxCdSa5jwjxOkR2BF0q0KuHbJEkv5EUF7ptUdtIB38iYdZHhmzOYc6EvL+bies5/Ckzbgy3EtYCGn1hXRb1/15Nd9vadBQwsHYZ6G1HhyyqhUBjmkeHwhsOuPakwJ6JBwJeUeDp8WK/YclPLPJa3IcoNSvBFcxnjO5+z7M5eUU7UWfJdnaeT9eKB/CBJxOI X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2158.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(39860400002)(136003)(366004)(396003)(376002)(451199015)(6862004)(8936002)(84970400001)(4326008)(41300700001)(5660300002)(44832011)(30864003)(66556008)(8676002)(66946007)(66476007)(31686004)(478600001)(36756003)(6636002)(316002)(2906002)(37006003)(6486002)(186003)(31696002)(86362001)(6512007)(2616005)(53546011)(6506007)(83380400001)(38100700002)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?NzY5N2RXSlhrblBodXpGTmlxUC82eUlKcVRJd0QyUlB5eTZMZE1LbnRpUzB6?= =?utf-8?B?amc5R1ZCaVYzaGVnUjZFZTRnVXI2NklEbWlUcHNtMVE2M1JpcFdrbWZQVXdV?= =?utf-8?B?V3hpVVF2ckREWVNPb3ZqTnN5aE1lRzdkSDNFTVFhcWZGL0MyWEJQSzY1d1dT?= =?utf-8?B?WHJDVUl2enF3WHp5b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mb1Z0NlFGQzZV?= =?utf-8?B?RnBYRTJWYlFYTlJRYlIvb212c1hSZldoUmtZVk9qdTBZR0Q2TDlZdFZJNGJ3?= =?utf-8?B?Q0FTTzFsdS9JS3dCWTNsc1ZKcmZlRE1mVUdTc1NxVk52dlhqa3FFcHFhR3hv?= =?utf-8?B?UmdSOCtmNDFlazlWMXplOFN3c0tPZEZ4Vmp4WGJaWHhNVG5xNzBGTkFPZWkv?= =?utf-8?Q?qzhs1LVagZv4l6X3Ea0+xlo=3D?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71403207-be48-417a-4851-08dadcd10630 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2022 06:12:33.8011 (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: Sc3HNwy5SoKFsND0QKvS3iI2WLbvGCcprzRQbGUcF+NaIgqA6pBvEepS3JAviMRqyYhhcjNsHksL1cTe47qsPQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB4918 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_02,2022-12-12_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212130056 X-Proofpoint-GUID: uG03ALC4n9ZqqCTJXpq1LKlM8e2JdY0C X-Proofpoint-ORIG-GUID: uG03ALC4n9ZqqCTJXpq1LKlM8e2JdY0C 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,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/12/22 12:31, David Faust wrote: > > > On 12/8/22 23:36, Indu Bhagat wrote: >> 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; >> } > > Using clang implementation as the reference, a single FUNC record > for "extfunc" with "global" linkage: > > $ cat extfuncdef.c > extern int extfunc (int x); > int extfunc (int x) { > int y = foo (); > return y; > } > > $ clang -target bpf -c -g extfuncdef.c -o extfuncdef.o > > $ /usr/sbin/bpftool btf dump file extfuncdef.o > [1] FUNC_PROTO '(anon)' ret_type_id=2 vlen=1 > '(anon)' type_id=2 > [2] INT 'int' size=4 bits_offset=0 nr_bits=32 encoding=SIGNED > [3] FUNC 'extfunc' type_id=1 linkage=global > > With this patch we do the same in GCC. > OK. Thanks for confirming. >> >>> + 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, >>