2014-11-01 07:23:08 +08:00
|
|
|
##############################################
|
|
|
|
## Perform configuration steps for sanitizers.
|
|
|
|
##############################################
|
|
|
|
|
2015-04-17 07:21:02 +08:00
|
|
|
my_sanitize := $(strip $(LOCAL_SANITIZE))
|
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
|
|
|
|
|
2015-04-18 02:04:06 +08:00
|
|
|
# Configure SANITIZE_HOST.
|
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
|
|
|
ifeq ($(my_sanitize),)
|
|
|
|
my_sanitize := $(strip $(SANITIZE_HOST))
|
|
|
|
|
|
|
|
# SANTIZIZE_HOST=true is a deprecated way to say SANITIZE_HOST=address.
|
|
|
|
ifeq ($(my_sanitize),true)
|
|
|
|
my_sanitize := address
|
|
|
|
endif
|
|
|
|
|
|
|
|
# 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`.
|
|
|
|
ifneq ($(my_clang),true)
|
|
|
|
my_sanitize :=
|
|
|
|
endif
|
|
|
|
endif
|
2015-04-17 07:21:02 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(my_sanitize),never)
|
2014-12-12 10:56:26 +08:00
|
|
|
my_sanitize :=
|
|
|
|
endif
|
|
|
|
|
2015-04-18 00:48:33 +08: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 09:07:07 +08:00
|
|
|
ifneq ($(filter default-ub,$(my_sanitize)),)
|
|
|
|
my_sanitize := $(CLANG_DEFAULT_UB_CHECKS)
|
2014-12-12 10:56:26 +08:00
|
|
|
|
2015-04-17 09:07:07 +08:00
|
|
|
ifdef LOCAL_IS_HOST_MODULE
|
|
|
|
my_cflags += -fno-sanitize-recover=all
|
2015-06-16 02:39:29 +08:00
|
|
|
my_ldlibs += -ldl
|
2015-04-17 09:07:07 +08:00
|
|
|
else
|
|
|
|
my_cflags += -fsanitize-undefined-trap-on-error
|
2015-06-16 02:39:29 +08:00
|
|
|
my_shared_libraries += libdl
|
2015-04-17 09:07:07 +08:00
|
|
|
endif
|
2014-12-12 10:56:26 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(my_sanitize),)
|
|
|
|
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)
|
2015-04-29 04:23:36 +08:00
|
|
|
my_ldlibs += -lm -ldl -lpthread
|
2015-04-29 05:55:50 +08:00
|
|
|
my_ldflags += -Wl,--no-as-needed
|
2014-12-12 10:56:26 +08:00
|
|
|
else
|
2015-04-25 07:34:47 +08: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 10:56:26 +08:00
|
|
|
my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES)
|
2015-04-25 07:34:47 +08:00
|
|
|
my_ldflags += -Wl,-rpath,$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RPATH)
|
2014-12-12 10:56:26 +08:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifneq ($(filter undefined,$(my_sanitize)),)
|
2015-04-17 09:08:44 +08:00
|
|
|
my_cflags += -fno-sanitize-recover=all
|
|
|
|
|
2014-12-12 10:56:26 +08:00
|
|
|
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
|
2015-04-17 09:08:44 +08:00
|
|
|
|
|
|
|
|
2015-04-29 02:26:45 +08:00
|
|
|
ifneq ($(strip $(LOCAL_SANITIZE_RECOVER)),)
|
|
|
|
recover_arg := $(subst $(space),$(comma),$(LOCAL_SANITIZE_RECOVER)),
|
2015-04-17 09:08:44 +08:00
|
|
|
my_cflags += -fsanitize-recover=$(recover_arg)
|
|
|
|
endif
|
2015-06-15 02:38:30 +08:00
|
|
|
|
|
|
|
ifeq ($(strip $(LOCAL_DETECT_INTEGER_OVERFLOWS)),true)
|
|
|
|
ifeq ($(my_clang),true)
|
|
|
|
my_cflags += -fsanitize=signed-integer-overflow,unsigned-integer-overflow
|
|
|
|
my_cflags += -ftrap-function=abort
|
|
|
|
my_cflags += -fsanitize-undefined-trap-on-error
|
|
|
|
else
|
|
|
|
$(error $(LOCAL_MODULE): You must enable LOCAL_CLANG:=true to use LOCAL_DETECT_INTEGER_OVERFLOWS)
|
|
|
|
endif
|
|
|
|
endif
|