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 050CF395A03A for ; Mon, 11 Jul 2022 20:37:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 050CF395A03A Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26BKOC1g003479 for ; Mon, 11 Jul 2022 20:37:28 GMT Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3h71rfvnc1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 11 Jul 2022 20:37:28 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.16.1.2/8.16.1.2) with SMTP id 26BKQlaj015313 for ; Mon, 11 Jul 2022 20:37:27 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2100.outbound.protection.outlook.com [104.47.55.100]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com with ESMTP id 3h70428pdd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 11 Jul 2022 20:37:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cdn7hEA9LCDPersuuEMy8DudTRYosV8PyQ4rscA5U41PlQJ0QefzCFXZjLlK4vk78i+9hsY7mOAkfiMuk8QxWoOB0PLKF8AMumE9vv+3UB1/ShVUP81CP4a/V7R03fV2SxylMIrdnJguWdVSB/CpUKaM2GFAdEUQ16YcSPuuoEzsfGFWSFOCcxKcsp0/xkV0UeeB+p4ZGkThYO9xihfN6cr+nVbqLX/jtQcasaaHCmfcWz5KS8woKRiCrO+gU8nzMQGe6jhFB4u6AM3VDkwjNVTDA+BG5TnAIJSxOAA2kclyKYLSbp5QjSlh3b2t5nT8nENuvJuR4CNgfVOLZuQsbg== 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=6FKQCXqa83m5BZHvgtd8ycsVBoUjjvOVnzfJ5Y0RXBU=; b=ZxZ/j36M4bESQ4SPiBiWiQMUqeX3Dfxc1Bx/X6kFKAwVUt2TkpQfkmpAj4q+BKGvvZVTnuNbhFlP3CVRhFVzC9lCcIwAqksDoZ8xCK2YZLFX+Sjqc1bEx10PNCcqUAVg/JPSmn7k5gIV6IJiyQA9RwmdAZ0rxlzF7BODanapCGQGegzYnDc9e3zH2kP/FoU5H1jMd5WqPHMae/Czwu3fON7Zhnac+gmTDaLgWdOOjL3CSeikXZ6tCGDtLLHOnHrkK/ak6iJNW6xFuVN0rzDM+wTCwKEmWx5+OKtAJjOMFRRmVLCHN1tk3n77WItu4hKCz8I5j4bPmmraHhxq3meRrQ== 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 MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by BYAPR10MB2454.namprd10.prod.outlook.com (2603:10b6:a02:a9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.15; Mon, 11 Jul 2022 20:37:24 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::65fb:fa92:9a15:f89b]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::65fb:fa92:9a15:f89b%6]) with mapi id 15.20.5417.025; Mon, 11 Jul 2022 20:37:24 +0000 Subject: Re: [PATCH] btf: emit linkage information in BTF_KIND_FUNC entries To: "Jose E. Marchesi" , gcc-patches@gcc.gnu.org References: <877d4ncv9c.fsf@oracle.com> From: Indu Bhagat Message-ID: Date: Mon, 11 Jul 2022 13:37:20 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 In-Reply-To: <877d4ncv9c.fsf@oracle.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-ClientProxiedBy: DM6PR11CA0070.namprd11.prod.outlook.com (2603:10b6:5:14c::47) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d81eb712-270c-4923-b64b-08da637d295d X-MS-TrafficTypeDiagnostic: BYAPR10MB2454:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /Vapsc9rU83+iZFAl9YPu+E+OUkAU6Ew7D1ctCmWiijaeS8Gsk/j7bPlxsU4wCRGi46dTSMRPgceS/cW4771ZgxG8kKaydmTY7mrhe0YzopW90tMVYCuF9JMPOe53BUgHgmhQAbZuywuZP84aMieq9kbjMQA6CzmJAEV9S50JJNAdPmkQov6I2CiqzJoIIxnRXL3Nww+1mTQeuk3I1/A3Jz/Umd0hDGqwEHKDfeUaLjU1wKZwNOhoRuCYIydjKYEuRvim261bUKH8JUU4+HBfQeSxj40FxKZq6OS392kBdReXHBTKw+uqmMefjGgNiOu/EYOiNt2/wxoEJJcZMBw4uUu1cYS4Wu8O3hWGXHHzORht6IPO+9hQvVCvXyp2qfJWby5wLMXfiEdwHFhfKVHmIvE1uhYlalgAoNRLRZJAS+gQHpMjmGDOQHI9AlpLkQV000ae0ycAkYGUuKA3QTYjlWtIHpw+AU1O6vbLSZaDVa6gsLzNVG77Tun0Ez75QtSdX6bgd7aM6sV8cjpQqv1rCX45eLzyO3rk4ujxpY/CSVE9gWKA4Cdyui+SL//XActdgHT0SdxwSz5BvTP5rTqII8LxRX1vBPTGcbKHKcrrY1OW5gc8wBZtQA5eKK3isuwIFt8H45xZfqqIwcqisZ99qcr8czUExN4jJwqGX0al7kubohC/xXkQUyqc7RmbGuBxhMILWYI4gy3NQYA8AMFM54cSjvorc84QJEAFMOdfPAJV13GFZNdpy6WXwAkqg1oASENTZklgU40oyxrUvyIaNALBCOJ42koYiQUWvLo+pc9wQq1cXVebx3cwAt4+Gfy7AZXrpnkSRO1KzKAp7yUgQbznjapJ6hfGZ7pGm5MCJ1aSJI7BikBKF6hCAleuA5d 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:(13230016)(39860400002)(366004)(346002)(136003)(376002)(396003)(41300700001)(8676002)(2616005)(66946007)(66476007)(6486002)(478600001)(66556008)(966005)(6666004)(83380400001)(5660300002)(6506007)(2906002)(316002)(44832011)(8936002)(36756003)(86362001)(31696002)(6512007)(38100700002)(31686004)(53546011)(186003)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SU5OWWtKUVdKN1dCVDd2STJEbWxrbysyQm9IVjFQR1h3aHVtNHVjS0poaEt5?= =?utf-8?B?QUJWVCttTzJOcEpiak9ETHZvZG1DT0NQYjVVd1hBNTk5emtCR0s4TDhqZnFt?= =?utf-8?B?L2FrZ3RqejdJaUFRdjk5c0NTa09SU1YweDJnVEw4YzB4SUpvZl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Qk9COGlKQ1JEc2dkcC9SUzRoaDVsOUZxeXc5WFM1bVhSVGJpc0V0?= =?utf-8?B?S1JRUHphZVc4STdUVzdIV3pZSnh6bjNaeGo2NC9uR0VFU0hTT3o2OGpxaG5h?= =?utf-8?B?dFZObDRYeklMK0NMRTFlZ2pTa0x3OXJ1YSsvS2xqYlZuQnhqVUNNU0Z3SVBq?= =?utf-8?B?aHQ1ZnhzeFMydEFoR1ErRG52ZC8waU1FN2lJZEU1bTM0YXpSNGFuVlJZaStJ?= =?utf-8?B?K0E9PQ==?= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d81eb712-270c-4923-b64b-08da637d295d X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jul 2022 20:37:24.5071 (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: nKzKdZJ24/ir7Q8slIqy6wyfVUaRDub1K/1BqNi1yezXQQqa249w3mSTZ4TPNZxs/oPqLO8S5AWNU957C2tmqQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR10MB2454 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.517, 18.0.883 definitions=2022-07-11_25:2022-07-08, 2022-07-11 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 mlxlogscore=999 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2206140000 definitions=main-2207110085 X-Proofpoint-GUID: EU8RjLnJfxllFldnJbbF0OnQoH9bzUHw X-Proofpoint-ORIG-GUID: EU8RjLnJfxllFldnJbbF0OnQoH9bzUHw 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, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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 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-List-Received-Date: Mon, 11 Jul 2022 20:37:40 -0000 On 7/8/22 11:30 AM, Jose E. Marchesi via Gcc-patches wrote: > > > The kernel bpftool expects BTF_KIND_FUNC entries in BTF to include an > annotation reflecting the linkage of functions (static, global). For > whatever reason they (ab)use the `vlen' field of the BTF_KIND_FUNC entry > instead of adding a variable-part to the record like it is done with > other entry kinds. > For BTF Variables, we have the linkage information in the output section as "btv_linkage".  To propagate that information from DWARF to BTF, we have the dvd_visibility in struct ctf_dvdef (in ctfc.h). Now that the linkage information is needed for the BTF_KIND_FUNC entries, what do you think about - adding something like dtd_visibility to ctf_dtdef. Updating the BTF format documentation will be useful https://www.kernel.org/doc/Documentation/bpf/btf.rst. Let's see what can be done for that... Also, adding some testcases with the current patch will be great. I have created PR debug/106263 "BTF_KIND_FUNC type does not encode linkage" to track this. > This patch makes GCC to include this linkage info in BTF_KIND_FUNC > entries. > > Tested in bpf-unknown-none target. > > gcc/ChangeLog: > > * ctfc.h (struct ctf_itype): Add field ctti_linkage. > * ctfc.cc (ctf_add_function): Set ctti_linkage. > * dwarf2ctf.cc (gen_ctf_function_type): Pass a linkage for > function types and subprograms. > * btfout.cc (btf_asm_func_type): Emit linkage information for the > function. > --- > gcc/btfout.cc | 3 ++- > gcc/ctfc.cc | 3 ++- > gcc/ctfc.h | 3 ++- > gcc/dwarf2ctf.cc | 4 +++- > 4 files changed, 9 insertions(+), 4 deletions(-) > > diff --git a/gcc/btfout.cc b/gcc/btfout.cc > index 31af50521da..417d87cf519 100644 > --- a/gcc/btfout.cc > +++ b/gcc/btfout.cc > @@ -740,7 +740,8 @@ static void > btf_asm_func_type (ctf_dtdef_ref dtd) > { > dw2_asm_output_data (4, dtd->dtd_data.ctti_name, "btt_name"); > - dw2_asm_output_data (4, BTF_TYPE_INFO (BTF_KIND_FUNC, 0, 0), "btt_info"); > + dw2_asm_output_data (4, BTF_TYPE_INFO (BTF_KIND_FUNC, 0, > + dtd->dtd_data.ctti_linkage), "btt_info"); > dw2_asm_output_data (4, get_btf_id (dtd->dtd_data.ctti_type), "btt_type"); > } > > diff --git a/gcc/ctfc.cc b/gcc/ctfc.cc > index f24e7bff948..ad7f8bb8e86 100644 > --- a/gcc/ctfc.cc > +++ b/gcc/ctfc.cc > @@ -777,7 +777,7 @@ ctf_add_function_arg (ctf_container_ref ctfc, dw_die_ref func, > ctf_id_t > ctf_add_function (ctf_container_ref ctfc, uint32_t flag, const char * name, > const ctf_funcinfo_t * ctc, dw_die_ref die, > - bool from_global_func) > + bool from_global_func, int linkage) > { > ctf_dtdef_ref dtd; > ctf_id_t type; > @@ -792,6 +792,7 @@ ctf_add_function (ctf_container_ref ctfc, uint32_t flag, const char * name, > > dtd->from_global_func = from_global_func; > dtd->dtd_data.ctti_info = CTF_TYPE_INFO (CTF_K_FUNCTION, flag, vlen); > + dtd->dtd_data.ctti_linkage = linkage; > /* Caller must make sure CTF types for ctc->ctc_return are already added. */ > dtd->dtd_data.ctti_type = (uint32_t) ctc->ctc_return; > /* Caller must make sure CTF types for function arguments are already added > diff --git a/gcc/ctfc.h b/gcc/ctfc.h > index 001e544ef08..273997a2302 100644 > --- a/gcc/ctfc.h > +++ b/gcc/ctfc.h > @@ -116,6 +116,7 @@ typedef struct GTY (()) ctf_itype > } _u; > uint32_t ctti_lsizehi; /* High 32 bits of type size in bytes. */ > uint32_t ctti_lsizelo; /* Low 32 bits of type size in bytes. */ > + uint32_t ctti_linkage; /* Linkage info for function types. */ > } ctf_itype_t; > > #define ctti_size _u._size > @@ -423,7 +424,7 @@ extern ctf_id_t ctf_add_forward (ctf_container_ref, uint32_t, const char *, > extern ctf_id_t ctf_add_typedef (ctf_container_ref, uint32_t, const char *, > ctf_id_t, dw_die_ref); > extern ctf_id_t ctf_add_function (ctf_container_ref, uint32_t, const char *, > - const ctf_funcinfo_t *, dw_die_ref, bool); > + const ctf_funcinfo_t *, dw_die_ref, bool, int); > extern ctf_id_t ctf_add_sou (ctf_container_ref, uint32_t, const char *, > uint32_t, size_t, dw_die_ref); > > diff --git a/gcc/dwarf2ctf.cc b/gcc/dwarf2ctf.cc > index a6329ab6ee4..397100004c2 100644 > --- a/gcc/dwarf2ctf.cc > +++ b/gcc/dwarf2ctf.cc > @@ -644,6 +644,7 @@ gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, > > ctf_funcinfo_t func_info; > uint32_t num_args = 0; > + int linkage = get_AT_flag (function, DW_AT_external); > > ctf_id_t return_type_id; > ctf_id_t function_type_id; > @@ -687,7 +688,8 @@ gen_ctf_function_type (ctf_container_ref ctfc, dw_die_ref function, > function_name, > (const ctf_funcinfo_t *)&func_info, > function, > - from_global_func); > + from_global_func, > + linkage); > > /* Second pass on formals: generate the CTF types corresponding to > them and add them as CTF function args. */ >