From patchwork Thu Aug 5 00:50:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 1513668 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: 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=WNOF8Tn4; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Gg96G38XXz9sRR for ; Thu, 5 Aug 2021 10:51:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 58DC03858424 for ; Thu, 5 Aug 2021 00:51:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58DC03858424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1628124688; bh=1MA4+guoLyYOyNooaASN4HYP5lY27x+ytauiYM7uS+8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WNOF8Tn48OSB0p9PBjWNr25338IRvFvVE656U+9ssfyv+Dj+4j6yrq3FN7w3eDd4y OzgNgb/5oPhY1lw7I74iObmdW2yQt5OH+r2qs1vRdZW98RKWt4QLn/H8/uKt5y3MVX 5pKZILqqb5Qsf4RdvJgryZ3AeucvTo1lVwSK+NtM= 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 C31D33858424 for ; Thu, 5 Aug 2021 00:50:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C31D33858424 Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 1750fPZ9001758 for ; Thu, 5 Aug 2021 00:50:41 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3a7cxn30qg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Aug 2021 00:50:41 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 1750oAFP189052 for ; Thu, 5 Aug 2021 00:50:40 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by aserp3030.oracle.com with ESMTP id 3a78d7nnn4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 05 Aug 2021 00:50:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KrabV2ivVCL5yOQ9l7wyOiPUMO33qeZJ8qTU08OVNyWA8ze80Bk3pIROzWL27qFefATtzG6oRaRdpuJAI12OtqtQdRgUscRAstmuvAD/Fsd3DHo+APfZQLloML0zRyWEa4F6Pt7/Ch1StVT+3BBkJu6koRMgYvsG1T0LjprDQ7yka79PfImkWn3PLRAdsV52ggPBEx8ybnrBbnWs7bnftoLLM3+wTh7GLzy2XztL+ptMUjpaMS+4YbbAYZC6Q0jwq5YyiYqleHhrGksz5I+Bxf0JOIYXiIsxAmxkuAWgbYfK32PUdaVkvbqX/2q32Yu1bLn+P/llvHM/rrS/XIhWzw== 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-SenderADCheck; bh=1MA4+guoLyYOyNooaASN4HYP5lY27x+ytauiYM7uS+8=; b=My4A9c7oUhuoVVoF3jcyg6AOKclEnlpFO4Ec23JNYcjKetmy91MZ4xegfFEVpusIKXkTsHN10lo5rJle6DGM9nihFliFWXwX1Y2vBTDT+aH3UUAfu9y5KpL2YOyQ2y93crsTd26XAX43WWOASKuCuHITIVDseH71iHycMqGGs3B1mt98lDSYSF/s6N2Svvm0Y2/rw0XNNu2xNiHuiD6VxiAaJQubV2pjWX47qEqL58FSVHIUq3VRGDGb0mhwiNGXDKs6g1JkFLMfd4WDOvgjXJgXnnvmqwvM2P4STRzuYb4i9aEsi7GOqiuPk7a9M9zQ80wOpB/hDAza0HPQcTCKjQ== 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 MWHPR10MB1887.namprd10.prod.outlook.com (2603:10b6:300:10b::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.16; Thu, 5 Aug 2021 00:50:38 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::c9ba:5127:fa3f:45cb]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::c9ba:5127:fa3f:45cb%4]) with mapi id 15.20.4373.026; Thu, 5 Aug 2021 00:50:38 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH,V2 0/3] Allow means for late BTF generation for BPF CO-RE Date: Wed, 4 Aug 2021 17:50:25 -0700 Message-Id: <1628124628-28706-1-git-send-email-indu.bhagat@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-ClientProxiedBy: MWHPR20CA0001.namprd20.prod.outlook.com (2603:10b6:300:13d::11) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from ibhagatpc.hitronhub.home (24.80.24.133) by MWHPR20CA0001.namprd20.prod.outlook.com (2603:10b6:300:13d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Thu, 5 Aug 2021 00:50:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eade786d-5525-420f-8ea0-08d957ab0ad3 X-MS-TrafficTypeDiagnostic: MWHPR10MB1887: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mQkT/UcIuiAtNASt2k4+8fno7WyQnn+WDnLoXC+N6hNm15nlFi9jw/qyr1pB72TQfmFORZNZQrelQDvJg1msDkMh2uymyB1erT9E6fN4TeYmNJjssYYuTwc/DbNzRUoidl7umyOn5IWWa286W957pfw5y431W6e261TWz7QUfz9PzTye5qjN/yOmw/iN7OBrtehP3lMEJaaJ0g0ftE1Ad3COWNzQGGsiMEAu3s8PG2AYI6gWuY4d3lPLvuQVgNYRDWcdRJqN+OhujPI4m9LNePaf2MZSYF2vxbITZYw5VQpeUp++ZD6VxC9l+rZ+OPhuw3ZkxTZyD40JFOVmRPZLiGGq1epH/IPg0zoxDwf4X9ObXmh4ZmoPiR6ta+47K0U9eowgqPD+18OtXIyQzpd2qTLCx9FYMS7517168iP7jAJxC7XXcsiYSnLnH58EjglkMJraGZkGJbscq9/71b3YH2yKVnRQNDgdSXv018t8RXYixCsYlSerbjokhQ/o+Q8IgqS8PyInIRhxAjzwcnUl/NdooOpTEGMbyoWHoGsNDCahQtgRIa+4G/0KKQfpaDGoD/yhq5cLPmcokg43wuMcPJ2Oy3w54oqZNuwtMvgQ0VBbWw/P2BvTSZ7JaJ9hzaQepxOmWy+YpYK0YJaplng86NbEISyC2E3/LpRMawXKUnFdMSOdL4sT/ShrN4yPNPPsRncs/Ham9YKtTrs8KSoBQk96xRqqUu9nb+sDPqyn/g0W8DhoFNfoM2C1l/DwlqmXMIzieALszVCXOSK+SNhDumXlIh0ja+BwaOxN2MXNqwUDuOMJg6btlvKKGvKRDyyD71U8zVPe4KJkcvmG1lUx/JzvXWnePL/IDZ0H/o8c73E= 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:(376002)(136003)(366004)(346002)(396003)(39860400002)(966005)(6666004)(66946007)(86362001)(66556008)(66476007)(956004)(2616005)(5660300002)(83380400001)(38350700002)(478600001)(38100700002)(36756003)(6512007)(6916009)(8936002)(52116002)(6486002)(26005)(8676002)(6506007)(44832011)(2906002)(186003)(316002)(21314003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZNOnZhiBKNwrVZ5VbDKzX9AkUjzatx2JZaRYzOiDRC+50Bc378xbkQ7Pr1w9jsHhidZDM7U32gD46QNeJbzxaSoFb52PIwFd/514PHm5nJ+hABozoQY+jvMPcSJNqokT0CVphKWBjy5bTlzjc2ACrWUrg6qZp20vGr9gVxiM2zCeRw1A5FMVz4VVTs1c3qwI0vWRI6Qfgl/i6K73odXStymVrzTHeMRtzBy+eyK5sQLJTNyl8DisgIDZRYO+42HxMOQ42RCqefI5qJ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hbtB X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eade786d-5525-420f-8ea0-08d957ab0ad3 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2021 00:50:38.3396 (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: nTkVEFmf26eVamfE1zwS7Xl9l0cKk24VprqASNEQdxitrtxRVUV610771OFOxEmgmq5ZeB3P7eaAeOfFqMlb7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR10MB1887 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=10066 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108050005 X-Proofpoint-GUID: yrb9Ve7mfVXt_89bS3GkkBLvA8RKIoGF X-Proofpoint-ORIG-GUID: yrb9Ve7mfVXt_89bS3GkkBLvA8RKIoGF X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Indu Bhagat via Gcc-patches From: Indu Bhagat Reply-To: Indu Bhagat Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" [Changes from V1] - [1/3] bpf: Add new -mcore option for BPF CO-RE Moved the testcase from gcc.dg/debug/btf/ to gcc.target/bpf/. Adjusted the testcase a bit. - targhooks: New target hook for CTF/BTF debug info emission (Same as V1) - dwarf2out: Emit BTF in dwarf2out_finish for BPF CO-RE usecase Moved the call to ctf_debug_finish (in dwarf2out_finish) before the point of early exit taken when dwarf_debuginfo_p () is false. [End of Changes from V1] Hello, This patch series puts the framework in place for late BTF generation (in dwarf2out_finish). This is needed for the landing of BPF CO-RE support in GCC, patches for which were posted recently https://gcc.gnu.org/pipermail/gcc-patches/2021-August/576719.html. BPF's Compile Once - Run Everywhere (CO-RE) feature is used to make a compiled BPF program portable across kernel versions, all this without the need to recompile the BPF program. A key part of BPF CO-RE capability is the BTF debug info generated for them. A traditional BPF program (non CO-RE) will have a .BTF section which contains the type information in the BTF debug format. In case of CO-RE, however, an additional section .BTF.ext section is generated. The .BTF.ext section contains the CO-RE relocations. A BPF loader will use the .BTF.ext section along with the associated .BTF.ext section to adjust some references in the instructions of program to ensure it is compatible with the required kernel version / headers. Roughly, each CO-RE relocation record will contain the following info - offset of BPF instruction to be patched - the BTF ID of the data structure being accessed by the instruction, and - an offset to the BTF string which encodes a series of field accesses to retrieve the field of interest in the instruction. High-level design ----------------- - The CTF container is populated with the compiler-internal representation for the "type information" at dwarf2out_early_finish time. - In case of CO-RE compilation, the information needed to generate .BTF.ext section is added by the BPF backend to the CTF container (CTFC) at XXX time. This introduces challenges in having LTO support for CO-RE - CO-RE relocations can only be generated late, much like late DWARF. - Combining late and early BTF is not being done as the patch set disables LTO to be used together with CO-RE for the BPF target. - A new target hook is added for the CTFC (CTF Container) to know whether early emission of CTF/BTF is allowed for the target. Testing Notes ------------ - Bootstrapped and reg tested on x86_64 - make all-gcc for --target=bpf-unknown-none; tested ctf.exp, btf.exp and bpf.exp Thanks, Indu Bhagat (3): bpf: Add new -mcore option for BPF CO-RE targhooks: New target hook for CTF/BTF debug info emission dwarf2out: Emit BTF in dwarf2out_finish for BPF CO-RE usecase gcc/config/bpf/bpf.c | 29 ++++++++++++++++ gcc/config/bpf/bpf.opt | 4 +++ gcc/doc/tm.texi | 6 ++++ gcc/doc/tm.texi.in | 2 ++ gcc/dwarf2ctf.c | 55 ++++++++++++++++++++++++------- gcc/dwarf2ctf.h | 4 ++- gcc/dwarf2out.c | 9 +++-- gcc/target.def | 10 ++++++ gcc/targhooks.c | 6 ++++ gcc/targhooks.h | 2 ++ gcc/testsuite/gcc.target/bpf/core-lto-1.c | 9 +++++ 11 files changed, 121 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.target/bpf/core-lto-1.c