From 1264fcc95abda4a1d04a0ffebe1f8c8d39a2fd49 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Fri, 26 Aug 2022 16:04:59 -0700 Subject: [PATCH] [make] Add memtag-stack sanitizer, switch to linker-generated notes. This change depends on the following toolchain commit: https://reviews.llvm.org/D118948 Bug: b/174878242 Change-Id: Id67503a5c0983c9ae6fc29f158f4d20bca778e9f --- core/config_sanitizers.mk | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk index a0ff11951a..f25ce720aa 100644 --- a/core/config_sanitizers.mk +++ b/core/config_sanitizers.mk @@ -161,9 +161,11 @@ ifeq ($(strip $(ENABLE_CFI)),false) my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag)) endif -# Also disable CFI if ASAN is enabled. +# Also disable CFI and MTE if ASAN is enabled. ifneq ($(filter address,$(my_sanitize)),) my_sanitize := $(filter-out cfi,$(my_sanitize)) + my_sanitize := $(filter-out memtag_stack,$(my_sanitize)) + my_sanitize := $(filter-out memtag_heap,$(my_sanitize)) my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag)) endif @@ -205,10 +207,13 @@ endif ifneq ($(filter arm x86 x86_64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) my_sanitize := $(filter-out hwaddress,$(my_sanitize)) my_sanitize := $(filter-out memtag_heap,$(my_sanitize)) + my_sanitize := $(filter-out memtag_stack,$(my_sanitize)) endif ifneq ($(filter hwaddress,$(my_sanitize)),) my_sanitize := $(filter-out address,$(my_sanitize)) + my_sanitize := $(filter-out memtag_stack,$(my_sanitize)) + my_sanitize := $(filter-out memtag_heap,$(my_sanitize)) my_sanitize := $(filter-out thread,$(my_sanitize)) my_sanitize := $(filter-out cfi,$(my_sanitize)) endif @@ -224,21 +229,27 @@ ifneq ($(filter hwaddress,$(my_sanitize)),) endif endif -ifneq ($(filter memtag_heap,$(my_sanitize)),) - # Add memtag ELF note. - ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) - ifneq ($(filter memtag_heap,$(my_sanitize_diag)),) - my_whole_static_libraries += note_memtag_heap_sync - else - my_whole_static_libraries += note_memtag_heap_async - endif +ifneq ($(filter memtag_heap memtag_stack,$(my_sanitize)),) + ifneq ($(filter memtag_heap,$(my_sanitize_diag)),) + my_cflags += -fsanitize-memtag-mode=sync + my_sanitize_diag := $(filter-out memtag_heap,$(my_sanitize_diag)) + else + my_cflags += -fsanitize-memtag-mode=async endif - # This is all that memtag_heap does - it is not an actual -fsanitize argument. - # Remove it from the list. +endif + +ifneq ($(filter memtag_heap,$(my_sanitize)),) + my_cflags += -fsanitize=memtag-heap my_sanitize := $(filter-out memtag_heap,$(my_sanitize)) endif -my_sanitize_diag := $(filter-out memtag_heap,$(my_sanitize_diag)) +ifneq ($(filter memtag_stack,$(my_sanitize)),) + my_cflags += -fsanitize=memtag-stack + my_cflags += -march=armv8a+memtag + my_ldflags += -march=armv8a+memtag + my_asflags += -march=armv8a+memtag + my_sanitize := $(filter-out memtag_stack,$(my_sanitize)) +endif # TSAN is not supported on 32-bit architectures. For non-multilib cases, make # its use an error. For multilib cases, don't use it for the 32-bit case.