diff mbox series

[RFC,5/9] targhooks: add new target hook TARGET_MEMTAG_TAG_MEMORY

Message ID 20241107213937.362703-6-indu.bhagat@oracle.com
State New
Headers show
Series Add -fsanitize=memtag | expand

Commit Message

Indu Bhagat Nov. 7, 2024, 9:39 p.m. UTC
Add a new target hook TARGET_MEMTAG_TAG_MEMORY to tag (and untag)
memory.  The default implementation is empty.

Hardware-assisted sanitizers on architectures providing instructions to
tag/untag memory can then make use of this target hook.  On AArch64,
e.g., the MEMTAG sanitizer will use this hook to tag and untag memory
using MTE insns.

gcc/ChangeLog:

	* doc/tm.texi: Re-generate.
	* doc/tm.texi.in: Add documentation for new target hooks.
	* target.def: Add new hook.
	* targhooks.cc (default_memtag_tag_memory): New hook.
	* targhooks.h (default_memtag_tag_memory): Likewise.
---
 gcc/doc/tm.texi    | 5 +++++
 gcc/doc/tm.texi.in | 2 ++
 gcc/target.def     | 6 ++++++
 gcc/targhooks.cc   | 7 +++++++
 gcc/targhooks.h    | 1 +
 5 files changed, 21 insertions(+)
diff mbox series

Patch

diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
index 4deb3d2c283a..fbc8efb7ede9 100644
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -12820,6 +12820,11 @@  Store the result in @var{target} if convenient.
 The default clears the top byte of the original pointer.
 @end deftypefn
 
+@deftypefn {Target Hook} rtx TARGET_MEMTAG_TAG_MEMORY (rtx @var{base}, rtx @var{size}, rtx @var{tagged_pointer})
+Tag memory at address @var{base} TBD FIXME.
+The default clears the top byte of the original pointer.
+@end deftypefn
+
 @deftypevr {Target Hook} bool TARGET_HAVE_SHADOW_CALL_STACK
 This value is true if the target platform supports
 @option{-fsanitize=shadow-call-stack}.  The default value is false.
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
index 9f147ccb95cc..b25ef8cc0f91 100644
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -8121,6 +8121,8 @@  maintainer is familiar with.
 
 @hook TARGET_MEMTAG_UNTAGGED_POINTER
 
+@hook TARGET_MEMTAG_TAG_MEMORY
+
 @hook TARGET_HAVE_SHADOW_CALL_STACK
 
 @hook TARGET_HAVE_LIBATOMIC
diff --git a/gcc/target.def b/gcc/target.def
index 523ae7ec9aaa..415cb8076ca4 100644
--- a/gcc/target.def
+++ b/gcc/target.def
@@ -7419,6 +7419,12 @@  Store the result in @var{target} if convenient.\n\
 The default clears the top byte of the original pointer.",
   rtx, (rtx tagged_pointer, rtx target), default_memtag_untagged_pointer)
 
+DEFHOOK
+(tag_memory,
+ "Tag memory at address @var{base} TBD FIXME.\n\
+The default clears the top byte of the original pointer.",
+  rtx, (rtx base, rtx size, rtx tagged_pointer), default_memtag_tag_memory)
+
 HOOK_VECTOR_END (memtag)
 #undef HOOK_PREFIX
 #define HOOK_PREFIX "TARGET_"
diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc
index 304b35ed7724..aa5d38a69fde 100644
--- a/gcc/targhooks.cc
+++ b/gcc/targhooks.cc
@@ -2843,4 +2843,11 @@  default_memtag_untagged_pointer (rtx tagged_pointer, rtx target)
   return untagged_base;
 }
 
+/* The default implementation of TARGET_MEMTAG_TAG_MEMORY.  */
+rtx
+default_memtag_tag_memory (rtx, rtx, rtx)
+{
+  gcc_unreachable ();
+}
+
 #include "gt-targhooks.h"
diff --git a/gcc/targhooks.h b/gcc/targhooks.h
index 2704d6008f14..44f5a28e0dd2 100644
--- a/gcc/targhooks.h
+++ b/gcc/targhooks.h
@@ -308,5 +308,6 @@  extern rtx default_memtag_add_tag (rtx, poly_int64, uint8_t);
 extern rtx default_memtag_set_tag (rtx, rtx, rtx);
 extern rtx default_memtag_extract_tag (rtx, rtx);
 extern rtx default_memtag_untagged_pointer (rtx, rtx);
+extern rtx default_memtag_tag_memory (rtx, rtx, rtx);
 
 #endif /* GCC_TARGHOOKS_H */