blob: 99dc55e4e4d63ed3bf007a085d53072e142be08f [file] [log] [blame]
Dan Albert4ae5d4b2014-10-31 16:23:08 -07001##############################################
2## Perform configuration steps for sanitizers.
3##############################################
4
5# Configure SANITIZE_HOST.
6ifdef LOCAL_IS_HOST_MODULE
Dan Albert27ccb752015-04-16 16:21:02 -07007 my_sanitize_host := $(strip $(SANITIZE_HOST))
Dan Albert4ae5d4b2014-10-31 16:23:08 -07008endif
9
Dan Albert27ccb752015-04-16 16:21:02 -070010# SANTIZIZE_HOST=true is a deprecated way to say SANITIZE_HOST=address.
11ifeq ($(my_sanitize_host),true)
12 my_sanitize_host := address
13endif
14
Dan Albert94b57912015-04-17 09:48:33 -070015# SANITIZE_HOST is only in effect if the module is already using clang (host
16# modules that haven't set `LOCAL_CLANG := false` and device modules that have
17# set `LOCAL_CLANG := true`.
18ifneq ($(my_clang),true)
Dan Albert27ccb752015-04-16 16:21:02 -070019 my_sanitize_host :=
20endif
21
22my_sanitize := $(strip $(LOCAL_SANITIZE))
Dan Albert08cca282014-12-11 18:56:26 -080023
24# Keep compatibility for LOCAL_ADDRESS_SANITIZER until all targets have moved to
25# `LOCAL_SANITIZE := address`.
Dan Albert4ae5d4b2014-10-31 16:23:08 -070026ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),true)
Dan Albert08cca282014-12-11 18:56:26 -080027 my_sanitize += address
28endif
29
Dan Albert27ccb752015-04-16 16:21:02 -070030# And `LOCAL_SANITIZE := never`.
31ifeq ($(strip $(LOCAL_ADDRESS_SANITIZER)),false)
32 my_sanitize := never
33endif
34
Dan Albert08cca282014-12-11 18:56:26 -080035# Don't apply sanitizers to NDK code.
36ifdef LOCAL_SDK_VERSION
Dan Albert27ccb752015-04-16 16:21:02 -070037 my_sanitize := never
38endif
39
40ifeq ($(my_sanitize),)
41 my_sanitize := $(my_sanitize_host)
42endif
43
44ifeq ($(my_sanitize),never)
Dan Albert08cca282014-12-11 18:56:26 -080045 my_sanitize :=
46endif
47
Dan Albert94b57912015-04-17 09:48:33 -070048# Sanitizers can only be used with clang.
49ifneq ($(my_clang),true)
50 ifneq ($(my_sanitize),)
51 $(error $(LOCAL_PATH): $(LOCAL_MODULE): Use of sanitizers requires LOCAL_CLANG := true)
52 endif
53endif
54
Dan Albert08cca282014-12-11 18:56:26 -080055unknown_sanitizers := $(filter-out address, \
56 $(filter-out undefined,$(my_sanitize)))
57
58ifneq ($(unknown_sanitizers),)
59 $(error Unknown sanitizers: $(unknown_sanitizers))
60endif
61
62ifneq ($(my_sanitize),)
Dan Albert08cca282014-12-11 18:56:26 -080063 fsanitize_arg := $(subst $(space),$(comma),$(my_sanitize)),
64 my_cflags += -fsanitize=$(fsanitize_arg)
65
66 ifdef LOCAL_IS_HOST_MODULE
67 my_ldflags += -fsanitize=$(fsanitize_arg)
68 endif
69endif
70
71ifneq ($(filter address,$(my_sanitize)),)
Dan Albert4ae5d4b2014-10-31 16:23:08 -070072 # Frame pointer based unwinder in ASan requires ARM frame setup.
73 LOCAL_ARM_MODE := arm
74 my_cflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS)
75 my_ldflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS)
76 ifdef LOCAL_IS_HOST_MODULE
Dan Albert08cca282014-12-11 18:56:26 -080077 # -nodefaultlibs (provided with libc++) prevents the driver from linking
78 # libraries needed with -fsanitize=address. http://b/18650275 (WAI)
79 my_ldlibs += -ldl -lpthread
Dan Albert4ae5d4b2014-10-31 16:23:08 -070080 else
Dan Albert08cca282014-12-11 18:56:26 -080081 my_shared_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_SHARED_LIBRARIES)
82 my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES)
83 endif
84endif
85
86ifneq ($(filter undefined,$(my_sanitize)),)
87 ifdef LOCAL_IS_HOST_MODULE
88 my_ldlibs += -ldl
89 else
90 $(error ubsan is not yet supported on the target)
Dan Albert4ae5d4b2014-10-31 16:23:08 -070091 endif
92endif