On 5/1/25 7:03 AM, Richard Sandiford wrote:
Indu Bhagat <indu.bha...@oracle.com> writes:
[...]
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ffde9df85fd3..de651183a703 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -17079,6 +17079,14 @@ and @option{-fsanitize=kernel-hwaddress}.
  To disable instrumentation of builtin functions use
  @option{--param hwasan-instrument-mem-intrinsics=0}.
+@item memtag-instrument-stack
+Enable MTE tagging of statically sized stack-allocated variables.  This kind of
+code generation is enabled by default when using @option{-fsanitize=memtag}.
+

This is now removed.

+@item memtag-instrument-allocas
+Enable MTE tagging of dynamically sized stack-allocated variables.  This kind 
of
+code generation is enabled by default when using @option{-fsanitize=memtag}.
+

Since this is a target-independent parameter, it might be better
to use something more neutral than "MTE", such as "hardware memory
tagging".  Same elsewhere.


Done.  Changed this to:

@item memtag-instrument-allocas
Enable hardware-assisted memory tagging of dynamically sized stack-allocated
variables.  This kind of code generation is enabled by default when using
@option{-fsanitize=memtag-stack}.


[...]
diff --git a/gcc/opts.cc b/gcc/opts.cc
index 86c6691ecec4..00db662c32ef 100644
--- a/gcc/opts.cc
+++ b/gcc/opts.cc
[...]
@@ -2780,6 +2788,13 @@ common_handle_option (struct gcc_options *opts,
          SET_OPTION_IF_UNSET (opts, opts_set,
                               param_hwasan_instrument_allocas, 0);
        }
+      /* Memtag sanitizer implies HWASAN but with tags always generated by the
+        hardware randomly.  */
+      if (opts->x_flag_sanitize & SANITIZE_MEMTAG)
+       {
+         SET_OPTION_IF_UNSET (opts, opts_set,
+                              param_hwasan_random_frame_tag, 1);
+       }

Does this have any effect in practice?  The default seems to be 1,
so I would expect this to be a nop.  The pattern elsewhere in the
sanitiser code seems to be to use SET_OPTION_IF_UNSET only to turn
features off.


You're right.  This can be removed.

I recall now that what I wanted to achieve was to render users' usage of "--param hwasan-random-frame-tag=0" non-consequential when memtag sanitizer is in effect.

Looks like I need to handle in finish_options ().  Something like:

  if ((opts->x_flag_sanitize & SANITIZE_MEMTAG_STACK)
      && opts->x_param_hwasan_random_frame_tag == 0)
    {
       warning_at (loc, OPT_fsanitize_,
"%<--param hwasan-random-frame-tag=0%> is not supported with"
                   "%<-fsanitize=memtag-stack%>");
       opts->x_param_hwasan_random_frame_tag = 1;
    }

Reply via email to