config_sanitizers.mk revision 4c92a681272519fa17c2b4a8bc807e2e7fe8e974
1############################################## 2## Perform configuration steps for sanitizers. 3############################################## 4 5my_sanitize := $(strip $(LOCAL_SANITIZE)) 6 7# Keep compatibility for LOCAL_ADDRESS_SANITIZER until all targets have moved to 8# `LOCAL_SANITIZE := address`. 9ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true) 10 my_sanitize += address 11endif 12 13# And `LOCAL_SANITIZE := never`. 14ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),false) 15 my_sanitize := never 16endif 17 18# Don't apply sanitizers to NDK code. 19ifdef LOCAL_SDK_VERSION 20 my_sanitize := never 21endif 22 23# Configure SANITIZE_HOST. 24ifdef LOCAL_IS_HOST_MODULE 25 ifeq ($(my_sanitize),) 26 my_sanitize := $(strip $(SANITIZE_HOST)) 27 28 # SANTIZIZE_HOST=true is a deprecated way to say SANITIZE_HOST=address. 29 ifeq ($(my_sanitize),true) 30 my_sanitize := address 31 endif 32 33 # SANITIZE_HOST is only in effect if the module is already using clang (host 34 # modules that haven't set `LOCAL_CLANG := false` and device modules that 35 # have set `LOCAL_CLANG := true`. 36 ifneq ($(my_clang),true) 37 my_sanitize := 38 endif 39 endif 40endif 41 42ifeq ($(my_sanitize),never) 43 my_sanitize := 44endif 45 46# Sanitizers can only be used with clang. 47ifneq ($(my_clang),true) 48 ifneq ($(my_sanitize),) 49 $(error $(LOCAL_PATH): $(LOCAL_MODULE): Use of sanitizers requires LOCAL_CLANG := true) 50 endif 51endif 52 53unknown_sanitizers := $(filter-out address, \ 54 $(filter-out undefined,$(my_sanitize))) 55 56ifneq ($(unknown_sanitizers),) 57 $(error Unknown sanitizers: $(unknown_sanitizers)) 58endif 59 60ifneq ($(my_sanitize),) 61 fsanitize_arg := $(subst $(space),$(comma),$(my_sanitize)), 62 my_cflags += -fsanitize=$(fsanitize_arg) 63 64 ifdef LOCAL_IS_HOST_MODULE 65 my_ldflags += -fsanitize=$(fsanitize_arg) 66 endif 67endif 68 69ifneq ($(filter address,$(my_sanitize)),) 70 # Frame pointer based unwinder in ASan requires ARM frame setup. 71 LOCAL_ARM_MODE := arm 72 my_cflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS) 73 my_ldflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS) 74 ifdef LOCAL_IS_HOST_MODULE 75 # -nodefaultlibs (provided with libc++) prevents the driver from linking 76 # libraries needed with -fsanitize=address. http://b/18650275 (WAI) 77 my_ldlibs += -ldl -lpthread 78 else 79 my_shared_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES) 80 my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES) 81 endif 82endif 83 84ifneq ($(filter undefined,$(my_sanitize)),) 85 ifdef LOCAL_IS_HOST_MODULE 86 my_ldlibs += -ldl 87 else 88 $(error ubsan is not yet supported on the target) 89 endif 90endif 91