From patchwork Tue Jan 18 20:48:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 50189 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3CF63857C4D for ; Tue, 18 Jan 2022 20:49:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3CF63857C4D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642538993; bh=6/e/COFv7M6SVlS6LmkEJQ6y9UoTYrGqURJ4TFBrMEM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=U9zbFsLKxqwVqetWtGX5fxZMEEHfybogSeGtIEFwxMbGE9rtpI2nnYqYHoASdzCit JqiO5rVZGwKUG5GbDoECav4FyIQZjGQJucLw4D6rFv4VNeBWQ9Ja0oHAgE0kkVsj0s irI3Zi92ZBlKzWACZXAshlIapPQk9I865ilDU+mA= 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 7AEBD3857C53 for ; Tue, 18 Jan 2022 20:48:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7AEBD3857C53 Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 20IKEDcV021232 for ; Tue, 18 Jan 2022 20:48:52 GMT Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4q375t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Jan 2022 20:48:51 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20IKKsbT032943 for ; Tue, 18 Jan 2022 20:48:51 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2107.outbound.protection.outlook.com [104.47.70.107]) by aserp3030.oracle.com with ESMTP id 3dkmachv0w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Jan 2022 20:48:51 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S7oqj0BmP09UgEsa53CAt7hQ4fsRlYxIKZ05v3w6mlX++kyTcqLM/co2f+Ap2lWQoJcfG1rAfP0AKJgyLPzc+IGN3d3/SW6qZBcMBwkZm3l2eTfGT4aOS0WJSmrDB6gKGSkUsvV2jBPnYXDTShSZ1PKgWS0yZZS/ArDeJoNXg1Cls67CoQWvMEUFBXegktomzhxS3FB/VuVm7dCqOstVS0EmQ5+xrf5BJUxfUPBhtr05tPtql6TokgbISbE4HEvqd/l5jilqr7khg1VjbOhnRUzbZvn9GhNHITTfNSHy5JDbLJ941tVpMUNWAtLNiR+lAvVTO7SCVuosyoZgqc7I4Q== 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=6/e/COFv7M6SVlS6LmkEJQ6y9UoTYrGqURJ4TFBrMEM=; b=QrfmnRZXBqbQw8Hic8Bg4qLfkNEZijgq2nL25Wlb8iOzV8fx0+HZbeo+G7kyXQ972FFXOnZsxBlTXRtuR5R4DPVQMAU7YMW3HBFCllOb0A3qVwYbs1ueEbtEA5PvH2WuKYxFNm5JILUrvXnG+lNiGzlj2IhFp1We5TI2ZboarlUT1fs1bNLHicynWPEBXrTk8n8aLwmTnVAbjizlTb4QIoZwNi9FG8y7OJ8RzBirWFFDEDttTfrgal7rYutmVxsTIzuztJTtXD1OyI/RDVAsPxj3AnlGBB8ErwQPIfo4a5PrDn+jgWDY+MTBixWv+YtvYtI03Coq42gou128C5Mx9g== 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 SA2PR10MB4458.namprd10.prod.outlook.com (2603:10b6:806:f8::24) by CO1PR10MB4626.namprd10.prod.outlook.com (2603:10b6:303:9f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.10; Tue, 18 Jan 2022 20:48:49 +0000 Received: from SA2PR10MB4458.namprd10.prod.outlook.com ([fe80::7cc8:3113:5f58:eed6]) by SA2PR10MB4458.namprd10.prod.outlook.com ([fe80::7cc8:3113:5f58:eed6%7]) with mapi id 15.20.4888.012; Tue, 18 Jan 2022 20:48:49 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH] bpf: ensure correct string offsets in BTF.ext Date: Tue, 18 Jan 2022 12:48:30 -0800 Message-Id: <20220118204830.6751-1-david.faust@oracle.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: SN4PR0501CA0058.namprd05.prod.outlook.com (2603:10b6:803:41::35) To SA2PR10MB4458.namprd10.prod.outlook.com (2603:10b6:806:f8::24) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b9a85528-244f-4982-0d6a-08d9dac3ed92 X-MS-TrafficTypeDiagnostic: CO1PR10MB4626:EE_ 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: +GwDQgulRZvbXh4FKvztf5Zf/UMK9q1AtvJt6eDc8L7Gcyo7/XVu4q4Lh8KAwt6uL7XpKoP2Aj4PC8/kPl+HJH9NlnRkp5gxWmgQQB80bFkR0zcWw7+6F5xWX9tFVaOZPrRB9glOuGSPqwhxEzeDafp7JzyouO8lZs/CN0BU7ppEknN2ylRx9jzVRox2W4Hee9iat/Y+TvE6ey5rbCGx/JCnvjh8A0DAWCF1ejSyHbsat3jytdlHLzrzw2f8auQgtNU5k800o9BaKSxw7s7afivk3xhOYYAUqX0ezqyMbaEOssyCZNkKbb8SCHj/0QuH6OpexhXdinp8EyLgWRwhOQvD3EsPh0MIThQPj2DLmoGLllx9OOuu2Wq/lUOvQi4Ahu6MH19yaTd5WozuXwqquOzeZ4kmqbHeE3NLJr78fsBuoqlV2xYJaRD/vehsa5+ZkXEZky+HBJZNfHaLZeCG7bRi2pJ/lNrUihqj7IrKb/8AI8h46q1VpN0R0ZezcNyUSviQ66LF8vhxQHk4f2nlhA1g6KF0XlGm6SyCtPPQ9EpTua/NURfPM+bL0ox2e1OQNAcpu2rjjCCEz36lC3XYlhtfBIt8BE9ZQU2W4O3QxBXXWeVQA/Xi6u6FssxAZS50m6tmAdhmiCmZdEwwDLkdxw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA2PR10MB4458.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(366004)(6512007)(107886003)(66556008)(8936002)(6666004)(52116002)(66476007)(8676002)(2616005)(66946007)(316002)(508600001)(38100700002)(83380400001)(6486002)(36756003)(5660300002)(4326008)(2906002)(86362001)(44832011)(186003)(1076003)(6506007)(6916009); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rylyKAcZGqXXzH8//U55WLYcZQjh+r+Biyiwr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FhXdJNu4Yc7Mc5g7VMFStLkWomaRcTewILEPZOeyJSb9ih6GCf8xs3nybDT9V/U6sakyWKsfjXuwIeg9lJiASZcBsSwMUXysLXjgyl4qtXyrEK/1FBe25SssLwlMZON4h5LFAaBoL1UB3YOIVTXgDj6UOdximQebQCyf0aQPXQ5gdqBzr1oylA5woFzgElmAVQSRuWjT2U46ow2SEbaNyZHPRBApQ7KMPxeL4yAodgoGxLLoOePD8+Q49OCwfM8CB2Ha5aH9lGL2t61lub8RTu6dnjglOTOVCSpzlsr3vYz+7QWKi3mTvbMBmTHQl2SkHxETszZN8XsVEwhsZ8c0OWoaqsez9aO920HdFm92yR+DzsJEQQBOzyOdITqhnrnJns2by8b6othg0hnNUuh5MqLmWOF1gozqzc31poBUQr/hjyFxXPuAocCXJhqgyh64CIt2u2P7Wxj4+/q5iE/258fEmMYWgiwCAKjQBVpRlAm7aVCmFiRq/HQrO7Xz+umXAemUHAr1pFw69rsIYvEYgZh8MMnCFrqy29y1N1Cvg3OKYVbZA X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9a85528-244f-4982-0d6a-08d9dac3ed92 X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4458.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2022 20:48:49.0447 (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: FMv6sOaZpYZ3+Jgv8JVaHcK/d/SnpPmRnx/eNUtUVcFGMHQtFqEUO8XxIfo9iv01o4cziXLH5c9fGjrdAy/5PA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4626 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10231 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201180120 X-Proofpoint-GUID: UNhlWOcuxd4xg0cQ4KaLH4zRJSy-quEb X-Proofpoint-ORIG-GUID: UNhlWOcuxd4xg0cQ4KaLH4zRJSy-quEb X-Spam-Status: No, score=-13.9 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.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: David Faust via Gcc-patches From: David Faust Reply-To: David Faust Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" BPF CO-RE relocations contain offsets to strings buffered in the BTF string table. These BTF-specific strings are stored in memory in the CTF auxilliary strtab, which at output time is concatenated onto the end of the standard strtab. Previously, these string offsets were computed at the time the relocations were created. But strings could be added to the standard strtab after this point, causing the offsets to no longer be correct. Compute the offsets just before output instead, when they are sure to no longer change. Tested for bpf-unknown-none. OK to install? Thanks gcc/ChangeLog: * config/bpf/coreout.c (bpf_core_reloc_add): Do not account for base strtab offset yet as it may change. (output_asm_btfext_core_reloc): Do so here instead. (output_btfext_core_sections): Likewise. --- gcc/config/bpf/coreout.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gcc/config/bpf/coreout.c b/gcc/config/bpf/coreout.c index 4ec12ecd305..cceaaa969cc 100644 --- a/gcc/config/bpf/coreout.c +++ b/gcc/config/bpf/coreout.c @@ -168,11 +168,8 @@ bpf_core_reloc_add (const tree type, const char * section_name, bpf_core_reloc_ref bpfcr = ggc_cleared_alloc (); ctf_container_ref ctfc = ctf_get_tu_ctfc (); - /* Buffer the access string in the auxiliary strtab. Since the two string - tables are concatenated, add the length of the first to the offset. */ - size_t strtab_len = ctfc_get_strtab_len (ctfc, CTF_STRTAB); + /* Buffer the access string in the auxiliary strtab. */ ctf_add_string (ctfc, buf, &(bpfcr->bpfcr_astr_off), CTF_AUX_STRTAB); - bpfcr->bpfcr_astr_off += strtab_len; bpfcr->bpfcr_type = get_btf_id (ctf_lookup_tree_type (ctfc, type)); bpfcr->bpfcr_insn_label = label; @@ -191,7 +188,6 @@ bpf_core_reloc_add (const tree type, const char * section_name, sec = ggc_cleared_alloc (); ctf_add_string (ctfc, section_name, &sec->name_offset, CTF_AUX_STRTAB); - sec->name_offset += strtab_len; if (strcmp (section_name, "")) ctfc->ctfc_aux_strlen += strlen (section_name) + 1; @@ -287,6 +283,9 @@ output_btfext_header (void) static void output_asm_btfext_core_reloc (bpf_core_reloc_ref bpfcr) { + bpfcr->bpfcr_astr_off += ctfc_get_strtab_len (ctf_get_tu_ctfc (), + CTF_STRTAB); + dw2_assemble_integer (4, gen_rtx_LABEL_REF (Pmode, bpfcr->bpfcr_insn_label)); fprintf (asm_out_file, "\t%s bpfcr_insn\n", ASM_COMMENT_START); @@ -323,6 +322,11 @@ output_btfext_core_sections (void) /* Section name offset, refers to the offset of a string with the name of the section to which these CORE relocations refer, e.g. '.text'. The string is buffered in the BTF strings table. */ + + /* BTF specific strings are in CTF_AUX_STRTAB, which is concatenated + after CTF_STRTAB. Add the length of STRTAB to the final offset. */ + sec->name_offset += ctfc_get_strtab_len (ctf_get_tu_ctfc (), CTF_STRTAB); + dw2_asm_output_data (4, sec->name_offset, "btfext_secinfo_sec_name_off"); dw2_asm_output_data (4, vec_safe_length (sec->relocs), "btfext_secinfo_num_recs");