From patchwork Tue Dec 13 18:44:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1715447 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=NPH1j8Ln; 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 4NWnVr10wrz23pD for ; Wed, 14 Dec 2022 05:45:23 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6503B387721D for ; Tue, 13 Dec 2022 18:45:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6503B387721D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670957121; bh=W4J7gIeizAAhXfflrY/7p03L/Sr4xMOVevjG00RSjVM=; 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=NPH1j8LnizMbzxMjl86dZIOkz4LXpFaRqx26NJAZvpqYytUV250mR4mY4KWCPo2L7 3TAlmHtxD+DO8RKMFj1AL720oorabpBk/utbLUYJfCov0BZGGHRhco0kuV+oGqqaxs SYMZ+qugpeVWaIS3rX7PvtM1NaetWYwyaiRw0SPw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 9FE7F3848E37 for ; Tue, 13 Dec 2022 18:44:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9FE7F3848E37 Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BDIiHPZ000427 for ; Tue, 13 Dec 2022 18:44:56 GMT Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mcgq0e7cm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Dec 2022 18:44:56 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2BDI0M2B006615 for ; Tue, 13 Dec 2022 18:44:55 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3mcgj68y2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Dec 2022 18:44:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k8IXc1ONNSEjKs8VK1OBEQS/9mZ3QXd8z1ShSoNEGABUqzL/TvPxG7zs8utZDgsnsMPrrpeiSIekaTl5889N9eptNMXi5ES1GiUruBQx9GukgVz5gFSgKvJPekAHY6jpWDGRFsKLI/AI06k72JMh+88WmwUSJC/aU9U/CkYYZbGzaLFctYaRxwRUDhNiUFzFX0TtX0AvbDb52ZimojtktRw6yXy82Dsxo1oJAtLkTesk/sGzy7GySzMmhFqW0hqRAa35JH4k/R0r9tHS5OLvCtRXUEcpU2roBRDfN8UV1Jijr3DIo1DRfNe8I5GPRT9WtjQDV2WLQDtGNSL8NifgJw== 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=W4J7gIeizAAhXfflrY/7p03L/Sr4xMOVevjG00RSjVM=; b=INrWdoB9FDh5qBV3qLp6YD/6kORIX05Xg7EEaaHRA0tvpxJ702Zwui2tN7XDZBdFi/mTaWscIOq/pPKSASufu+WdH7jXfKIOW9tMNjwH2D7dYnjXXTidMEs+YUO9HBuSnXdDPGu8pEmWc5NhumVwYWXxkI+r4izVW6XviOQyo2AK1M2ZmHk9+ceudVJ3F4vK6TOkRjayF9mGNyu87nhHXB+4GSnJ984V/kJxHJ9yXOfOg87Ue04o7Ms5jO+tRhKmtZpnwxfJThyyXOUZBgAjW90CQW40Ye10SVPBtfrRzBsAuaGzTGQsYTiTIwyedb5p6XBQHQxd10DV/+57obWeXQ== 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:44:53 +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:44:53 +0000 To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com Subject: [PATCH v2 1/3] btf: add 'extern' linkage for variables [PR106773] Date: Tue, 13 Dec 2022 10:44:24 -0800 Message-Id: <20221213184426.8861-2-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: SJ0PR05CA0107.namprd05.prod.outlook.com (2603:10b6:a03:334::22) 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: e115277e-6d77-412e-af51-08dadd3a1f40 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I1vvkcZMCmuEHZI5Bn7NnpXYN72UDgG5iBD7MITPKmhXNYMMsUOJf8r2GuLOytKEFPW45u5kHC1k3ii2Zd+abBtdhc32iwdzzHI82L6G56g2eh83GK3IXXV2vHQLCi1C1tGzcD0YxPofiovHsGKMKi73mXgoZVi594CC7kge9KhGMewpSCdZPADkPG3hTsv9eHCotNXwLK3i7sK/hP7DmHN+tKWJsPUH9UXhP8WQvQNzdqMTfrvHZcQvlNPGo69/SXvl1q4W1BOSzTFsyJlJG8ukh4/j+HP+2EY1EcP60SoTzYA51Pmx/k0i4eKsZmJBUgH8srmOjaKBUSV2YhrK7SlwY2TQV/YCjLxap2fLqN4ZpW5pIcxqZr9PNcx+qdJBwMhCD0ffHVA5IMn7CzBPDqw/WgbhoSZ9tcleasTnW45qKYXcQOqLYsoV9HTRTAW3suF++9ij4Z9jSUEGFHXMYL8jcdj9DW1/pTDfx2iFrkmGhEO0ksdUD3/TjLBfXPymlz6wzHU02IO5sSR9nSRqEyKXbiNnj2fTGpWJA6FLznJxLXLe6CwmkUUNqx2JxCABmomRrk5l1XmPQYj1Bn1e2Wecw03fF9wIp7x4TyxLOhrIDz3zWe/hnoFHAULDKZkT77tJ/AT6TJ//dfssueiFIN9rtWGbae6HGDqoreW6v0JTJvAeDhLul79pUhfFiH+Ub8LAItwUEO+GIGgn0sId4w== 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: a4LqTQmc0ZWYBoOeVxap1pKDAJtwuXtve3HgSI4FjQwYLu5/LR3O6EWVguDrWhceyWfxV9o6nKlyYE3GE+Pr5Z/Om5L6On0RvllA602MSv6wGnsDkudu0ixCJC36pjnf3bTfDo9f/alymooVeNN9IXeW0ALMorYCd5Bi3HZZZSdVZMstAstn+SfQADEvW67XawO6gzVia6nZ3TX1LeeZJJ06wVVL0K8MhoVTGA18S/p/eNUK0tSxej+QbTGC/nXDCVgN0PHs1tYkaMV5M+MnDXSBMXzrNtiibjiA6H+Vo5EtMnSLaGIm/qOCH/7eP4Pn7ZtcIwvGLw4+tNKAcyTVpOkEb9TvAZeVQighVeEtghDMHveCExi8YxdutIRQOLMixSLXsLgtNxGMu5UzWAFAtVM5vjoaYXJ4q9Zwuxzzr2GlSLOZ4yJvRwyJJJrbJvUoCFQuCO1ajujYZSzmEBroqRd2qVUo78p50kmfoVfTVNzTuCxW92MBOlDHQVtZEBc8aBok2fxi8xHNVv6dK3wN5vWUIuDkDbOKPQu0IGDPVK1JzJ71FooLKkM45ATkbyLFGaAYc7yNAgIxelLfhcI5n3iX+Eat6a10Da9lSn3p6nvzZVhCXKSWwTsxlXBHSIQtYtcS/jkkLapDOWra5nPYXSCnIliUbwXUHrsPHMRakYUsgXKIRxl2t5j6OSvQIrXX5ox+T68WCgHRSwXyxfdlMS72a/h4Lzzz6K8tHBasfayo+esf/09/4mYvAX5/yABR16g6cX5ZVlkt3b1kBxsnDiGI1zzmcrIXEWvhxEyOKSRneFAkVurgXuQg0WIQIah4/o4QI29O/RTUS2ITE/vO3u3qxyFkcED/bC/CVmnTkrPuk/cXEwWuMWctjqbRm6WMhMF9yn974Xe/lu7DlpwwJvbidFQLKa8GTXJz0ujw6BYLNJSRo5xNr1ASqZgSZ6sXDC4Y/SnkmuYDTARzeRrdbB0ZFqG17RMu/zIb9oIYeF5ktk+MC5AQFTE44soXY3cs2SDp+nKiD56vjTPrkjXgkKkOKSOJQ9OMS2YvyGujcJan2m2rOiFyyDqUqRUz1xW1gVZLsdszRHDuvb2FweWZk8FmdelazkPfTKGMsEWJlxW1bzdfcmz0Hi8AP6DEk4e8Oj3Wx5zJYyYV9cmoYq5QS2gelegzspCT3AtlytsKtmT0pYt5TMbPBV8LCi+kreLGy8IaA+3dxrC79io1+CGYHkR9Ame9CuosbK/LqBFPq0U/2Okr9pXHxsIkDCfY/p+xYio/PGvRfY48r50WLIYxfyRB9uekQz866Lu1dkD3j9lbm2n/Sb9NlgjZ4NQLvF4Fusg2++Z95MWkGbOMsaJhZqduvyd+zOoqBfn0ezxflAUed3GCJOlB3AH2prMjIpcUyEdN0TC/WGiK7ZdK+Pt38/CtFrAKaZ6Dk4rgMCmX8JJVB7SgDucAlJVpOauli0XSxGt6v5RohCGhNJMWiT42orS6F/WCL9UjNrtOTCYzdlPcZyHqRV66q1c8XcvVkB6tDHEEBAGQKBbl6Wr+Nl0uunxmy8HgcuWSmS0XeVwDMHJUwAE6v1kD7WHsF6n8dc0b X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e115277e-6d77-412e-af51-08dadd3a1f40 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:44:53.0239 (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: Ty+kPF+d0oVOk75J5tlB+DLku1lWm/zOuuWXnPKYGlDBuWNTqxAAvw85bQ1TaIREdr4e/iwelFm1XewLsTzYVw== 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 suspectscore=0 spamscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212130164 X-Proofpoint-ORIG-GUID: lCKeFLeWhI9USsTD2V7PfbOaupkEem-_ X-Proofpoint-GUID: lCKeFLeWhI9USsTD2V7PfbOaupkEem-_ 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" [Changes from v1: - Add enum btf_var_linkage in include/btf.h and use that instead of local #defines. - Fix BTF generation for extern variable with both non-defining and defining decls in the same CU. Add a test for this. ] Add support for the 'extern' linkage value for BTF_KIND_VAR records, which is used for variables declared as extern in the source file. This also fixes a bug with BTF generation for extern variables which have both a non-defining declaration and a defining declaration in the same CU. PR target/106773 gcc/ * btfout.cc (btf_collect_datasec): Mark extern variables as such. (btf_dvd_emit_preprocess_cb): Skip non-defining extern variable decl if there is a defining decl for the same variable. (btf_asm_varent): Accomodate 'extern' linkage. gcc/testsuite/ * gcc.dg/debug/btf/btf-variables-4.c: New test. * gcc.dg/debug/btf/btf-variables-5.c: New test. include/ * btf.h (enum btf_var_linkage): New. (struct btf_var): Update comment to note 'extern' linkage. --- gcc/btfout.cc | 11 ++++++++- .../gcc.dg/debug/btf/btf-variables-4.c | 24 +++++++++++++++++++ .../gcc.dg/debug/btf/btf-variables-5.c | 19 +++++++++++++++ include/btf.h | 11 ++++++++- 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-variables-4.c create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c diff --git a/gcc/btfout.cc b/gcc/btfout.cc index aef9fd70a28..677e8324424 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -314,6 +314,9 @@ btf_collect_datasec (ctf_container_ref ctfc) continue; const char *section_name = node->get_section (); + /* Mark extern variables. */ + if (DECL_EXTERNAL (node->decl)) + dvd->dvd_visibility = BTF_VAR_GLOBAL_EXTERN; if (section_name == NULL) { @@ -431,6 +434,12 @@ btf_dvd_emit_preprocess_cb (ctf_dvdef_ref *slot, ctf_container_ref arg_ctfc) { ctf_dvdef_ref var = (ctf_dvdef_ref) * slot; + /* If this is an extern variable declaration with a defining declaration + later, skip it so that only the defining declaration is emitted. + This is the same case, fix and reasoning as in CTF; see PR105089. */ + if (ctf_dvd_ignore_lookup (arg_ctfc, var->dvd_key)) + return 1; + /* Do not add variables which refer to unsupported types. */ if (btf_removed_type_p (var->dvd_type)) return 1; @@ -676,7 +685,7 @@ btf_asm_varent (ctf_dvdef_ref var) dw2_asm_output_data (4, var->dvd_name_offset, "btv_name"); dw2_asm_output_data (4, BTF_TYPE_INFO (BTF_KIND_VAR, 0, 0), "btv_info"); dw2_asm_output_data (4, get_btf_id (var->dvd_type), "btv_type"); - dw2_asm_output_data (4, (var->dvd_visibility ? 1 : 0), "btv_linkage"); + dw2_asm_output_data (4, var->dvd_visibility, "btv_linkage"); } /* Asm'out a member description following a BTF_KIND_STRUCT or diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-variables-4.c b/gcc/testsuite/gcc.dg/debug/btf/btf-variables-4.c new file mode 100644 index 00000000000..d77600bae1c --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-variables-4.c @@ -0,0 +1,24 @@ +/* Test BTF generation for extern variables. */ + +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +/* Expect 4 variables. */ +/* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t \]+\[^\n\]*btv_info" 4 } } */ + +/* 2 extern, 1 global, 1 static. */ +/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*btv_linkage" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0x1\[\t \]+\[^\n\]*btv_linkage" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0x2\[\t \]+\[^\n\]*btv_linkage" 2 } } */ + +extern int a; +extern const int b; +int c; +static const int d = 5; + +int foo (int x) +{ + c = a + b + x; + + return c + d; +} diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c b/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c new file mode 100644 index 00000000000..8aae76cacab --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-variables-5.c @@ -0,0 +1,19 @@ +/* Test BTF generation for extern variable with both non-defining and + defining declarations. + + In this case, only a single variable record should be emitted, + with 'global' linkage. However two array types will be generated. */ + +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +/* Expect 1 variable with global (1) linkage. */ +/* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t \]+\[^\n\]*btv_info" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0x1\[\t \]+\[^\n\]*btv_linkage" 1 } } */ + +/* Expect 2 array types, one of which is unsized. */ +/* { dg-final { scan-assembler-times "\[\t \]0x4\[\t \]+\[^\n\]*bta_nelems" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*bta_nelems" 1 } } */ + +extern const char FOO[]; +const char FOO[] = "foo"; diff --git a/include/btf.h b/include/btf.h index eba67f9d599..da621353aa1 100644 --- a/include/btf.h +++ b/include/btf.h @@ -178,11 +178,20 @@ struct btf_param uint32_t type; /* Type of parameter. */ }; +/* BTF_KIND_VAR records encode linkage information in a single + trailing struct btf_var. These are the supported values. */ +enum btf_var_linkage +{ + BTF_VAR_STATIC = 0, + BTF_VAR_GLOBAL_ALLOCATED = 1, + BTF_VAR_GLOBAL_EXTERN = 2, +}; + /* BTF_KIND_VAR is followed by a single struct btf_var, which describes information about the variable. */ struct btf_var { - uint32_t linkage; /* Currently only 0=static or 1=global. */ + uint32_t linkage; /* 0=static, 1=global, 2=extern. */ }; /* BTF_KIND_DATASEC is followed by VLEN struct btf_var_secinfo entries, From patchwork Tue Dec 13 18:44:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1715448 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=VXKdUfmE; 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 4NWnVv1S7Pz23pD for ; Wed, 14 Dec 2022 05:45:27 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 283CB387720C for ; Tue, 13 Dec 2022 18:45:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 283CB387720C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670957125; bh=ys+CVKcfPX0WFeALBHE2JIx/MrGyjSkzcxtujfnpZq0=; 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=VXKdUfmE7TSUcPoIlKl5YbKp0No9cB5K5DwCf5ZOCdtWE7c6wfvhbaXWEAeOfK1qC MSPxjfE8XCI4eamG4DucmTevTYBp4xlQsa+M04TLqd5av1O++PYDlgwmP3u6BuvxKG b0RBhuL0xbias1NNe+T01NjkYL97OgJslI3+c1Fk= 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 5D37D384D3DB for ; Tue, 13 Dec 2022 18:45:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5D37D384D3DB Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BDIho7g019013 for ; Tue, 13 Dec 2022 18:45:01 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 3mcgw2e66n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Dec 2022 18:45: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 2BDI6Nk2039967 for ; Tue, 13 Dec 2022 18:45:00 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2102.outbound.protection.outlook.com [104.47.55.102]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3mcgjctsmu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 13 Dec 2022 18:44:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HX8CXBW2QUJWIzjd5beLk+edG1FaEAGTtfKCm0HnSn81OFxgQO63ff7FZhwlirvCwWUM39BzlNTFciGTRApL1uugFHNFKp+ZS4+fv1H7wt1wX87l6yLlB/hXWGO+MuM6SC9K3SMSgdDQUrN1LeG3Zowpmn1DtxSF3plqPCz5So7NZWKAvylCmu/y2P4913UZ4uqIrsN76WutFRbq/8qC3JUP2bS4gEUOgTgpxQ25Fm5mYxiQTARBty11f3cdXEqlrhRlU53ZK6HuiC7C6lXdxF9lg7pwAHelKNG37dc66fPWlmEP8QboPE4xUZl9oLSd0zhsgWL6E27dXAMu+MUCEw== 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=ys+CVKcfPX0WFeALBHE2JIx/MrGyjSkzcxtujfnpZq0=; b=HZn47Uzw+cNR64yebfR1AHB8tYinm96y9H5eKXIJN88pLMxU7wlaCREzKtqV61V447C4P6BkLllOFGs20oawZSRcxgQwn6h5b8rh54gVrAu0Ck5MG+QeqkzFa31tY3I/ifrX9SM+SEcJCC1YBRMOV82pgSNA9hFpyTjqKoZDxYQuklC8ORG5zPrUXaKlYeEbz6TqkQWpYdJ0etCipwFWQpq/uuYWZ+7RZYIYvivZ3aM8ojeV8W7l1RCfcNkZeaxeQvHI3UG7BlovCz4z04Ww12TpIO1tf5bc6gTSjC918cRv0MNkFzwWFesYq29DotmP3rTi7HW50pDoiFbMnIK2OQ== 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:44:57 +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:44:57 +0000 To: gcc-patches@gcc.gnu.org Cc: indu.bhagat@oracle.com Subject: [PATCH v2 2/3] btf: fix 'extern const void' variables [PR106773] Date: Tue, 13 Dec 2022 10:44:25 -0800 Message-Id: <20221213184426.8861-3-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: BYAPR01CA0063.prod.exchangelabs.com (2603:10b6:a03:94::40) 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: d090a471-97e2-499d-953e-08dadd3a21fd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eT7yNpZbs40XyqBCFDHd1OSrukO7skVlT8EZEZiTDMw58XRKQIHccNNiG/nR55jvQsUcrIn3koreMMgGEcOjqJGrZSS0wYL0Iz61yVwtRkCG3aH2zvDqYqh/lgbBy8zGcsybsP3jX3Kyd9m/NED7sJbKP1KPyvdlxkMhO5wKLON3oQUCoIDUXlw6lUU/H3vAhWV+E9jgDYKtA57Zb2u6dr4Amlz7ALBupRq4hiUWs7P/QqU8x92wBSHmCgQkbHOiRDyDCdOr5a1dnYiV/C1lE93N2v/NIDHgPgmGbW93Gvi5fXmQwauMTAMPOCF9P97WCnERb7wOx6oy91k+pAJYEnASTXMPeq3M8fKc5dSerWpoDnRzv4Paw7cfH1qd1iLf2tDXtI8OuxG/xiCTfnZ9Rf3j8rIXXuUFSpYWKmBVEDoced93m1rzm0rEqx4jHCOYnfqqGeLPKPlDYqBg6e/NXx3+pLqSke2VvuIKySDaLl0KofTvu7C3DjebAHJe2mnT6I7uiktLCl6OT1AR2+nw/t9LKjgJuloNzXnMApdl8rwXLIIJPf1+N4I6VNashn3DVm0NXRrv5wlp8pZJ3LF7gkBkewLFgKTu8jqT2jGLiWPii4r4DYHdYTsg1hQidqn6bAwq5/dWmB79k/kBb23X4+FBzu/sunT1pTKHccUKIq4= 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: cGRZ8x8g36gvyMsOGbY3EndgxL13zM7mBa/BjbWt1U4oMswG93mOCqeYQ6sfwXzKsz3QeIIYxM3xL/pnRt+0oCO5YqP9DUDp65Q2QJxUL6FSPRFpUmlZYf3Fa0j7q3aFtN97rRKstGb28xroqH30fZCRjevIGCcFr5tozMVY9AA3cLPmqUqdH+KstBGYCWg5e3yxJz0tMJL5Tt/Em7LHqIyU+AFIdS+zTJ3QB+RCQ3LPl8cmuiHPKHHnbZQv4/scKHGcyQffem1hnX+0DpIgIpWsXuez+p6H42G54ON7jU3W71TpQ1WCoAIQuz1fVXMvz8qcc+5XiOKDOh95pTqQLZV3l61Ih8F+2/2CdnUmCaVytCMy6Ek0Quo1p90LhofLJQMLarJZY059YjRf/nMTFWhx4xxRzbY/h1pxtXcmqJIB8utMy8lIgU3TUp4+DVdQaAZzMuDp/sLWUFDwzZHWsDxenV3OODrqMg5NaDNkWssdzG5QF1KzpfWrWn13yB6JTQ7j+LlUQb4nD/XP7IBE2dcbbc5sqltXM86XPqrGzWjYJD1OnDkvWA3z7Y4Z8PnWa4pluCgiO0ykDKNJLFPD7uxarWzHPqRrY8nrrlh/V0kUekPQNEovpEWQxKrz73j+ekHMhdDvb2mdeh0KnR3II3VdolP2lj7FtzowZhI8gWUzLxfo67NsylC57vDLVS3Z24uJl+VH0ENn0RaWzUVLR2jVx8JZfCJu471yCY6XpAQeTIX3jc1jhNiVCfBNQYHIv3KyTx86WAWqMjAjhH/zscarAJw6g6w49iCsl7KLDd6VsguZZnj4pEn09apEFF6kA5hAEgLPs0qX/+l5ir4YmSGBEDNmYvAlV/mujTSG7cEpjdsjIUKbdK3vbnsTb0iTljtKIWa57GTsu9yH5MfV9KpQj5bCIRe1FliKrADutfQJRdRAA+YgWwoYcBTMeazp9qiILSv/gox0THnq/4KAYAYeVGfU/1dsO1O46+u34rsImQc9l21lIrUKaQiYvNX3Uf8NMOI2NqqVF9r/H4twiT/icm+KeMe0fm56L/aQdjzsl4V6oWnThZmdwG+OKcMhCbAhfp9FjI10P4HYaRka/qeCnsfzTlRjIBsT556PmiQ/qK7VGsobk20H6B9+YIB7BmXBNg5sELxr2WTGhJLK4vXnUekUUoylNzFVfxT+m6nPONP0ych5p1fyUQDYJBiGqpZD9w89JFl8+w1I4KmpiVxeCgZB88s5ZD52OQFo7jyfwHvYca69yzhhSCMz4sP/F+QJrqMUfVWhvU1ATaUJ1JdkmohcRXYUqvja6xvgS62iTziZBb0fEC5CP4yTWZ7LLWMR4ceL1RvXqo7EzqIewF/o/VwaFRtMI2igANdjmyXwRuA38zp2Etb1R5n/HK0l1eYsY47kEaS//MDK21uTgSPY/i2fFCKP/zXkUbjCtqGgx6/gdOJHdUucWWL3ZLiOYQK2zSyZkxb97zlMfGid7pI1QX/s0sj4o8a2RGWizwp3Mni2SJ8vfITADv308Z+aqtqou24BMsXHOAOo7yBvS5Y6QFYXpEGlWiAwJNxP7I2ql1d2t1Ci0/TivHQGrtNm X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d090a471-97e2-499d-953e-08dadd3a21fd 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:44:57.7267 (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: HJgUkmLvVixsnKz+sn9rMb0Wc5A0OfF4l9A9Gpq6EIiR9CNSfhFBhSrWUeIezWdj83OD0mx7USgiOTPsONrsRQ== 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-ORIG-GUID: -lV652P4KzYt9HjSE99-hwqN7fNo5AI7 X-Proofpoint-GUID: -lV652P4KzYt9HjSE99-hwqN7fNo5AI7 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: Minor updates to comments per review. ] The eBPF loader expects to find BTF_KIND_VAR records for references to extern const void symbols. We were mistakenly identifing these as unsupported types, and as a result skipping emitting VAR records for them. In addition, the internal DWARF representation from which BTF is produced does not generate 'const' modifier DIEs for the void type, which meant in BTF the 'const' qualifier was dropped for 'extern const void' variables. This patch also adds support for generating a const void type in BTF to correct emission for these variables. PR target/106773 gcc/ * btfout.cc (btf_collect_datasec): Correct size of void entries. (btf_dvd_emit_preprocess_cb): Do not skip emitting variables which refer to void types. (btf_init_postprocess): Create 'const void' type record if needed and adjust variables to refer to it as appropriate. gcc/testsuite/ * gcc.dg/debug/btf/btf-pr106773.c: New test. --- gcc/btfout.cc | 44 +++++++++++++++++-- gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c | 25 +++++++++++ 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c diff --git a/gcc/btfout.cc b/gcc/btfout.cc index 677e8324424..204b11d4e9f 100644 --- a/gcc/btfout.cc +++ b/gcc/btfout.cc @@ -350,6 +350,8 @@ btf_collect_datasec (ctf_container_ref ctfc) tree size = DECL_SIZE_UNIT (node->decl); if (tree_fits_uhwi_p (size)) info.size = tree_to_uhwi (size); + else if (VOID_TYPE_P (TREE_TYPE (node->decl))) + info.size = 1; /* Offset is left as 0 at compile time, to be filled in by loaders such as libbpf. */ @@ -441,7 +443,7 @@ btf_dvd_emit_preprocess_cb (ctf_dvdef_ref *slot, ctf_container_ref arg_ctfc) return 1; /* Do not add variables which refer to unsupported types. */ - if (btf_removed_type_p (var->dvd_type)) + if (!voids.contains (var->dvd_type) && btf_removed_type_p (var->dvd_type)) return 1; arg_ctfc->ctfc_vars_list[num_vars_added] = var; @@ -1075,15 +1077,49 @@ btf_init_postprocess (void) { ctf_container_ref tu_ctfc = ctf_get_tu_ctfc (); - size_t i; - size_t num_ctf_types = tu_ctfc->ctfc_types->elements (); - holes.create (0); voids.create (0); num_types_added = 0; num_types_created = 0; + /* Workaround for 'const void' variables. These variables are sometimes used + in eBPF programs to address kernel symbols. DWARF does not generate const + qualifier on void type, so we would incorrectly emit these variables + without the const qualifier. + Unfortunately we need the TREE node to know it was const, and we need + to create the const modifier type (if needed) now, before making the types + list. So we can't avoid iterating with FOR_EACH_VARIABLE here, and then + again when creating the DATASEC entries. */ + ctf_id_t constvoid_id = CTF_NULL_TYPEID; + varpool_node *var; + FOR_EACH_VARIABLE (var) + { + if (!var->decl) + continue; + + tree type = TREE_TYPE (var->decl); + if (type && VOID_TYPE_P (type) && TYPE_READONLY (type)) + { + dw_die_ref die = lookup_decl_die (var->decl); + if (die == NULL) + continue; + + ctf_dvdef_ref dvd = ctf_dvd_lookup (tu_ctfc, die); + if (dvd == NULL) + continue; + + /* Create the 'const' modifier type for void. */ + if (constvoid_id == CTF_NULL_TYPEID) + constvoid_id = ctf_add_reftype (tu_ctfc, CTF_ADD_ROOT, + dvd->dvd_type, CTF_K_CONST, NULL); + dvd->dvd_type = constvoid_id; + } + } + + size_t i; + size_t num_ctf_types = tu_ctfc->ctfc_types->elements (); + if (num_ctf_types) { init_btf_id_map (num_ctf_types + 1); diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c b/gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c new file mode 100644 index 00000000000..f90fa773a4b --- /dev/null +++ b/gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c @@ -0,0 +1,25 @@ +/* Test BTF generation for extern const void symbols. + BTF_KIND_VAR records should be emitted for such symbols if they are used, + as well as a corresponding entry in the appropriate DATASEC record. */ + +/* { dg-do compile } */ +/* { dg-options "-O0 -gbtf -dA" } */ + +/* Expect 1 variable record only for foo, with 'extern' (2) linkage. */ +/* { dg-final { scan-assembler-times "\[\t \]0xe000000\[\t \]+\[^\n\]*btv_info" 1 } } */ +/* { dg-final { scan-assembler-times "\[\t \]0x2\[\t \]+\[^\n\]*btv_linkage" 1 } } */ + +/* { dg-final { scan-assembler-times "ascii \"foo.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */ + +/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bts_offset" 1 } } */ +/* { dg-final { scan-assembler-times "1\[\t \]+\[^\n\]*bts_size" 1 } } */ + +extern const void foo __attribute__((weak)) __attribute__((section (".ksyms"))); +extern const void bar __attribute__((weak)) __attribute__((section (".ksyms"))); + +unsigned long func () { + unsigned long x = (unsigned long) &foo; + + return x; +} + 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,