From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2066.outbound.protection.outlook.com [40.107.22.66]) by sourceware.org (Postfix) with ESMTPS id A02AA38515FA for ; Thu, 21 Apr 2022 15:19:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A02AA38515FA Received: from AM6P191CA0017.EURP191.PROD.OUTLOOK.COM (2603:10a6:209:8b::30) by DB8PR08MB5516.eurprd08.prod.outlook.com (2603:10a6:10:f9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14; Thu, 21 Apr 2022 15:19:00 +0000 Received: from VE1EUR03FT021.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:8b:cafe::df) by AM6P191CA0017.outlook.office365.com (2603:10a6:209:8b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Thu, 21 Apr 2022 15:19:00 +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 VE1EUR03FT021.mail.protection.outlook.com (10.152.18.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.14 via Frontend Transport; Thu, 21 Apr 2022 15:18:59 +0000 Received: ("Tessian outbound 9613c00560a5:v118"); Thu, 21 Apr 2022 15:18:59 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 42daef65c66ea56e X-CR-MTA-TID: 64aa7808 Received: from d989f8a54e98.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A92AE26B-538A-42F9-84B2-29041DCD2A4D.1; Thu, 21 Apr 2022 15:18:53 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d989f8a54e98.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 21 Apr 2022 15:18:53 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cFM6/Ny042oc4pcX26yhKvdyU/5n3Ibw0JS+6TORszc1PgPqgTeE2AfOtHaqE5LX44rsscQ7pHnmB1dxNL/z05DqV3NWIhBSz5r6wYqJhBWCcGueGwFEtiAlsXF2Nj4UVvrl0x7ML1D+/F/XHdcLkW9Z75tyQWgGv1l8yRr1L6VwLIJu73zKZy183Zbshva/4fS+xNcKat4SbRGOgi+kFnxl6+olb/B6Q0LDOvTIt4au2pnekuHPE68wOi2QgYG9vsVccq5DKGCsedwPsGw+rZo/YZAx6GR9w2fa4pNAtElGTtAOMSSHbumj5NanbIycvzPYshwjWmXDcxIOJKzqGw== 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=fvd3wOWv5dcP3gFNov9MeiMe/ETpWKQH3iMJmzsKRi4=; b=k3ImcAQwNUlXocFvupHC76D5mbiGioKdS4EQonTycnUmxdraL7djWZxxWmeVc7G7CzHfi9Ysw+3n8zgQCr1tgDbL7Xow8bnjUbc/B3dDPWUAt4ZhreChuyfppL7EH0g4l0xj3qry3phukcA8U2hGthsrKWP8lL12zmZmwtND4FDRXUDqqferYdOZpcOSe7s4S3BVdKfyZEj5iSqCGsyc+BzM9wqHE8XBpJSg/UV4g/SQ8Tx3302DI2ceGyp1KGrgGTURsaODFC84p0Qd7vuHObZ7ilz/ZMEkVCGstp732HUgOsUaZwNGb/U5QGIFFk2PvnWIX2UHAJlbdfH7K4xtuw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from AS9PR06CA0234.eurprd06.prod.outlook.com (2603:10a6:20b:45e::31) by DBBPR08MB4629.eurprd08.prod.outlook.com (2603:10a6:10:f4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5164.20; Thu, 21 Apr 2022 15:18:52 +0000 Received: from AM5EUR03FT026.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45e:cafe::56) by AS9PR06CA0234.outlook.office365.com (2603:10a6:20b:45e::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.15 via Frontend Transport; Thu, 21 Apr 2022 15:18:51 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; Received: from nebula.arm.com (40.67.248.234) by AM5EUR03FT026.mail.protection.outlook.com (10.152.16.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5186.14 via Frontend Transport; Thu, 21 Apr 2022 15:18:51 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Thu, 21 Apr 2022 15:18:51 +0000 Received: from e129171.cambridge.arm.com (10.2.80.38) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2308.27 via Frontend Transport; Thu, 21 Apr 2022 15:18:51 +0000 From: Luis Machado To: Subject: [PATCH, v2] [AArch64] Support AArch64 MTE memory tag dumps in core files Date: Thu, 21 Apr 2022 16:18:41 +0100 Message-ID: <20220421151841.127371-1-luis.machado@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220331140457.9237-1-luis.machado@arm.com> References: <20220331140457.9237-1-luis.machado@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-Office365-Filtering-Correlation-Id: 6eabe415-5f8c-4153-bd33-08da23aa428c X-MS-TrafficTypeDiagnostic: DBBPR08MB4629:EE_|VE1EUR03FT021:EE_|DB8PR08MB5516: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: PSOvP/9vGascq7p9hjRkUubioHoUeLwZVm6F3yl0ck87ZucPBpzTLFO9Xi6W21HF7CDdPgCchCbEX10vEF5eTrsop2zsNw59Hzrtms0xjHQteuWBaAh/SOlv2RMFDF6m6rWxqr7hSQhr85EvBi4cyOzJ6nn9pMdwV8RLMjFuF1TyKbJxJ4AjBEpXiN6DD2r7L0WRupR2kpvV0FWhSHt/a3cuKbvgf5YtWGVzROwE+UEGYdFpH2BiTcL46uoPjXQRH1RFXeDsvsnvgggq1XJYenAvYj0Unvds30Seu0ep4K9icvfxAGnLlzfCzd+JdxxRgg97jqH+QrBCtCYmE12xkrgV+Ni0wzknDT8+uYcN9MHqKk5i/ogLVUCbJkqb4Bk6Eb+ct5x7rnQzOvFPUH7tC0A83614IkLg1ljdMw2u69PWXhC43ntB905hqJj00g8rvAl7u8jXpJfdmokLPuFvr4zmEGFZ6wWwzemM+SV2bThOg5uzas5LDX6sbGCn1Ojwbzhr44eRmI+kgWhckL/TLT3i5N44eRz8YWmj2yoLvxQUq1AQMHJ+k6PjQMN6JJLOh0W/AYETx6KqIJRNQumrYt8dgHC+a2yYeLRWTo7J8mgu9GqfJL5eJMM9q+I254X5EwLd68N3wJKCBCJhOb4krUumeYeQFe5QxQ+qLCV/rRZeaMR2I9IuWg0axcME+omLDU5BggU9b30q6CYXxL5lDg== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(26005)(186003)(86362001)(81166007)(4326008)(336012)(6666004)(8676002)(7696005)(70586007)(70206006)(426003)(82310400005)(36756003)(40460700003)(2906002)(1076003)(356005)(36860700001)(508600001)(2616005)(5660300002)(47076005)(6916009)(316002)(8936002)(44832011)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR08MB4629 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 36985f93-5d79-40ed-4741-08da23aa3deb X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0SfRF5RBwMev2H/uCm0XDEpe2yhKCRXw+eKvKBniid0UPQWcxjp75C7xQ6NeUwlpVy605gG0CibKt3/XP15rr3c6cDAIF3hcsnbvKMCjsb4xqLFsLyIMys03ObYqMafMQKNW3ERVNd8cBi7IU36HuNZwbDhBcbO8S+hhZq3mL1A166G8xBWL5NBLhiwpVUupzmvqD2YRs+dEVdv71RqP2ASKlR8cEDpmZTXfNORPgLCg1x7Uq4NlNMtMyD/eHavW6F/lPPqC01AcHfzYimuYAj+13ZDkztT26KPdl4x3egSLfeaSLmKio3FhmwNHXCBLzhduOtxsIERTRVV6GqwajoxOCrnQhchFEyNgxwgZ6g7op5CJozOs1x7RsVWxdp+wscayHsNSqrJ7hKtPVGXnm9o75tCHva1sY3YcxFSneWQukN9e01OqOB7d9DjnlVrACZ2Afo4KByo4sLmuKLHrXUjcRpBqpSsQSwNnDnya911s2QweG34C3fVl05ceMUEEFOON6H9y39jDnzhAlMexchMyb7onYE0XJIrpOS7BBxJ+5Rz2su4CpZ5FeFjNxz0pUerTC+8lcE0q8UGW1vAQCOoqgV9xyy+3t0mAr8chH9We42ziyEwLqjI3WCRf65IwlsvHgmOfHWYUufvUjaKEV8vUHe++OuYtXXUMbbLrcR1fu7lsJkfuaVOGOxZiE3d8 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)(40470700004)(46966006)(36840700001)(81166007)(82310400005)(70206006)(70586007)(6916009)(336012)(426003)(36756003)(36860700001)(47076005)(316002)(8676002)(4326008)(2906002)(1076003)(8936002)(508600001)(86362001)(107886003)(26005)(2616005)(40460700003)(186003)(44832011)(5660300002)(6666004)(7696005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2022 15:18:59.3185 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6eabe415-5f8c-4153-bd33-08da23aa428c 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: VE1EUR03FT021.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR08MB5516 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_PASS, TXREP, 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: Thu, 21 Apr 2022 15:19:05 -0000 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 | 88 ++++++++++++++++++++++++++++++++++++++++++++ binutils/readelf.c | 1 + include/elf/common.h | 5 +++ 3 files changed, 94 insertions(+) diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 4926bab9cf2..a79a6849a3a 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -8158,6 +8158,88 @@ 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_ARM_MEMTAG_MTE segment type. */ + if (hdr == NULL || hdr->p_type != PT_ARM_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_ARM_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 +10141,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..bf574509cb0 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_ARM_MEMTAG_MTE: return "ARM_MEMTAG_MTE"; default: return NULL; } } diff --git a/include/elf/common.h b/include/elf/common.h index e4bc53e35b4..4eeaf3d4949 100644 --- a/include/elf/common.h +++ b/include/elf/common.h @@ -500,6 +500,11 @@ #define PT_GNU_MBIND_LO (PT_LOOS + 0x474e555) #define PT_GNU_MBIND_HI (PT_GNU_MBIND_LO + PT_GNU_MBIND_NUM - 1) +/* ARM memory tag segment types. */ + +/* MTE memory tag segment type. */ +#define PT_ARM_MEMTAG_MTE (PT_LOPROC + 0x1) + /* Program segment permissions, in program header p_flags field. */ #define PF_X (1 << 0) /* Segment is executable */ -- 2.25.1