[AArch64] MTE corefile support

Message ID 20210518202027.3492146-1-luis.machado@linaro.org
State New
Headers show
Series
  • [AArch64] MTE corefile support
Related show

Commit Message

H.J. Lu via Binutils May 18, 2021, 8:20 p.m.
For MTE, we need core files to carry information about the memory tags. That
way we can look up the tags when inspecting the data and it will show
potentially conflicting tags for particular pointers/memory.

This patch defines a new NT_MEMTAG note type (generic) and also a new tag dump
format (NT_MEMTAG_TYPE_AARCH_MTE) that is ARM-specific.

bfd/ChangeLog:

YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org>

	* elf.c (elfcore_make_memtag_note_section): New function.
	(elfcore_grok_note): Handle NT_MEMTAG note types.

binutils/ChangeLog:

YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org>

	* readelf.c (get_note_type): Handle NT_MEMTAG note types.

include/ChangeLog:

YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org>

	* elf/common.h (NT_MEMTAG): New constant.
	(NT_MEMTAG_TYPE_AARCH_MTE): New constant.
---
 bfd/elf.c            | 19 +++++++++++++++++++
 binutils/readelf.c   |  2 ++
 include/elf/common.h |  7 +++++++
 3 files changed, 28 insertions(+)

-- 
2.25.1

Comments

H.J. Lu via Binutils May 21, 2021, 9:41 a.m. | #1
Hi Luis,

> bfd/ChangeLog:

> 

> YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org>

> 

> 	* elf.c (elfcore_make_memtag_note_section): New function.

> 	(elfcore_grok_note): Handle NT_MEMTAG note types.

> 

> binutils/ChangeLog:

> 

> YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org>

> 

> 	* readelf.c (get_note_type): Handle NT_MEMTAG note types.

> 

> include/ChangeLog:

> 

> YYYY-MM-DD  Luis Machado  <luis.machado@linaro.org>

> 

> 	* elf/common.h (NT_MEMTAG): New constant.

> 	(NT_MEMTAG_TYPE_AARCH_MTE): New constant.


Approved and applied.

Cheers
   Nick

Patch

diff --git a/bfd/elf.c b/bfd/elf.c
index 8ed1623dfc1..a4cfaf1512f 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -9597,6 +9597,23 @@  elfcore_make_auxv_note_section (bfd *abfd, Elf_Internal_Note *note,
   return true;
 }
 
+static bool
+elfcore_make_memtag_note_section (bfd *abfd, Elf_Internal_Note *note,
+				  size_t offs)
+{
+  asection *sect = bfd_make_section_anyway_with_flags (abfd, ".memtag",
+						       SEC_HAS_CONTENTS);
+
+  if (sect == NULL)
+    return false;
+
+  sect->size = note->descsz - offs;
+  sect->filepos = note->descpos + offs;
+  sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32;
+
+  return true;
+}
+
 /* prstatus_t exists on:
      solaris 2.5+
      linux 2.[01] + glibc
@@ -10657,6 +10674,8 @@  elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note)
       return elfcore_make_note_pseudosection (abfd, ".note.linuxcore.siginfo",
 					      note);
 
+    case NT_MEMTAG:
+      return elfcore_make_memtag_note_section (abfd, note, 0);
     }
 }
 
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 8357df69363..5da49a223af 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -18702,6 +18702,8 @@  get_note_type (Filedata * filedata, unsigned e_type)
 	return _("NT_SIGINFO (siginfo_t data)");
       case NT_FILE:
 	return _("NT_FILE (mapped files)");
+      case NT_MEMTAG:
+	return _("NT_MEMTAG (memory tags)");
       default:
 	break;
       }
diff --git a/include/elf/common.h b/include/elf/common.h
index f36bb0b80a2..735528f7488 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -682,9 +682,16 @@ 
 #define NT_SIGINFO	0x53494749	/* Fields of siginfo_t.  */
 #define NT_FILE		0x46494c45	/* Description of mapped files.  */
 
+/* NT_MEMTAG record types.  */
+
+/* ARM-specific NT_MEMTAG types.  */
+#define NT_MEMTAG_TYPE_AARCH_MTE  0x400	/* MTE memory tags for AArch64.  */
+
 /* The range 0xff000000 to 0xffffffff is set aside for notes that don't
    originate from any particular operating system.  */
 #define NT_GDB_TDESC	0xff000000	/* Contains copy of GDB's target description XML.  */
+#define NT_MEMTAG	0xff000001	/* Contains a copy of the memory
+					   tags */
 
 /* Note segments for core files on dir-style procfs systems.  */