diff options
author | Matthew Malcomson <matthew.malcomson@arm.com> | 2020-11-25 16:31:43 +0000 |
---|---|---|
committer | Matthew Malcomson <matthew.malcomson@arm.com> | 2020-11-25 16:35:39 +0000 |
commit | 3bd8783207760cc805d8a4e64e5ac92ca508a711 (patch) | |
tree | 1d270dc01883654cbe0681e5f06c2aea5c1e460f /gcc/toplev.c | |
parent | 170e618ef559a9b1220174c1d33cd7e5b1045cc8 (diff) | |
download | gcc-3bd8783207760cc805d8a4e64e5ac92ca508a711.zip gcc-3bd8783207760cc805d8a4e64e5ac92ca508a711.tar.gz gcc-3bd8783207760cc805d8a4e64e5ac92ca508a711.tar.bz2 |
libsanitizer: options: Add hwasan flags and argument parsing
These flags can't be used at the same time as any of the other
sanitizers.
We add an equivalent flag to -static-libasan in -static-libhwasan to
ensure static linking.
The -fsanitize=kernel-hwaddress option is for compiling targeting the
kernel. This flag has defaults to match the LLVM implementation and
sets some other behaviors to work in the kernel (e.g. accounting for
the fact that the stack pointer will have 0xff in the top byte and to not
call the userspace library initialisation routines).
The defaults are that we do not sanitize variables on the stack and
always recover from a detected bug.
Since we are introducing a few more conflicts between sanitizer flags we
refactor the checking for such conflicts to use a helper function which
makes checking for such conflicts more easy and consistent.
We introduce a backend hook `targetm.memtag.can_tag_addresses` that
indicates to the mid-end whether a target has a feature like AArch64 TBI
where the top byte of an address is ignored.
Without this feature hwasan sanitization is not done.
gcc/ChangeLog:
* common.opt (flag_sanitize_recover): Default for kernel
hwaddress.
(static-libhwasan): New cli option.
* config/aarch64/aarch64.c (aarch64_can_tag_addresses): New.
(TARGET_MEMTAG_CAN_TAG_ADDRESSES): New.
* config/gnu-user.h (LIBHWASAN_EARLY_SPEC): hwasan equivalent of
asan command line flags.
* cppbuiltin.c (define_builtin_macros_for_compilation_flags):
Add hwasan equivalent of __SANITIZE_ADDRESS__.
* doc/invoke.texi: Document hwasan command line flags.
* doc/tm.texi: Document new hook.
* doc/tm.texi.in: Document new hook.
* flag-types.h (enum sanitize_code): New sanitizer values.
* gcc.c (STATIC_LIBHWASAN_LIBS): New macro.
(LIBHWASAN_SPEC): New macro.
(LIBHWASAN_EARLY_SPEC): New macro.
(SANITIZER_EARLY_SPEC): Update to include hwasan.
(SANITIZER_SPEC): Update to include hwasan.
(sanitize_spec_function): Use hwasan options.
* opts.c (finish_options): Describe conflicts between address
sanitizers.
(find_sanitizer_argument): New.
(report_conflicting_sanitizer_options): New.
(sanitizer_opts): Introduce new sanitizer flags.
(common_handle_option): Add defaults for kernel sanitizer.
* params.opt (hwasan--instrument-stack): New
(hwasan-random-frame-tag): New
(hwasan-instrument-allocas): New
(hwasan-instrument-reads): New
(hwasan-instrument-writes): New
(hwasan-instrument-mem-intrinsics): New
* target.def (HOOK_PREFIX): Add new hook.
(can_tag_addresses): Add new hook under memtag prefix.
* targhooks.c (default_memtag_can_tag_addresses): New.
* targhooks.h (default_memtag_can_tag_addresses): New decl.
* toplev.c (process_options): Ensure hwasan only on
architectures that advertise the possibility.
Diffstat (limited to 'gcc/toplev.c')
-rw-r--r-- | gcc/toplev.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/toplev.c b/gcc/toplev.c index e0e0e04..2a3e7c0 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -1853,6 +1853,15 @@ process_options (void) flag_sanitize &= ~SANITIZE_ADDRESS; } + /* HWAsan requires top byte ignore feature in the backend. */ + if (flag_sanitize & SANITIZE_HWADDRESS + && ! targetm.memtag.can_tag_addresses ()) + { + warning_at (UNKNOWN_LOCATION, 0, "%qs is not supported for this target", + "-fsanitize=hwaddress"); + flag_sanitize &= ~SANITIZE_HWADDRESS; + } + /* Do not use IPA optimizations for register allocation if profiler is active or patchable function entries are inserted for run-time instrumentation or port does not emit prologue and epilogue as RTL. */ |