2014-11-01 07:23:08 +08:00
|
|
|
##############################################
|
|
|
|
## Perform configuration steps for sanitizers.
|
|
|
|
##############################################
|
|
|
|
|
|
|
|
# Configure SANITIZE_HOST.
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
2015-04-17 07:21:02 +08:00
|
|
|
my_sanitize_host := $(strip $(SANITIZE_HOST))
|
2014-11-01 07:23:08 +08:00
|
|
|
endif
|
2015-04-17 07:21:02 +08:00
|
|
|
|
|
|
|
# SANTIZIZE_HOST=true is a deprecated way to say SANITIZE_HOST=address.
|
|
|
|
ifeq ($(my_sanitize_host),true)
|
|
|
|
my_sanitize_host := address
|
2014-11-01 07:23:08 +08:00
|
|
|
endif
|
2015-04-17 07:21:02 +08:00
|
|
|
|
|
|
|
# `LOCAL_CLANG := false` disables SANITIZE_HOST.
|
|
|
|
ifeq ($(my_clang),false)
|
|
|
|
my_sanitize_host :=
|
2014-11-01 07:23:08 +08:00
|
|
|
endif
|
|
|
|
|
2015-04-17 07:21:02 +08:00
|
|
|
my_sanitize := $(strip $(LOCAL_SANITIZE))
|
2014-12-12 10:56:26 +08:00
|
|
|
|
|
|
|
# Keep compatibility for LOCAL_ADDRESS_SANITIZER until all targets have moved to
|
|
|
|
# `LOCAL_SANITIZE := address`.
|
2014-11-01 07:23:08 +08:00
|
|
|
ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true)
|
2014-12-12 10:56:26 +08:00
|
|
|
my_sanitize += address
|
|
|
|
endif
|
|
|
|
|
2015-04-17 07:21:02 +08:00
|
|
|
# And `LOCAL_SANITIZE := never`.
|
|
|
|
ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),false)
|
|
|
|
my_sanitize := never
|
|
|
|
endif
|
|
|
|
|
2014-12-12 10:56:26 +08:00
|
|
|
# Don't apply sanitizers to NDK code.
|
|
|
|
ifdef LOCAL_SDK_VERSION
|
2015-04-17 07:21:02 +08:00
|
|
|
my_sanitize := never
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(my_sanitize),)
|
|
|
|
my_sanitize := $(my_sanitize_host)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(my_sanitize),never)
|
2014-12-12 10:56:26 +08:00
|
|
|
my_sanitize :=
|
|
|
|
endif
|
|
|
|
|
|
|
|
unknown_sanitizers := $(filter-out address, \
|
|
|
|
$(filter-out undefined,$(my_sanitize)))
|
|
|
|
|
|
|
|
ifneq ($(unknown_sanitizers),)
|
|
|
|
$(error Unknown sanitizers: $(unknown_sanitizers))
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(my_sanitize),)
|
2014-11-01 07:23:08 +08:00
|
|
|
my_clang := true
|
2014-12-12 10:56:26 +08:00
|
|
|
|
|
|
|
fsanitize_arg := $(subst $(space),$(comma),$(my_sanitize)),
|
|
|
|
my_cflags += -fsanitize=$(fsanitize_arg)
|
|
|
|
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
|
|
|
my_ldflags += -fsanitize=$(fsanitize_arg)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(filter address,$(my_sanitize)),)
|
2014-11-01 07:23:08 +08: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 10:56:26 +08:00
|
|
|
# -nodefaultlibs (provided with libc++) prevents the driver from linking
|
|
|
|
# libraries needed with -fsanitize=address. http://b/18650275 (WAI)
|
|
|
|
my_ldlibs += -ldl -lpthread
|
|
|
|
else
|
|
|
|
my_shared_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES)
|
|
|
|
my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(filter undefined,$(my_sanitize)),)
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
|
|
|
my_ldlibs += -ldl
|
2014-11-01 07:23:08 +08:00
|
|
|
else
|
2014-12-12 10:56:26 +08:00
|
|
|
$(error ubsan is not yet supported on the target)
|
2014-11-01 07:23:08 +08:00
|
|
|
endif
|
|
|
|
endif
|