From 3330b2fe0beeee3d35f50b99f2a146b5c8f16ea7 Mon Sep 17 00:00:00 2001 From: Evgenii Stepanov Date: Wed, 13 Jan 2021 12:14:55 -0800 Subject: [PATCH] Support memtag_heap sanitizer type in make. Bug: b/135772972 Test: build with SANITIZE_TARGET=memtag_heap Change-Id: I0f66649e7a689c9f050dc49974e218b56698254c --- core/config_sanitizers.mk | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/core/config_sanitizers.mk b/core/config_sanitizers.mk index c92cea2688..f39b84a5c7 100644 --- a/core/config_sanitizers.mk +++ b/core/config_sanitizers.mk @@ -53,6 +53,18 @@ ifneq ($(filter cfi, $(my_global_sanitize)),) endif endif +# Disable global memtag_heap in excluded paths +ifneq ($(filter memtag_heap, $(my_global_sanitize)),) + combined_exclude_paths := $(MEMTAG_HEAP_EXCLUDE_PATHS) \ + $(PRODUCT_MEMTAG_HEAP_EXCLUDE_PATHS) + + ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_exclude_paths)),\ + $(filter $(dir)%,$(LOCAL_PATH)))),) + my_global_sanitize := $(filter-out memtag_heap,$(my_global_sanitize)) + my_global_sanitize_diag := $(filter-out memtag_heap,$(my_global_sanitize_diag)) + endif +endif + ifneq ($(my_global_sanitize),) my_sanitize := $(my_global_sanitize) $(my_sanitize) endif @@ -116,6 +128,25 @@ ifeq ($(filter cfi, $(my_sanitize)),) endif endif +# Enable memtag_heap in included paths (for Arm64 only). +ifeq ($(filter memtag_heap, $(my_sanitize)),) + ifneq ($(filter arm64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) + combined_sync_include_paths := $(MEMTAG_HEAP_SYNC_INCLUDE_PATHS) \ + $(PRODUCT_MEMTAG_HEAP_SYNC_INCLUDE_PATHS) + combined_async_include_paths := $(MEMTAG_HEAP_ASYNC_INCLUDE_PATHS) \ + $(PRODUCT_MEMTAG_HEAP_ASYNC_INCLUDE_PATHS) + + ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_sync_include_paths)),\ + $(filter $(dir)%,$(LOCAL_PATH)))),) + my_sanitize := memtag_heap $(my_sanitize) + my_sanitize_diag := memtag_heap $(my_sanitize) + else ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_async_include_paths)),\ + $(filter $(dir)%,$(LOCAL_PATH)))),) + my_sanitize := memtag_heap $(my_sanitize) + endif + endif +endif + # If CFI is disabled globally, remove it from my_sanitize. ifeq ($(strip $(ENABLE_CFI)),false) my_sanitize := $(filter-out cfi,$(my_sanitize)) @@ -164,6 +195,7 @@ 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)) endif ifneq ($(filter hwaddress,$(my_sanitize)),) @@ -183,6 +215,20 @@ ifneq ($(filter hwaddress,$(my_sanitize)),) endif endif +ifneq ($(filter memtag_heap,$(my_sanitize)),) + # Add memtag ELF note. + 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 + # This is all that memtag_heap does - it is not an actual -fsanitize argument. + # Remove it from the list. + my_sanitize := $(filter-out memtag_heap,$(my_sanitize)) +endif + +my_sanitize_diag := $(filter-out memtag_heap,$(my_sanitize_diag)) + # 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. ifneq ($(filter thread,$(my_sanitize)),)