From patchwork Tue Jan 18 21:14:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Faust X-Patchwork-Id: 1581538 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=GIhH+mda; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JdhPn2LmBz9sCD for ; Wed, 19 Jan 2022 08:15:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 507E83857C73 for ; Tue, 18 Jan 2022 21:15:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 507E83857C73 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642540522; bh=ehhmXteBPqotrS40Oq4qGfy/B8yeP+Ti/QULq5kIF1E=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=GIhH+mda8mupiPlKmv0xoxtYm0sPh4/9iU2fhVWqVAiP9Gqacyun2nTSuh004zZCP /ctOPrZdfbaPNNwEAox7ZW8CNreaY8sG7FSrbYzsOEHYMb5O0auoNU8cgAPsTyrxNe 6qCUvF8uazurl71TAT75QVDgli0YrDPiaI2r79Us= 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 7AF443858D39 for ; Tue, 18 Jan 2022 21:15:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7AF443858D39 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 20IKEEuj021250 for ; Tue, 18 Jan 2022 21:15:02 GMT Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3dnc4q394b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Jan 2022 21:15:01 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 20IKuLPq142226 for ; Tue, 18 Jan 2022 21:15:00 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by userp3020.oracle.com with ESMTP id 3dkqqp4ffr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 18 Jan 2022 21:15:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FQXyvoAAJVJ6lKLUl0Q9r5lcO+RrsvkureNul6YoNrO+S3Dgk+aI+87iN6rQLc8njfOn9LRIwgMwYtNCOxdLjuyCL+VYPa/EHhInqO460/o0wey9EDwi1fxH+y9JBboL9ipcZQy23csyzoM+me4EbJxgYm2vR3QzmCWLXYT7rUcu9ERwGwcwDM0H201bu+63ybTVsb2VwZkInygGGcXKYcR8lUGdxrnVCI70mbPGErhzZtpbNrdzgXE0ngCveE5/1k+yaYJKmrrwFCadPmUfcYytWSKJVoR3NtTKHfv0SBYbb2uBRTbJnXMnILnp0FhrBhj/l4LyswrCEzK+soFMRA== 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=ehhmXteBPqotrS40Oq4qGfy/B8yeP+Ti/QULq5kIF1E=; b=n5vBDn+VGJ5kmzFN+anxJbr/xXolFUZ52GnefB7GFLr0mvhJp2FSQxGF6Aes9fA/xP3UkNANn6ICjWx+uQZeRKrvR6AFen9q8sHLgkcHEVty20IzRjhIzTSVNMqCW+VoKAJz2BAaV3J6NJQPUkRfeF3e1wyoO/3CMEskuonP2rFGzPJlz5s3oq1HXsXOj0vC9I6RvuA5lxLx/WDVK7B9Y8uyrrhv6HHypdPNx+XfE2iQ8X6zxKK3DASIR8wR2htvSX2qUPt56uSAiVLZPAab6e/d/WQKU2j2j90hNP9mlnlWRH3TT/OrnKJBrr8JnBB1Bda9vUqmuiLo75KYNZMNRw== 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 SJ0PR10MB5566.namprd10.prod.outlook.com (2603:10b6:a03:3d8::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4888.11; Tue, 18 Jan 2022 21:14:58 +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 21:14:57 +0000 To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] bpf: ensure correct string offsets in BTF.ext Date: Tue, 18 Jan 2022 13:14:27 -0800 Message-Id: <20220118211427.7602-1-david.faust@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220118204830.6751-1-david.faust@oracle.com> References: <20220118204830.6751-1-david.faust@oracle.com> X-ClientProxiedBy: SA0PR11CA0188.namprd11.prod.outlook.com (2603:10b6:806:1bc::13) 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: db2fecb6-45d3-465f-d8eb-08d9dac794ac X-MS-TrafficTypeDiagnostic: SJ0PR10MB5566: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: bxHQ0WJJSTfaIwrGoumkQk0XCQ6nFyI0K4LEiwsd9S2z7yXpPaiCcgpJ8n0SC770OaKEiw61XUCr5MqeGvS5gEn68vJMZpRP9I6B5LBwIKmBNvQp+w+PKqzEI6GW5mTYaZjkr3n41HQb+7BvFVdn/TDlWg2pzgWdCBRoY87Sx8+BAk8V2KGUfXKRwiAN+I6MeuA6E+9i2dVxUb98Fm5Fxr5QXDKaht/2fAzLbK2nc/MfmiiK5WgzlUYOpP2Nu0iUm1zpg5sBa0pFqUuYPBoMVqwvB6MManXyL1gmzoBT2g+XHQtKqpKHKva9TLuNS8z7zLg+G4ngCHmMVcWgByvjg7ZflTeZH6VYTb42JnWpojuvjRGO+WBk+A9XZT55kjpvMA7Na2VmkO0t01wdJ5YefLY92PL2gfvdgM+39g8jOso1ylQ3mrzqCwoecxcROW4OVlDjZyA770tXYZ4EzthqYSBqzUquLZeDDEXaOYXmn8BLTHwCDLbqvPLW5eYSf6OeVL/EpDFYpS/J8NliXNaOr778rXvdf7fXwxx2o4Ypi6PoXecT4/UqBoKrId0O71B20T7b1+5qUstsJAfNBhm3gXifxt8gkd7Fq2pKV7S8oJCxq13fBfWxjpcuhc+Gkn/+HyHFwWsBdH9RZYwSIRufRQ== 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)(66556008)(2616005)(1076003)(8936002)(316002)(52116002)(6916009)(186003)(8676002)(66476007)(66946007)(2906002)(508600001)(6506007)(86362001)(5660300002)(36756003)(83380400001)(44832011)(38100700002)(6666004)(6486002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: naTKdR4nc6ZvtfDtUH6bD6+3jqOQ3+Wuk8WmbJ4TMxbFnFcJ6fUs9+lz0XLd+ZjRsWHDtqW1FgiTFUJ8mdNw93iQkCnI0v4rHSxawzHjLIlGSRn4mm3DxCzMkrWoSChHYpct0IPs5n/VjgFBDLuYKpfM52VFWXNepPwyii8B6Jfc1vAkepMzRiCQHgkJfe5HQ9lXXKPSl8GljFUe5NOh56DHJb8qPlQF6UfZlSEMHjgKibVfXGb6+3asXbgDnvr+nmBhNnRXd6GM4iJgH03xVZ4fQbXvdQkkRNB0nZGIaEdywvLuSYmi0kQ46Ix90WifxGQ+EGJT8SivVDxPwaASGcUtDUhwj6VbVRlVcQyeIJ5pLZMdtCef4RToTIdj4vJO2Uddbp4i3c/OzqO+skih4sDiWLmRTrupFiA+2T9m37yYejZKb7Zz7oX8dVT6lubseN71M8hVHdm+DUDbewUHpUziMY4BWRBPzq0ufDGLVLJ5DeMtvE4DNK871P1ANBZo8dUPSMwsLoSviTBQ/vePBZ2w3TFz3ThnE4eppjXhRbDHz4DUZZjpV+RsTk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UHeb+CWG7X X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: db2fecb6-45d3-465f-d8eb-08d9dac794ac X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4458.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2022 21:14:57.8913 (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: fJUuIfklptOlBv5ZrDiYC6ILaZqry6TRtK03rLOYKF0DhgHDvn88lpHzx/PPGIiC6nk9IuIUHitnc6SU/S2rKA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5566 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10231 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 phishscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2201180121 X-Proofpoint-GUID: iOdPW5mo5k41Du4PiFREuCi-oR5nupXx X-Proofpoint-ORIG-GUID: iOdPW5mo5k41Du4PiFREuCi-oR5nupXx 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" [Changed from v1: Adjust to account for file renaming so patch applies.] 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.cc (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.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc index 4ec12ecd305..cceaaa969cc 100644 --- a/gcc/config/bpf/coreout.cc +++ b/gcc/config/bpf/coreout.cc @@ -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");