2014-11-01 00:23:08 +01:00
|
|
|
##############################################
|
|
|
|
## Perform configuration steps for sanitizers.
|
|
|
|
##############################################
|
|
|
|
|
2015-04-17 01:21:02 +02:00
|
|
|
my_sanitize := $(strip $(LOCAL_SANITIZE))
|
2014-12-12 03:56:26 +01:00
|
|
|
|
2015-08-20 05:13:33 +02:00
|
|
|
# SANITIZE_HOST is only in effect if the module is already using clang (host
|
|
|
|
# modules that haven't set `LOCAL_CLANG := false` and device modules that
|
|
|
|
# have set `LOCAL_CLANG := true`.
|
|
|
|
my_global_sanitize :=
|
|
|
|
ifeq ($(my_clang),true)
|
2015-06-11 22:57:10 +02:00
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
2015-08-20 05:13:33 +02:00
|
|
|
my_global_sanitize := $(strip $(SANITIZE_HOST))
|
|
|
|
|
|
|
|
# SANITIZE_HOST=true is a deprecated way to say SANITIZE_HOST=address.
|
|
|
|
my_global_sanitize := $(subst true,address,$(my_global_sanitize))
|
2015-06-11 22:57:10 +02:00
|
|
|
else
|
2015-08-20 05:13:33 +02:00
|
|
|
my_global_sanitize := $(strip $(SANITIZE_TARGET))
|
2015-06-11 22:57:10 +02:00
|
|
|
endif
|
2015-08-20 05:13:33 +02:00
|
|
|
endif
|
2015-04-17 20:04:06 +02:00
|
|
|
|
2015-08-20 05:13:33 +02:00
|
|
|
# The sanitizer specified by the environment wins over the module.
|
|
|
|
ifneq ($(my_global_sanitize),)
|
|
|
|
my_sanitize := $(my_global_sanitize)
|
|
|
|
endif
|
2015-04-17 20:04:06 +02:00
|
|
|
|
2015-08-20 05:13:33 +02:00
|
|
|
# Don't apply sanitizers to NDK code.
|
|
|
|
ifdef LOCAL_SDK_VERSION
|
|
|
|
my_sanitize :=
|
2015-04-17 01:21:02 +02:00
|
|
|
endif
|
|
|
|
|
2015-08-20 05:13:33 +02:00
|
|
|
# Never always wins.
|
|
|
|
ifeq ($(LOCAL_SANITIZE),never)
|
2014-12-12 03:56:26 +01:00
|
|
|
my_sanitize :=
|
|
|
|
endif
|
|
|
|
|
2015-07-30 19:17:33 +02:00
|
|
|
# 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)),)
|
|
|
|
ifeq ($(my_32_64_bit_suffix),32)
|
|
|
|
ifeq ($(my_module_multilib),both)
|
|
|
|
my_sanitize := $(filter-out thread,$(my_sanitize))
|
|
|
|
else
|
|
|
|
$(error $(LOCAL_PATH): $(LOCAL_MODULE): TSAN cannot be used for 32-bit modules.)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2015-06-26 01:38:25 +02:00
|
|
|
# Undefined symbols can occur if a non-sanitized library links
|
|
|
|
# sanitized static libraries. That's OK, because the executable
|
|
|
|
# always depends on the ASan runtime library, which defines these
|
|
|
|
# symbols.
|
|
|
|
ifneq ($(strip $(SANITIZE_TARGET)),)
|
|
|
|
ifndef LOCAL_IS_HOST_MODULE
|
|
|
|
ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES)
|
|
|
|
ifeq ($(my_sanitize),)
|
|
|
|
my_allow_undefined_symbols := true
|
|
|
|
endif
|
|
|
|
endif
|
2015-07-21 01:32:53 +02:00
|
|
|
# Workaround for a bug in AddressSanitizer that breaks stack unwinding.
|
|
|
|
# https://code.google.com/p/address-sanitizer/issues/detail?id=387
|
|
|
|
# Revert when external/compiler-rt is updated past r236014.
|
|
|
|
LOCAL_PACK_MODULE_RELOCATIONS := false
|
2015-06-26 01:38:25 +02:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2015-04-17 18:48:33 +02:00
|
|
|
# Sanitizers can only be used with clang.
|
|
|
|
ifneq ($(my_clang),true)
|
|
|
|
ifneq ($(my_sanitize),)
|
|
|
|
$(error $(LOCAL_PATH): $(LOCAL_MODULE): Use of sanitizers requires LOCAL_CLANG := true)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2015-04-17 03:07:07 +02:00
|
|
|
ifneq ($(filter default-ub,$(my_sanitize)),)
|
|
|
|
my_sanitize := $(CLANG_DEFAULT_UB_CHECKS)
|
2014-12-12 03:56:26 +01:00
|
|
|
endif
|
|
|
|
|
2015-09-18 20:54:43 +02:00
|
|
|
ifneq ($(filter coverage,$(my_sanitize)),)
|
|
|
|
ifeq ($(filter address,$(my_sanitize)),)
|
|
|
|
$(error $(LOCAL_PATH): $(LOCAL_MODULE): Use of 'coverage' also requires 'address')
|
|
|
|
endif
|
|
|
|
my_cflags += -fsanitize-coverage=edge,indirect-calls,8bit-counters,trace-cmp
|
|
|
|
my_sanitize := $(filter-out coverage,$(my_sanitize))
|
|
|
|
endif
|
|
|
|
|
2014-12-12 03:56:26 +01:00
|
|
|
ifneq ($(my_sanitize),)
|
|
|
|
fsanitize_arg := $(subst $(space),$(comma),$(my_sanitize)),
|
|
|
|
my_cflags += -fsanitize=$(fsanitize_arg)
|
|
|
|
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
2015-06-17 08:27:34 +02:00
|
|
|
my_cflags += -fno-sanitize-recover=all
|
2014-12-12 03:56:26 +01:00
|
|
|
my_ldflags += -fsanitize=$(fsanitize_arg)
|
2015-08-14 02:25:10 +02:00
|
|
|
my_ldlibs += -lrt -ldl
|
2015-06-17 08:27:34 +02:00
|
|
|
else
|
|
|
|
my_cflags += -fsanitize-undefined-trap-on-error
|
|
|
|
my_cflags += -ftrap-function=abort
|
|
|
|
my_shared_libraries += libdl
|
2014-12-12 03:56:26 +01:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(filter address,$(my_sanitize)),)
|
2014-11-01 00:23:08 +01:00
|
|
|
# Frame pointer based unwinder in ASan requires ARM frame setup.
|
|
|
|
LOCAL_ARM_MODE := arm
|
|
|
|
my_cflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS)
|
|
|
|
my_ldflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS)
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
2014-12-12 03:56:26 +01:00
|
|
|
# -nodefaultlibs (provided with libc++) prevents the driver from linking
|
|
|
|
# libraries needed with -fsanitize=address. http://b/18650275 (WAI)
|
2015-06-17 08:27:34 +02:00
|
|
|
my_ldlibs += -lm -lpthread
|
2015-04-28 23:55:50 +02:00
|
|
|
my_ldflags += -Wl,--no-as-needed
|
2014-12-12 03:56:26 +01:00
|
|
|
else
|
2015-07-14 03:12:17 +02:00
|
|
|
my_cflags += -mllvm -asan-globals=0
|
2015-04-25 01:34:47 +02:00
|
|
|
# ASan runtime library must be the first in the link order.
|
|
|
|
my_shared_libraries := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RUNTIME_LIBRARY) \
|
|
|
|
$(my_shared_libraries) \
|
|
|
|
$(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES)
|
2014-12-12 03:56:26 +01:00
|
|
|
my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES)
|
2015-04-25 01:34:47 +02:00
|
|
|
my_ldflags += -Wl,-rpath,$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RPATH)
|
2015-08-18 01:13:24 +02:00
|
|
|
|
2015-07-11 03:06:51 +02:00
|
|
|
my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER)
|
2015-08-18 01:13:24 +02:00
|
|
|
# Make sure linker_asan get installed.
|
|
|
|
$(LOCAL_INSTALLED_MODULE) : | $(PRODUCT_OUT)$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER)
|
2014-12-12 03:56:26 +01:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(filter undefined,$(my_sanitize)),)
|
2015-06-17 08:27:34 +02:00
|
|
|
ifndef LOCAL_IS_HOST_MODULE
|
2014-12-12 03:56:26 +01:00
|
|
|
$(error ubsan is not yet supported on the target)
|
2014-11-01 00:23:08 +01:00
|
|
|
endif
|
|
|
|
endif
|
2015-04-17 03:08:44 +02:00
|
|
|
|
2015-04-28 20:26:45 +02:00
|
|
|
ifneq ($(strip $(LOCAL_SANITIZE_RECOVER)),)
|
|
|
|
recover_arg := $(subst $(space),$(comma),$(LOCAL_SANITIZE_RECOVER)),
|
2015-04-17 03:08:44 +02:00
|
|
|
my_cflags += -fsanitize-recover=$(recover_arg)
|
|
|
|
endif
|