From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70080.outbound.protection.outlook.com [40.107.7.80]) by sourceware.org (Postfix) with ESMTPS id B645C3856271 for ; Wed, 11 May 2022 15:13:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B645C3856271 ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=PcpUcsJZVmLIjxLyBbn4r5XZkaAo51cuo8DrTS/q+mjKd6xLwYMrntaiYtwDnqAMBTrmmtC2WAgMCxYQ2zCCmfCX6QdsNkJZsPcKaR/eUwEUoTTsPu7BW9Ckta4Tlhmnt335rR4XQj/4rvFFbihnsR7iVd1wgcHH/SMLLYESWTZxqc6VJnOd46c25faAKfp4wJHkIod4DIkktlL4Rm/qEoQeRuSp430NdI8UJhgXe3tZLEeQl2S86vUff7J4WsYYOoRnTYenQPAvErmoLJoLCLpimFVwEhSmp+VimhYAH1/LPMV8uEu7dtU/mlyaYXkkiO9YiPuQbH0joOF1hLhTQA== ARC-Message-Signature: i=2; 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=R+jJhNSUs5voy6c7mlyRWXhQZrKPLTC+kxfA2cZ4m98=; b=iAPrZpanKRDDSlOl5HYJGoGixMpqxJMGe1VKxF1Tu8V4KJM+iI95sBfrzFYgVJh7Gv24I1qWcLt574nt13NVWGX9dieZvQRWDzaD9X5Uzijo1ZUPyPoE9+YX2PCBhzRMWbF76iSvtgcb1DdJQoatXeUzDRp9JlfyvcgE2q4ZM08Ae2RJvl5+hKypnyimML6xTKGLms0ssoWIekV1rOAvtWoV8bZQqLB441jnVTchQqLWnsl1EK8rYSuLGN3+OnNIQ49kwcgyO8jcKriN5V3vOs4DSxboZaCP0WbagMfhBzM2n+ryI9GJVm4ftmdCLfmOY3Z+P+GMlkmveyHvhNWbzA== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com]) Received: from AM7PR03CA0013.eurprd03.prod.outlook.com (2603:10a6:20b:130::23) by VI1PR08MB4015.eurprd08.prod.outlook.com (2603:10a6:803:e1::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.21; Wed, 11 May 2022 15:13:23 +0000 Received: from AM5EUR03FT040.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:130:cafe::40) by AM7PR03CA0013.outlook.office365.com (2603:10a6:20b:130::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.13 via Frontend Transport; Wed, 11 May 2022 15:13:23 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT040.mail.protection.outlook.com (10.152.17.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5250.13 via Frontend Transport; Wed, 11 May 2022 15:13:23 +0000 Received: ("Tessian outbound 361d68419a2f:v119"); Wed, 11 May 2022 15:13:22 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: b1b8efc4f9397aca X-CR-MTA-TID: 64aa7808 Received: from 3af07c022530.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C45C4B65-96A6-438B-8D34-DC500FFB72E7.1; Wed, 11 May 2022 15:13:16 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3af07c022530.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 11 May 2022 15:13:16 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NYs7uDJCC62J2nvqpmbMGqjlC2y7Msh8u2CR2mbWOxz8TY7Iv13Wa1VJH9V0qmdYmecxBj9DdX72U9VCjMFNfD+DnfEEnOWQJNWQ5FAvIBAeH+zasA8GLb0vuieky7IBEpbeS8P0ipX7t60N8g0gCgfW23loPb/2Fr/bNReG295NohzA3wzNXz10c33fT6K8yT7GwLfqvBqFljRUUNKe1xo0xO8SJBYhye/joEeNxdxnEao2XYunubWSdXyOiM7NpHQa/uta5oKYN0jFVafAJgZi4Bg/Qtl6/OMkT43ueYBLoxUTN+XMFzgKEXvE3vvwmIEsCTK1QkjggJ1oFobbfA== 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=R+jJhNSUs5voy6c7mlyRWXhQZrKPLTC+kxfA2cZ4m98=; b=ceydQ+7BPntrbtr7rcS5x8zT2ExXRmgpY+2mLqrGJTKx2qaoU6iQ4JufvJH6AiKu2qly/JkhkY+NqGxYyWwWc3HFRrqFH3qadFwmI1xx+GFQ6Fq321c48U2pJy6JiPdlU48RfbS/l4nmu1FCgCyICqvWGJ5whEopHyFIl5/XgNM6Bkr9VeSHONY/EvLHQSNmAj5rWin2uJkDyxPPdFufIQZ/ddQ7XMXpMYbFByZXkE20qhSDcoTBJtsWqVJccN2Pb/ysoSucssCHzQkD6sxbQEIX8ThSBb/xRzsTth+QKbeob2kC3cOGuEDBfPqPMIvEDN3bKdPZxkwI9r5BLTV3dg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) by AM0PR08MB4001.eurprd08.prod.outlook.com (2603:10a6:208:129::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5227.21; Wed, 11 May 2022 15:13:15 +0000 Received: from VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::7080:6233:cf8f:a8a6]) by VI1PR08MB3919.eurprd08.prod.outlook.com ([fe80::7080:6233:cf8f:a8a6%7]) with mapi id 15.20.5227.023; Wed, 11 May 2022 15:13:15 +0000 Message-ID: Date: Wed, 11 May 2022 16:13:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: [PATCH] [AArch64] Support AArch64 MTE memory tag dumps in core files Content-Language: en-US To: binutils@sourceware.org, Alan Modra References: <20220331140457.9237-1-luis.machado@arm.com> <20220503113350.571511-1-luis.machado@arm.com> From: Luis Machado In-Reply-To: <20220503113350.571511-1-luis.machado@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: LO2P265CA0089.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8::29) To VI1PR08MB3919.eurprd08.prod.outlook.com (2603:10a6:803:c4::31) MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: f230a367-96f1-4258-dc55-08da3360ca56 X-MS-TrafficTypeDiagnostic: AM0PR08MB4001:EE_|AM5EUR03FT040:EE_|VI1PR08MB4015:EE_ X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: XQESZGhOUgxIudv8bF2E9cHrFfFBG3pDjjbVVEIdbn+Ui4jQp/+i712WGzvjADsiQOGlYvDXIdVXArTJ5zYDFG/r0kewti4owqvpPsvOUFkCTy6xq9ccHzXhFosejdrxgjZEiBZPEyHdzY27a+69a/9cmZWwHqRCiG8PxRkAkAXNXuqL2NjRZ2nQgM63vhVDU46RUpShnZhxa1qdfONfqdLJCtbyHCU7HWMEL/YZ+0cqrAywzcrsdoEaIfto95C8teVCTH102GqPZMBWoZJPT8YNMHezaBFxZWTk4jHX2rbCWY7jMcdjtJg54NvYMWsar77I1Q1rg4p7vUE9BHmWVwKOBjgh1Q5Ccf6oR4WrJkFmQkNvc105pJ+DXT/rn1r78CONRqujl+FBi98eeG9tpiSEFdlNbgdX+Xhy1ti+iHG71mO2lKtB4FVuzM1wqmIAMGo/mxnfLAzMCnx/CWeeWKPIAXoox5tDkiOOWkJRYEwe+TWjLc+AdYyG5n0S/G2mbv4LeczxByhDRycQYiHa6jJemkQ01dqOGDIFKGRyKzbXJW6BDAB45qwv/y4TUVUUfMv2apunRt0Psl+YBYO21AdtTFjYwBHXivFrxfQ2MA42KRXMjIMNxHkYtdHKueVDFi7GyRvr4EGPZm1pdG2ZwX+hwNJx82MyOwdaSBcgOp7zSkAPfaq1ucn/5FEcLi5vsmBf5k3JeBUB4FEHQUSV+BytgwaOdSJTW3rsTar5/oU= X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR08MB3919.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(6486002)(83380400001)(31686004)(508600001)(2906002)(6512007)(26005)(186003)(31696002)(44832011)(5660300002)(6506007)(53546011)(86362001)(2616005)(8936002)(36756003)(8676002)(66476007)(66946007)(6916009)(38100700002)(66556008)(316002)(45980500001)(43740500002); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4001 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT040.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: a5643ee0-68ed-45f8-ce11-08da3360c56c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZXjJhBMp3N9pbh/m1uy/s6NHfZz4IHvMk6lWwY59UMfF6AsfFc6JcT/cY4wxPz+xRgeNwiF2bNXHKm6KZqJVVjdmlAGgqSqqfVhbyDFtqEij0l6fYyrBbAGrxddnqGneHrpNr196ls8xA4LA2PedGWgprlzR1AjZaw+5BZuOVbbL1MqJNCXpSqE0WAY6yhpu6JrshRXQYygKT0O3pJDF/IKrdq95ILTE4FSyJmMN5VeSe5FM6trWG5cHWL4bKBc4Q9VZjHHsIs0gF97ZwDoK8WV6BRA/undhJQcHpseThFld5idiXKMDjSACpuQv/jzqwpKVZTAZau9YDpV19HSFr5mAPkaBC+Qseb1y71/HHbHnUcvIwCef9P4IZYTX8V8LZGa7FtcglsPQJYJc1fIS94BxpijJurD5s70N6Mz2rLmycMpONQ1vUfa5+fGwBEr6vp1TIxnusqIQMXYfK3PKJCwomzApXNt4tBOU5eoCRH7/+L6U0cvrizzqKHJqJM1iYH9jem3c+J9Hl53/AtlBkn/9dq94fRTvl5lTI46n7fYJqDla/KShkpiEKRqGXFATHpgH4Q0n3WzAbpdbYrXz3y1DqZmPxhBfhtMDVgueo4SRvoDbJqzlRhhV/GiF+iekrGTXw+7qB5o0NVn3ZNI4HE42XlODMiK1TaJ40BKYGP/jdoO6nPvJhUONsZMq7RtkrnqWkeZ53WIjjjnXsu+MQg== X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(36860700001)(508600001)(6486002)(31696002)(81166007)(40460700003)(356005)(8676002)(6862004)(70206006)(70586007)(86362001)(2616005)(316002)(5660300002)(6512007)(26005)(31686004)(53546011)(6506007)(2906002)(336012)(186003)(47076005)(83380400001)(44832011)(82310400005)(36756003)(8936002)(43740500002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 May 2022 15:13:23.0132 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f230a367-96f1-4258-dc55-08da3360ca56 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: AM5EUR03FT040.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB4015 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2022 15:13:31 -0000 Alan, Does this updated version look OK to you? On 5/3/22 12:33, Luis Machado via Binutils wrote: > v3: > > - Update the segment name from PT_ARM_MEMTAG_MTE to PT_AARCH64_MEMTAG_MTE > and change its value to PT_LOPROC + 0x2, as PT_LOPROC + 0x1 was taken. > > v2: > > - Drop arch-specific fields from the generic section data structure. > - Use the rawsize field of the section structure to store the original > memory range of the memory-tagged area. > - Implement the bfd_elf_modify_headers for aarch64, to adjust the values > for the memory tag segment according to the Linux Kernel's format. > > -- > > The Linux kernel can dump memory tag segments to a core file, one segment > per mapped range. The format and documentation can be found in the Linux > kernel tree [1]. > > The following patch adjusts bfd and binutils so they can handle this new > segment type and display it accordingly. It also adds code required so GDB > can properly read/dump core file data containing memory tags. > > Upon reading, each segment that contains memory tags gets mapped to a > section named "memtag". These sections will be used by GDB to lookup the tag > data. There can be multiple such sections with the same name, and they are not > numbered to simplify GDB's handling and lookup. > > There is another patch for GDB that enables both reading > and dumping of memory tag segments. > > Tested on aarch64-linux Ubuntu 20.04. > > [1] Documentation/arm64/memory-tagging-extension.rst (Core Dump Support) > --- > bfd/elfnn-aarch64.c | 89 +++++++++++++++++++++++++++++++++++++++++++ > binutils/readelf.c | 1 + > include/elf/aarch64.h | 3 ++ > 3 files changed, 93 insertions(+) > > diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c > index 4926bab9cf2..3eee97b7ada 100644 > --- a/bfd/elfnn-aarch64.c > +++ b/bfd/elfnn-aarch64.c > @@ -8158,6 +8158,89 @@ elfNN_aarch64_section_from_shdr (bfd *abfd, > return true; > } > > +/* Process any AArch64-specific program segment types. */ > + > +static bool > +elfNN_aarch64_section_from_phdr (bfd *abfd ATTRIBUTE_UNUSED, > + Elf_Internal_Phdr *hdr, > + int hdr_index ATTRIBUTE_UNUSED, > + const char *name ATTRIBUTE_UNUSED) > +{ > + /* Right now we only handle the PT_AARCH64_MEMTAG_MTE segment type. */ > + if (hdr == NULL || hdr->p_type != PT_AARCH64_MEMTAG_MTE) > + return false; > + > + if (hdr->p_filesz > 0) > + { > + /* Sections created from memory tag p_type's are always named > + "memtag". This makes it easier for tools (for example, GDB) > + to find them. */ > + asection *newsect = bfd_make_section_anyway (abfd, "memtag"); > + > + if (newsect == NULL) > + return false; > + > + unsigned int opb = bfd_octets_per_byte (abfd, NULL); > + > + /* p_vaddr holds the original start address of the tagged memory > + range. */ > + newsect->vma = hdr->p_vaddr / opb; > + > + /* p_filesz holds the storage size of the packed tags. */ > + newsect->size = hdr->p_filesz; > + newsect->filepos = hdr->p_offset; > + > + /* p_memsz holds the size of the memory range that contains tags. The > + section's rawsize field is reused for this purpose. */ > + newsect->rawsize = hdr->p_memsz; > + > + /* Make sure the section's flags has SEC_HAS_CONTENTS set, otherwise > + BFD will return all zeroes when attempting to get contents from this > + section. */ > + newsect->flags |= SEC_HAS_CONTENTS; > + } > + > + return true; > +} > + > +/* Implements the bfd_elf_modify_headers hook for aarch64. */ > + > +static bool > +elfNN_aarch64_modify_headers (bfd *abfd, > + struct bfd_link_info *info) > +{ > + struct elf_segment_map *m; > + unsigned int segment_count = 0; > + Elf_Internal_Phdr *p; > + > + for (m = elf_seg_map (abfd); m != NULL; m = m->next, segment_count++) > + { > + /* We are only interested in the memory tag segment that will be dumped > + to a core file. If we have no memory tags or this isn't a core file we > + are dealing with, just skip this segment. */ > + if (m->p_type != PT_AARCH64_MEMTAG_MTE > + || bfd_get_format (abfd) != bfd_core) > + continue; > + > + /* For memory tag segments in core files, the size of the file contents > + is smaller than the size of the memory range. Adjust the memory size > + accordingly. The real memory size is held in the section's rawsize > + field. */ > + if (m->count > 0) > + { > + p = elf_tdata (abfd)->phdr; > + p += m->idx; > + p->p_memsz = m->sections[0]->rawsize; > + p->p_flags = 0; > + p->p_paddr = 0; > + p->p_align = 0; > + } > + } > + > + /* Give the generic code a chance to handle the headers. */ > + return _bfd_elf_modify_headers (abfd, info); > +} > + > /* A structure used to record a list of sections, independently > of the next and prev fields in the asection structure. */ > typedef struct section_list > @@ -10059,6 +10142,12 @@ const struct elf_size_info elfNN_aarch64_size_info = > #define elf_backend_section_from_shdr \ > elfNN_aarch64_section_from_shdr > > +#define elf_backend_section_from_phdr \ > + elfNN_aarch64_section_from_phdr > + > +#define elf_backend_modify_headers \ > + elfNN_aarch64_modify_headers > + > #define elf_backend_size_dynamic_sections \ > elfNN_aarch64_size_dynamic_sections > > diff --git a/binutils/readelf.c b/binutils/readelf.c > index d45e0920788..ea20479daef 100644 > --- a/binutils/readelf.c > +++ b/binutils/readelf.c > @@ -4499,6 +4499,7 @@ get_aarch64_segment_type (unsigned long type) > switch (type) > { > case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT"; > + case PT_AARCH64_MEMTAG_MTE: return "AARCH64_MEMTAG_MTE"; > default: return NULL; > } > } > diff --git a/include/elf/aarch64.h b/include/elf/aarch64.h > index 703a62baeca..e368ff2dffe 100644 > --- a/include/elf/aarch64.h > +++ b/include/elf/aarch64.h > @@ -27,6 +27,9 @@ > /* Processor specific program header types. */ > #define PT_AARCH64_ARCHEXT (PT_LOPROC + 0) > > +/* MTE memory tag segment type. */ > +#define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 0x2) > + > /* Additional section types. */ > #define SHT_AARCH64_ATTRIBUTES 0x70000003 /* Section holds attributes. */ >