]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd/binutils: Handle Morello memory tag core dump segments.
authorJohn Baldwin <jhb@FreeBSD.org>
Fri, 2 Sep 2022 00:01:51 +0000 (17:01 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Fri, 2 Sep 2022 00:01:51 +0000 (17:01 -0700)
This is similar to the support for MTE core dump segments.

bfd/elfnn-aarch64.c
binutils/readelf.c
include/elf/aarch64.h

index 6e633074fe40b4f7b114b4883fc693f68f4b453d..c1aef487f7b23d09e5c4a4f5f6f2aac456775da4 100644 (file)
@@ -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;
index 7375e41bbb645185981e0e87e3c8569df6abda54..87f88fe371b5e101bcbf44e20d58fa8d77f76e68 100644 (file)
@@ -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;
     }
 }
index e9a6c437d3a2b6a4ebe6cff8826412f6de54b646..c9e6325d20a56d44615bca89e00f154bf92fa120 100644 (file)
@@ -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.  */