From patchwork Fri Jul 30 20:12:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 1511799 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=Z67S6xeR; 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 4GbzCB6BPkz9sWd for ; Sat, 31 Jul 2021 06:14:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C7C13398841D for ; Fri, 30 Jul 2021 20:14:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7C13398841D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1627676084; bh=uaxg2mDF9ZO/ciQFfnVWIiJG+1pbwgodzda+upBRyiY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Z67S6xeRZORX8GgxVFmdZER4JUtWv4gMispeHGnQfMWY0ETVnuAotdJdzsb5KyCRr NzFMNc4Sy8QS/dXOZftAZt3DYkG1TsfZ+YmKbNKjz+nmWhdlqNbYFzpHDA8XlXh6Ok CeXONZphLkadHgTHQuCO05YvnhLn4WOOgkQ8C2gI= 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 E5EBE3955C09 for ; Fri, 30 Jul 2021 20:12:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5EBE3955C09 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16UKBmn3004660 for ; Fri, 30 Jul 2021 20:12:53 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3a3uujbsyu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 30 Jul 2021 20:12:53 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 16UKB5ws003823 for ; Fri, 30 Jul 2021 20:12:52 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam08lp2042.outbound.protection.outlook.com [104.47.74.42]) by userp3030.oracle.com with ESMTP id 3a235a6a5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 30 Jul 2021 20:12:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ULuRyCWFw2SehGA7VTry/+LpnlqB60pvQLx+zI+StMhlMp7m+E6Q/GgBKiy2v2F/9CcLHDnfriYA6xPLksVI0mDvNuNKdTx8qPg5Kz9DuMjpBe2JJFYZn1ffkOjPwggIhUO+pxfBgtsZPHPECF1qm8mwScV7P4UZi1qQf5dNYrS06W5HrfkgVScvcDpIcu9N/4LUA3KWDf7tm/yN2+D+vtG+4irDEEprlJqMtCInk68QNLoFbqVYIkWEuRxzXC9Yd3SbcKuFsTbDvbqnQFArnM7Q8FqXoweyiqdy1N3EwuuM/xjF50zfH8gdyRWgu3Lw0C/MTgEU7qYZTXsMlc0X/g== 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=uaxg2mDF9ZO/ciQFfnVWIiJG+1pbwgodzda+upBRyiY=; b=aqHLfcIz9lQZhjZdKolXnr+0cJvITN35/ZOu7UvR+Z9lEvQY+NmaqUjc3DwxPVcmUirUlSW2mjTlZmPVTsAmfBiFMZWj0pjwzSlimUp055X4tNEmUYBdak/BXLthOgzHIIzGv20FCV+reCo4ZclZgU6abHvnaZLOe6S6+Yo8hi67HLoBFAfrS3by65CUNTheZ/lUiD5qEMUKofASp4DFw0w9rbJLgDV4pVpA0yrneY+0pUQSpgrzKeRYxHTQpM78NDSnKHovd+eYFpjg/qRpC4qeXB66ebo30f3AOyTBcxmopllTJeuBiciJexLcP0RBDKgcWhh7GAfAV9ZRgNnQJQ== 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 CO1PR10MB4689.namprd10.prod.outlook.com (2603:10b6:303:98::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.17; Fri, 30 Jul 2021 20:12:49 +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.4352.033; Fri, 30 Jul 2021 20:12:49 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH 0/3] Allow means for late BTF generation for BPF CO-RE Date: Fri, 30 Jul 2021 13:12:36 -0700 Message-Id: <1627675959-17662-1-git-send-email-indu.bhagat@oracle.com> X-Mailer: git-send-email 1.8.3.1 X-ClientProxiedBy: MWHPR08CA0042.namprd08.prod.outlook.com (2603:10b6:300:c0::16) 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 MWHPR08CA0042.namprd08.prod.outlook.com (2603:10b6:300:c0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4373.20 via Frontend Transport; Fri, 30 Jul 2021 20:12:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8a668e11-a4cd-4efe-7d9f-08d95396677c X-MS-TrafficTypeDiagnostic: CO1PR10MB4689: 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: 0o7jiPq3eRg3IpKhKB0Al3DIxp2Ft8nj3zRmfrdo7hPgu0KS+OaOteX+IqW5pwWu+K1dCTbvsnKYCGh8U3TQdDZRHFMMnGgChcwGUu4crNgr8nOdE4vFOQKPc6Y5Q4UzWMXjS/3XerzYYX7e3lXke8KlknJae4WP6UJuUJ1LL/jNYnehaUCFevdrrortJUcvo+kktrus6rJfSTTc90Qj1FZM5QHlM9WznHYseJrxbn72K1AdxPJNvdAJqDkGe7LFV9mwvI663KKv/yJE1IJ5TQFL0/HhfFGU3DYjDNwBw11QV9cOToJllsChkANXwZV0XO3TCe+99/dFn6CQinZ/z8QmHTVBw9s7cOEt6BflXO6gmefewbVTOcu4UySHHXsGtz1zVE6AvQULUV+09dzQr/8Nntx5Klfu3dDCFjMh680q8BwE8Z1ehlLGaBn9lmFNdZgN3PfyL2BpxVjTYRqq+ngFWR8Ma1Bw1zZ6JO6NcTXcSu2PgGlLVDjaL/CUOufDulTyQoUmFzHumKyBknXFHWPA4fBMOfRizeUZIw+J9abzxa+rym5dbJ0Nr1dQXsfZ7SpSMgER1dJEExKVSg1Wbtk0kxiQWzHzh1G0ICK9UY5PLVO13behcoBDOuUUNBV7EY2HTMK5i57FhRQoB+Azi7bcGsDHXbiEJde5yIRad4Ugglw8N7AlnMOMR04esnIss7hA7lFKD5O6c5YCJMf/6g== 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:(39860400002)(346002)(396003)(366004)(136003)(376002)(66946007)(2906002)(66476007)(66556008)(52116002)(316002)(6512007)(6666004)(6916009)(36756003)(44832011)(186003)(8936002)(5660300002)(86362001)(2616005)(83380400001)(38350700002)(6486002)(26005)(6506007)(478600001)(956004)(8676002)(38100700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ++Pyhvfsake9TBP8OlkZCaNOCAFKYgkZ7txLtgfGXV5DvlMzQWBqd5wFqC4dbCXFG9SsqPq7m3W3l3C9elHbz3Tkc/soXZgiANh2pP8FbeSvIwTSOBV11n3LXU8ywzld0ivwQ44Xad4UNN8oPzLvmfMnE/fWMbtJLdx6tTZi51dIPCrm1r6lbGN04H7wIWSM7oD/O6H8d3v+zOy3GvqYP9npg3MvCQsnnwi5UPKuAPPMo7SC/OcWDYmQd2FjuQIwUkYSSRLVulv81F1Vfce71dpCJu47S49jrfjifwU0eYuK1uYaMUlOjwObII6cQp4Tvc+JcbPfzFpOqjFRkvcaAnIif+DnIL41eI0IAaHHU+wDtinZDwBnldZW9NMK2SZmTusMAf7NlgrOtpovnY4S/50nOkxd1tb4wQ7uaa0FuIgXBBKICBTlpaNI9gMUF6icLPbYnCbHPoW3t9oVW9zU9Pso5VpLC3qrlqhuhEEYczxZ5Ks19phifY5hoCKaXBJ81cyQqo9mtPzz2AOaoCeug5xJXptPzy352AnsYPRa5802V+uXYAUpn0jkfkUZJGKyccTiS3pbdoqfKBPREdcsUOXWg5Ujah9sbVqvV9X5Qc654xhvqKmz5PndjyvpyM30DQmKQbmmHmF2rWb0BOeotK+zO3Celf3Xl5Jc9edvjMP4ynU+Ex+JTYnKROSMCnRq3cLbdzfo8AsmpE+s6buLtVv0yue2lRTLnHyNcsKO+OVdHdrWX8Bgl70OCK8ioumhGxYVoNtOzf6ztwMWLvqGhQRqihEtnl21vfxzRWzM55kZAnjXE/45ZBc/6+0asRtVPSDkwzfMSLe8+4T5VemEBE1vOIyBomThCpUrbQ40BfvrlvCKZhjiMO7Rv0i+t130ThrQ0xFfC1ppGGTRHoNPg/c06Fh7N7q8IzOntaywom724ZiBzgaDTUvIVcQLUnUMmX05UZyJuvbzeV96j6IypPfjxtfH82DlYQynjZkbNFb+2Y29r6faDOCpnuSy0xoddvgHMp7/hwZhzC6Dz6CW916A22xfnt5hn5sgxbv3lkLZKF30P/JYH0G4u5qyYw4orcYRT/o14wKBb+nc9Gramhm17WCLIRht/CqfvNJzbXztxIx31dmiz/LVfLPB9T26i1XD7p4Cf+byDG2PvxgYo3NXs4bM4IW7acOFKxRR2xJ6O6Do2cTHIIK9VqJ7WwenvEKcc9SlOHwdIleWHx9hs12KKw7eHudKYW+51hzVAVqyjfgcspwvzGgXH3uX5y9D6EkIwPht5MmXQESp5hxOBUxv3r09ChfIVuTxLHp8Q48UKrNTFNPHNJwn5nJIBLEt X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a668e11-a4cd-4efe-7d9f-08d95396677c X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2021 20:12:49.7206 (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: 6bKUPwLPiYghIW5KMRiNZ7Vwo4CJZzneDcmvFXS6E3qSE1Qcs608MlebpMQsfvUBvTXaTjTEF6HAjTozMvU2KQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4689 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=10061 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 suspectscore=0 phishscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2107300137 X-Proofpoint-ORIG-GUID: ThEi3TwH0ZYTsfh8F0h1L4Ih01ZfG-_8 X-Proofpoint-GUID: ThEi3TwH0ZYTsfh8F0h1L4Ih01ZfG-_8 X-Spam-Status: No, score=-6.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, MSGID_FROM_MTA_HEADER, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_BL, RCVD_IN_MSPIKE_L3, 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" 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. 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 the BPF program. 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 section to adjust some references in the instructions of the BPF 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 (CTFC) is populated with the compiler-internal representation for the CTF/BTF "type information" at dwarf2out_early_finish time. - In case of CO-RE compilation, the information needed to generate .BTF.ext section will be added by the BPF backend to the CTF container (CTFC) at expand time. This introduces challenges in having LTO support for CO-RE - CO-RE relocations can only be generated late in the compilation process, much like late DWARF. - While .BTF.ext is a separate section, the format requires that the string encodings of field accesses (in the CO-RE relocation record) are added in the .BTF string table. Recall that .BTF strings are owned by the .BTF section. Hence, this means that .BTF section cannot simply be emitted "early" because the CO-RE relocations records will need to add additional .BTF strings to the .BTF section. - This patch set disables LTO to be used together with CO-RE for the BPF target. Combining late and early BTF is not being done in this patch series. BTF debug info emission for CO-RE compilations is done at dwarf2out_finish time. - A new target hook is added for the CTFC (CTF Container) to know whether early emission of CTF/BTF is allowed for the target. The hook returns false when "-mcore" for the BPF target is in effect. Testing notes ------------- - Bootstrapped and reg tested (make check-gcc) on x86_64-pc-linux. - make all-gcc for --target=bpf-unknown-none. 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.dg/debug/btf/btf-mcore-1.c | 14 +++++++ 11 files changed, 126 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/debug/btf/btf-mcore-1.c