From: John Baldwin Date: Fri, 2 Sep 2022 00:01:51 +0000 (-0700) Subject: bfd/binutils: Handle Morello memory tag core dump segments. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7bc890cf0605a7cd43e5e0b0d4f85a95c0afb7b1;p=thirdparty%2Fbinutils-gdb.git bfd/binutils: Handle Morello memory tag core dump segments. This is similar to the support for MTE core dump segments. --- diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 6e633074fe4..c1aef487f7b 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -10420,16 +10420,30 @@ elfNN_aarch64_section_from_phdr (bfd *abfd ATTRIBUTE_UNUSED, 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) + const char *sectname; + + if (hdr == NULL) return false; - if (hdr->p_filesz > 0) + /* Right now we only handle the PT_AARCH64_MEMTAG_* segment types. */ + switch (hdr->p_type) { + case PT_AARCH64_MEMTAG_MTE: /* 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"); + sectname = "memtag"; + break; + case PT_AARCH64_MEMTAG_CHERI: + sectname = "memtag.cheri"; + break; + default: + return false; + } + + if (hdr->p_filesz > 0) + { + asection *newsect = bfd_make_section_anyway (abfd, sectname); if (newsect == NULL) return false; @@ -10472,7 +10486,8 @@ elfNN_aarch64_modify_headers (bfd *abfd, /* 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 + if ((m->p_type != PT_AARCH64_MEMTAG_MTE + && m->p_type != PT_AARCH64_MEMTAG_CHERI) || bfd_get_format (abfd) != bfd_core) continue; @@ -10485,6 +10500,7 @@ elfNN_aarch64_modify_headers (bfd *abfd, p = elf_tdata (abfd)->phdr; p += m->idx; p->p_memsz = m->sections[0]->rawsize; + /* XXX: CHERI phdrs should set flags to cap permissions */ p->p_flags = 0; p->p_paddr = 0; p->p_align = 0; diff --git a/binutils/readelf.c b/binutils/readelf.c index 7375e41bbb6..87f88fe371b 100644 --- a/binutils/readelf.c +++ b/binutils/readelf.c @@ -4500,6 +4500,7 @@ get_aarch64_segment_type (unsigned long type) { case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT"; case PT_AARCH64_MEMTAG_MTE: return "AARCH64_MEMTAG_MTE"; + case PT_AARCH64_MEMTAG_CHERI: return "AARCH64_MEMTAG_CHERI"; default: return NULL; } } diff --git a/include/elf/aarch64.h b/include/elf/aarch64.h index e9a6c437d3a..c9e6325d20a 100644 --- a/include/elf/aarch64.h +++ b/include/elf/aarch64.h @@ -30,6 +30,9 @@ /* MTE memory tag segment type. */ #define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 0x2) +/* CHERI memory tag segment type. */ +#define PT_AARCH64_MEMTAG_CHERI (PT_LOPROC + 0x3) + /* Additional section types. */ #define SHT_AARCH64_ATTRIBUTES 0x70000003 /* Section holds attributes. */