claudiu.zissulescu-iancule...@oracle.com writes:
> From: Claudiu Zissulescu <claudiu.zissulescu-iancule...@oracle.com>
>
> Add a new target hook TARGET_MEMTAG_COMPOSE_OFFSET_TAG to perform
> addition between two tags.
>
> The default of this hook is to byte add the inputs.
>
> Hardware-assisted sanitizers on architectures providing instructions
> to compose (add) two tags like in the case of AArch64.
>
> gcc/
>
>       * doc/tm.texi: Re-generate.
>       * doc/tm.texi.in: Add documentation for new target hooks.
>       * target.def: Add new hook.
>       * targhooks.cc (default_memtag_compose_offset_tag): New hook.
>       * targhooks.h (default_memtag_compose_offset_tag): Likewise.
>
> Signed-off-by: Claudiu Zissulescu <claudiu.zissulescu-iancule...@oracle.com>
> ---
>  gcc/doc/tm.texi    | 6 ++++++
>  gcc/doc/tm.texi.in | 2 ++
>  gcc/target.def     | 7 +++++++
>  gcc/targhooks.cc   | 7 +++++++
>  gcc/targhooks.h    | 2 +-
>  5 files changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
> index 3f87abf97b2..a4fba6d21b3 100644
> --- a/gcc/doc/tm.texi
> +++ b/gcc/doc/tm.texi
> @@ -12917,6 +12917,12 @@ 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_COMPOSE_OFFSET_TAG (rtx 
> @var{base_tag}, uint8_t @var{tag_offset})
> +Return an RTX that represnts the result of composing @var{tag_offset} with
> +the base tag @var{base_tag}.
> +The default of this hook is to byte add @var{tag_offset} to @var{base_tag}.
> +@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 040d26c40f1..ff381b486e1 100644
> --- a/gcc/doc/tm.texi.in
> +++ b/gcc/doc/tm.texi.in
> @@ -8138,6 +8138,8 @@ maintainer is familiar with.
>  
>  @hook TARGET_MEMTAG_UNTAGGED_POINTER
>  
> +@hook TARGET_MEMTAG_COMPOSE_OFFSET_TAG
> +
>  @hook TARGET_HAVE_SHADOW_CALL_STACK
>  
>  @hook TARGET_HAVE_LIBATOMIC
> diff --git a/gcc/target.def b/gcc/target.def
> index db48df9498d..89f96ca73c5 100644
> --- a/gcc/target.def
> +++ b/gcc/target.def
> @@ -7521,6 +7521,13 @@ 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
> +(compose_offset_tag,
> + "Return an RTX that represnts the result of composing @var{tag_offset} 
> with\n\
> +the base tag @var{base_tag}.\n\
> +The default of this hook is to byte add @var{tag_offset} to @var{base_tag}.",
> +  rtx, (rtx base_tag, uint8_t tag_offset), default_memtag_compose_offset_tag)
> +

I can't remember whether this was the result of a previous discussion,
sorry, but I'm not sure about the interface.  It seems that "base_tag"
really is a tag for the hwasan case, but is actually a tagged address
for MTE.  It therefore feels like these are two separate operations.

Since there is no immediate need to put the current hwasan behaviour
behind a hook, how about defining an interface specifically for memtag
sanitisation that explicitly has a tagged base address as its first
operand?

The memtag behaviour feels more like an optab than a hook to me, but I
realise that the other sanitiser stuff is heavily hook-based, so I won't
try to push for an optab here.

Thanks,
Richard

>  HOOK_VECTOR_END (memtag)
>  #undef HOOK_PREFIX
>  #define HOOK_PREFIX "TARGET_"
> diff --git a/gcc/targhooks.cc b/gcc/targhooks.cc
> index 0696f95adeb..cfea4a70403 100644
> --- a/gcc/targhooks.cc
> +++ b/gcc/targhooks.cc
> @@ -2904,4 +2904,11 @@ default_memtag_untagged_pointer (rtx tagged_pointer, 
> rtx target)
>    return untagged_base;
>  }
>  
> +/* The default implementation of TARGET_MEMTAG_COMPOSE_OFFSET_TAG.  */
> +rtx
> +default_memtag_compose_offset_tag (rtx base_tag, uint8_t tag_offset)
> +{
> +  return plus_constant (QImode, base_tag, tag_offset);
> +}
> +
>  #include "gt-targhooks.h"
> diff --git a/gcc/targhooks.h b/gcc/targhooks.h
> index c9e57e475dc..76afce71baa 100644
> --- a/gcc/targhooks.h
> +++ b/gcc/targhooks.h
> @@ -317,5 +317,5 @@ 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_compose_offset_tag (rtx, uint8_t);
>  #endif /* GCC_TARGHOOKS_H */

Reply via email to