Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 1 | ############################################## |
| 2 | ## Perform configuration steps for sanitizers. |
| 3 | ############################################## |
| 4 | |
Dan Albert | 27ccb75 | 2015-04-16 16:21:02 -0700 | [diff] [blame] | 5 | my_sanitize := $(strip $(LOCAL_SANITIZE)) |
Vishwath Mohan | 8dcfdce | 2017-01-18 17:50:29 -0800 | [diff] [blame] | 6 | my_sanitize_diag := $(strip $(LOCAL_SANITIZE_DIAG)) |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 7 | |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 8 | # SANITIZE_HOST is only in effect if the module is already using clang (host |
| 9 | # modules that haven't set `LOCAL_CLANG := false` and device modules that |
| 10 | # have set `LOCAL_CLANG := true`. |
| 11 | my_global_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 12 | my_global_sanitize_diag := |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 13 | ifeq ($(my_clang),true) |
| 14 | ifdef LOCAL_IS_HOST_MODULE |
| 15 | my_global_sanitize := $(strip $(SANITIZE_HOST)) |
| 16 | |
| 17 | # SANITIZE_HOST=true is a deprecated way to say SANITIZE_HOST=address. |
| 18 | my_global_sanitize := $(subst true,address,$(my_global_sanitize)) |
| 19 | else |
| 20 | my_global_sanitize := $(strip $(SANITIZE_TARGET)) |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 21 | my_global_sanitize_diag := $(strip $(SANITIZE_TARGET_DIAG)) |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 22 | endif |
| 23 | endif |
| 24 | |
Ivan Lozano | b4749cb | 2017-07-21 10:33:32 -0700 | [diff] [blame] | 25 | # Disable global integer_overflow in excluded paths. |
| 26 | ifneq ($(filter integer_overflow, $(my_global_sanitize)),) |
| 27 | combined_exclude_paths := $(INTEGER_OVERFLOW_EXCLUDE_PATHS) \ |
| 28 | $(PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS) |
| 29 | |
| 30 | ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_exclude_paths)),\ |
| 31 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 32 | my_global_sanitize := $(filter-out integer_overflow,$(my_global_sanitize)) |
| 33 | my_global_sanitize_diag := $(filter-out integer_overflow,$(my_global_sanitize_diag)) |
| 34 | endif |
| 35 | endif |
| 36 | |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 37 | ifneq ($(my_global_sanitize),) |
Evgenii Stepanov | 71faa19 | 2016-05-19 17:45:21 -0700 | [diff] [blame] | 38 | my_sanitize := $(my_global_sanitize) $(my_sanitize) |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 39 | endif |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 40 | ifneq ($(my_global_sanitize_diag),) |
| 41 | my_sanitize_diag := $(my_global_sanitize_diag) $(my_sanitize_diag) |
| 42 | endif |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 43 | |
Andreas Gampe | 6b30d77 | 2016-06-27 15:15:31 -0700 | [diff] [blame] | 44 | # The sanitizer specified in the product configuration wins over the previous. |
| 45 | ifneq ($(SANITIZER.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG),) |
| 46 | my_sanitize := $(SANITIZER.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG) |
| 47 | ifeq ($(my_sanitize),never) |
| 48 | my_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 49 | my_sanitize_diag := |
Andreas Gampe | 6b30d77 | 2016-06-27 15:15:31 -0700 | [diff] [blame] | 50 | endif |
| 51 | endif |
| 52 | |
Colin Cross | 2361842 | 2016-11-02 15:05:21 -0700 | [diff] [blame] | 53 | ifndef LOCAL_IS_HOST_MODULE |
| 54 | # Add a filter point for 32-bit vs 64-bit sanitization (to lighten the burden) |
| 55 | SANITIZE_TARGET_ARCH ?= $(TARGET_ARCH) $(TARGET_2ND_ARCH) |
| 56 | ifeq ($(filter $(SANITIZE_TARGET_ARCH),$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) |
| 57 | my_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 58 | my_sanitize_diag := |
Colin Cross | 2361842 | 2016-11-02 15:05:21 -0700 | [diff] [blame] | 59 | endif |
Andreas Gampe | cd25740 | 2016-06-20 17:36:49 -0700 | [diff] [blame] | 60 | endif |
| 61 | |
Andreas Gampe | 3d3b0c9 | 2016-06-20 17:46:29 -0700 | [diff] [blame] | 62 | # Add a filter point based on module owner (to lighten the burden). The format is a space- or |
| 63 | # colon-separated list of owner names. |
| 64 | ifneq (,$(SANITIZE_NEVER_BY_OWNER)) |
| 65 | ifneq (,$(LOCAL_MODULE_OWNER)) |
| 66 | ifneq (,$(filter $(LOCAL_MODULE_OWNER),$(subst :, ,$(SANITIZE_NEVER_BY_OWNER)))) |
| 67 | $(warning Not sanitizing $(LOCAL_MODULE) based on module owner.) |
| 68 | my_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 69 | my_sanitize_diag := |
Andreas Gampe | 3d3b0c9 | 2016-06-20 17:46:29 -0700 | [diff] [blame] | 70 | endif |
| 71 | endif |
| 72 | endif |
| 73 | |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 74 | # Don't apply sanitizers to NDK code. |
| 75 | ifdef LOCAL_SDK_VERSION |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 76 | my_sanitize := |
Dan Willemsen | f761c0f | 2016-06-28 16:47:43 -0700 | [diff] [blame] | 77 | my_global_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 78 | my_sanitize_diag := |
Dan Albert | 27ccb75 | 2015-04-16 16:21:02 -0700 | [diff] [blame] | 79 | endif |
| 80 | |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 81 | # Never always wins. |
| 82 | ifeq ($(LOCAL_SANITIZE),never) |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 83 | my_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 84 | my_sanitize_diag := |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 85 | endif |
| 86 | |
Vishwath Mohan | 8dcfdce | 2017-01-18 17:50:29 -0800 | [diff] [blame] | 87 | # If CFI is disabled globally, remove it from my_sanitize. |
Vishwath Mohan | 45665b4 | 2017-01-24 13:20:28 -0800 | [diff] [blame] | 88 | ifeq ($(strip $(ENABLE_CFI)),false) |
Vishwath Mohan | 8dcfdce | 2017-01-18 17:50:29 -0800 | [diff] [blame] | 89 | my_sanitize := $(filter-out cfi,$(my_sanitize)) |
| 90 | my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag)) |
| 91 | endif |
| 92 | |
Vishwath Mohan | a204606 | 2017-02-07 20:28:07 -0800 | [diff] [blame] | 93 | # Disable CFI for arm32 (b/35157333). |
| 94 | ifneq ($(filter arm,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) |
| 95 | my_sanitize := $(filter-out cfi,$(my_sanitize)) |
| 96 | my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag)) |
| 97 | endif |
| 98 | |
Vishwath Mohan | c026f6d | 2017-04-20 07:39:13 -0700 | [diff] [blame] | 99 | # Also disable CFI if ASAN is enabled. |
| 100 | ifneq ($(filter address,$(my_sanitize)),) |
| 101 | my_sanitize := $(filter-out cfi,$(my_sanitize)) |
| 102 | my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag)) |
| 103 | endif |
| 104 | |
Evgenii Stepanov | 8c50e3c | 2017-01-31 17:08:33 -0800 | [diff] [blame] | 105 | # CFI needs gold linker, and mips toolchain does not have one. |
| 106 | ifneq ($(filter mips mips64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) |
| 107 | my_sanitize := $(filter-out cfi,$(my_sanitize)) |
| 108 | my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag)) |
| 109 | endif |
| 110 | |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 111 | # Support for local sanitize blacklist paths. |
| 112 | ifneq ($(my_sanitize)$(my_global_sanitize),) |
| 113 | ifneq ($(LOCAL_SANITIZE_BLACKLIST),) |
| 114 | my_cflags += -fsanitize-blacklist=$(LOCAL_PATH)/$(LOCAL_SANITIZE_BLACKLIST) |
| 115 | endif |
| 116 | endif |
| 117 | |
Ivan Lozano | b4749cb | 2017-07-21 10:33:32 -0700 | [diff] [blame] | 118 | # Disable integer_overflow if LOCAL_NOSANITIZE=integer. |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 119 | ifneq ($(filter integer_overflow, $(my_global_sanitize) $(my_sanitize)),) |
| 120 | ifneq ($(filter integer, $(strip $(LOCAL_NOSANITIZE))),) |
| 121 | my_sanitize := $(filter-out integer_overflow,$(my_sanitize)) |
| 122 | my_sanitize_diag := $(filter-out integer_overflow,$(my_sanitize_diag)) |
| 123 | endif |
| 124 | endif |
| 125 | |
Evgenii Stepanov | 4282366 | 2016-05-12 13:07:17 -0700 | [diff] [blame] | 126 | my_nosanitize = $(strip $(LOCAL_NOSANITIZE)) |
| 127 | ifneq ($(my_nosanitize),) |
| 128 | my_sanitize := $(filter-out $(my_nosanitize),$(my_sanitize)) |
| 129 | endif |
| 130 | |
Dan Albert | a6311b7 | 2015-07-30 10:17:33 -0700 | [diff] [blame] | 131 | # TSAN is not supported on 32-bit architectures. For non-multilib cases, make |
| 132 | # its use an error. For multilib cases, don't use it for the 32-bit case. |
| 133 | ifneq ($(filter thread,$(my_sanitize)),) |
| 134 | ifeq ($(my_32_64_bit_suffix),32) |
| 135 | ifeq ($(my_module_multilib),both) |
| 136 | my_sanitize := $(filter-out thread,$(my_sanitize)) |
| 137 | else |
| 138 | $(error $(LOCAL_PATH): $(LOCAL_MODULE): TSAN cannot be used for 32-bit modules.) |
| 139 | endif |
| 140 | endif |
| 141 | endif |
| 142 | |
Evgenii Stepanov | 7dcb8b8 | 2016-05-06 18:15:57 -0700 | [diff] [blame] | 143 | ifneq ($(filter safe-stack,$(my_sanitize)),) |
| 144 | ifeq ($(my_32_64_bit_suffix),32) |
| 145 | my_sanitize := $(filter-out safe-stack,$(my_sanitize)) |
| 146 | endif |
| 147 | endif |
| 148 | |
Evgenii Stepanov | 5adfcb1 | 2015-06-25 16:38:25 -0700 | [diff] [blame] | 149 | # Undefined symbols can occur if a non-sanitized library links |
| 150 | # sanitized static libraries. That's OK, because the executable |
| 151 | # always depends on the ASan runtime library, which defines these |
| 152 | # symbols. |
Evgenii Stepanov | 912b51f | 2016-05-19 17:49:51 -0700 | [diff] [blame] | 153 | ifneq ($(filter address thread,$(strip $(SANITIZE_TARGET))),) |
Evgenii Stepanov | 5adfcb1 | 2015-06-25 16:38:25 -0700 | [diff] [blame] | 154 | ifndef LOCAL_IS_HOST_MODULE |
| 155 | ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES) |
| 156 | ifeq ($(my_sanitize),) |
| 157 | my_allow_undefined_symbols := true |
| 158 | endif |
| 159 | endif |
| 160 | endif |
| 161 | endif |
| 162 | |
Dan Albert | 94b5791 | 2015-04-17 09:48:33 -0700 | [diff] [blame] | 163 | # Sanitizers can only be used with clang. |
| 164 | ifneq ($(my_clang),true) |
| 165 | ifneq ($(my_sanitize),) |
| 166 | $(error $(LOCAL_PATH): $(LOCAL_MODULE): Use of sanitizers requires LOCAL_CLANG := true) |
| 167 | endif |
| 168 | endif |
| 169 | |
Dan Albert | b5b2ffe | 2015-04-16 18:07:07 -0700 | [diff] [blame] | 170 | ifneq ($(filter default-ub,$(my_sanitize)),) |
| 171 | my_sanitize := $(CLANG_DEFAULT_UB_CHECKS) |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 172 | endif |
| 173 | |
Ivan Krasin | 74b32b8 | 2015-09-18 11:54:43 -0700 | [diff] [blame] | 174 | ifneq ($(filter coverage,$(my_sanitize)),) |
| 175 | ifeq ($(filter address,$(my_sanitize)),) |
| 176 | $(error $(LOCAL_PATH): $(LOCAL_MODULE): Use of 'coverage' also requires 'address') |
| 177 | endif |
Zach Riggle | be0811f | 2017-08-21 17:07:42 -0400 | [diff] [blame] | 178 | my_cflags += -fsanitize-coverage=trace-pc-guard,indirect-calls,trace-cmp |
Ivan Krasin | 74b32b8 | 2015-09-18 11:54:43 -0700 | [diff] [blame] | 179 | my_sanitize := $(filter-out coverage,$(my_sanitize)) |
| 180 | endif |
| 181 | |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 182 | ifneq ($(filter integer_overflow,$(my_sanitize)),) |
| 183 | ifneq ($(filter SHARED_LIBRARIES EXECUTABLES,$(LOCAL_MODULE_CLASS)),) |
| 184 | ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
| 185 | |
| 186 | # Respect LOCAL_NOSANITIZE for integer-overflow flags. |
| 187 | ifeq ($(filter signed-integer-overflow, $(strip $(LOCAL_NOSANITIZE))),) |
| 188 | my_cflags += -fsanitize=signed-integer-overflow |
| 189 | endif |
| 190 | ifeq ($(filter unsigned-integer-overflow, $(strip $(LOCAL_NOSANITIZE))),) |
| 191 | my_cflags += -fsanitize=unsigned-integer-overflow |
| 192 | endif |
| 193 | my_cflags += -fsanitize-trap=all |
| 194 | my_cflags += -ftrap-function=abort |
| 195 | my_cflags += $(INTEGER_OVERFLOW_EXTRA_CFLAGS) |
| 196 | |
| 197 | # Check for diagnostics mode (on by default). |
| 198 | ifneq ($(filter integer_overflow,$(my_sanitize_diag)),) |
| 199 | my_cflags += -fno-sanitize-trap=signed-integer-overflow,unsigned-integer-overflow |
| 200 | my_shared_libraries := $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY) $(my_shared_libraries) |
| 201 | endif |
| 202 | endif |
| 203 | endif |
| 204 | my_sanitize := $(filter-out integer_overflow,$(my_sanitize)) |
| 205 | endif |
| 206 | |
| 207 | # Makes sure integer_overflow diagnostics is removed from the diagnostics list |
| 208 | # even if integer_overflow is not set for some reason. |
| 209 | ifneq ($(filter integer_overflow,$(my_sanitize_diag)),) |
| 210 | my_sanitize_diag := $(filter-out integer_overflow,$(my_sanitize_diag)) |
| 211 | endif |
| 212 | |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 213 | ifneq ($(my_sanitize),) |
Stephen Hines | e8119e9 | 2015-11-09 16:32:11 -0800 | [diff] [blame] | 214 | fsanitize_arg := $(subst $(space),$(comma),$(my_sanitize)) |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 215 | my_cflags += -fsanitize=$(fsanitize_arg) |
| 216 | |
| 217 | ifdef LOCAL_IS_HOST_MODULE |
Dan Albert | abf4bc9 | 2015-06-16 23:27:34 -0700 | [diff] [blame] | 218 | my_cflags += -fno-sanitize-recover=all |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 219 | my_ldflags += -fsanitize=$(fsanitize_arg) |
Dan Albert | 2922411 | 2015-08-13 17:25:10 -0700 | [diff] [blame] | 220 | my_ldlibs += -lrt -ldl |
Dan Albert | abf4bc9 | 2015-06-16 23:27:34 -0700 | [diff] [blame] | 221 | else |
Evgenii Stepanov | 71faa19 | 2016-05-19 17:45:21 -0700 | [diff] [blame] | 222 | my_cflags += -fsanitize-trap=all |
| 223 | my_cflags += -ftrap-function=abort |
Evgenii Stepanov | 55f73e6 | 2016-05-12 13:07:36 -0700 | [diff] [blame] | 224 | ifneq ($(filter address thread,$(my_sanitize)),) |
Evgenii Stepanov | 71faa19 | 2016-05-19 17:45:21 -0700 | [diff] [blame] | 225 | my_cflags += -fno-sanitize-trap=address,thread |
Evgenii Stepanov | 55f73e6 | 2016-05-12 13:07:36 -0700 | [diff] [blame] | 226 | my_shared_libraries += libdl |
| 227 | endif |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 228 | endif |
| 229 | endif |
| 230 | |
Evgenii Stepanov | 202c7a7 | 2016-07-07 10:56:39 -0700 | [diff] [blame] | 231 | ifneq ($(filter cfi,$(my_sanitize)),) |
Evgenii Stepanov | 81bea1b | 2017-01-20 14:12:08 -0800 | [diff] [blame] | 232 | # __cfi_check needs to be built as Thumb (see the code in linker_cfi.cpp). |
| 233 | # LLVM is not set up to do this on a function basis, so force Thumb on the |
| 234 | # entire module. |
| 235 | LOCAL_ARM_MODE := thumb |
Vishwath Mohan | 5b69c06 | 2017-02-14 07:55:37 -0800 | [diff] [blame] | 236 | my_cflags += $(CFI_EXTRA_CFLAGS) |
| 237 | my_ldflags += $(CFI_EXTRA_LDFLAGS) |
Evgenii Stepanov | e1b96f3 | 2017-01-23 16:57:38 -0800 | [diff] [blame] | 238 | my_arflags += --plugin $(LLVM_PREBUILTS_PATH)/../lib64/LLVMgold.so |
Evgenii Stepanov | 8c50e3c | 2017-01-31 17:08:33 -0800 | [diff] [blame] | 239 | # Workaround for b/33678192. CFI jumptables need Thumb2 codegen. Revert when |
| 240 | # Clang is updated past r290384. |
| 241 | ifneq ($(filter arm,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) |
| 242 | my_ldflags += -march=armv7-a |
| 243 | endif |
Evgenii Stepanov | 202c7a7 | 2016-07-07 10:56:39 -0700 | [diff] [blame] | 244 | endif |
| 245 | |
Chih-Hung Hsieh | ad741e6 | 2016-03-09 14:54:55 -0800 | [diff] [blame] | 246 | # If local or global modules need ASAN, add linker flags. |
| 247 | ifneq ($(filter address,$(my_global_sanitize) $(my_sanitize)),) |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 248 | my_ldflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS) |
| 249 | ifdef LOCAL_IS_HOST_MODULE |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 250 | # -nodefaultlibs (provided with libc++) prevents the driver from linking |
| 251 | # libraries needed with -fsanitize=address. http://b/18650275 (WAI) |
Dan Albert | abf4bc9 | 2015-06-16 23:27:34 -0700 | [diff] [blame] | 252 | my_ldlibs += -lm -lpthread |
Dan Albert | 1f0d530 | 2015-04-28 14:55:50 -0700 | [diff] [blame] | 253 | my_ldflags += -Wl,--no-as-needed |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 254 | else |
Chih-Hung Hsieh | ad741e6 | 2016-03-09 14:54:55 -0800 | [diff] [blame] | 255 | # Add asan libraries unless LOCAL_MODULE is the asan library. |
Evgenii Stepanov | f0b15e1 | 2015-04-24 16:34:47 -0700 | [diff] [blame] | 256 | # ASan runtime library must be the first in the link order. |
Chih-Hung Hsieh | ad741e6 | 2016-03-09 14:54:55 -0800 | [diff] [blame] | 257 | ifeq (,$(filter $(LOCAL_MODULE),$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RUNTIME_LIBRARY))) |
| 258 | my_shared_libraries := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RUNTIME_LIBRARY) \ |
| 259 | $(my_shared_libraries) |
| 260 | endif |
| 261 | ifeq (,$(filter $(LOCAL_MODULE),$(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES))) |
| 262 | my_static_libraries += $(ADDRESS_SANITIZER_CONFIG_EXTRA_STATIC_LIBRARIES) |
| 263 | endif |
| 264 | |
| 265 | # Do not add unnecessary dependency in shared libraries. |
| 266 | ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES) |
| 267 | my_ldflags += -Wl,--as-needed |
| 268 | endif |
Ying Wang | a05e222 | 2015-08-17 16:13:24 -0700 | [diff] [blame] | 269 | |
Colin Cross | d08699e | 2016-07-17 15:28:07 -0700 | [diff] [blame] | 270 | ifeq ($(LOCAL_MODULE_CLASS),EXECUTABLES) |
| 271 | ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
| 272 | my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER) |
| 273 | # Make sure linker_asan get installed. |
| 274 | $(LOCAL_INSTALLED_MODULE) : | $(PRODUCT_OUT)$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER) |
| 275 | endif |
| 276 | endif |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 277 | endif |
| 278 | endif |
| 279 | |
Chih-Hung Hsieh | ad741e6 | 2016-03-09 14:54:55 -0800 | [diff] [blame] | 280 | # If local module needs ASAN, add compiler flags. |
| 281 | ifneq ($(filter address,$(my_sanitize)),) |
| 282 | # Frame pointer based unwinder in ASan requires ARM frame setup. |
| 283 | LOCAL_ARM_MODE := arm |
| 284 | my_cflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS) |
| 285 | ifndef LOCAL_IS_HOST_MODULE |
| 286 | my_cflags += -mllvm -asan-globals=0 |
| 287 | endif |
| 288 | endif |
| 289 | |
Dan Albert | 9f17655 | 2015-04-28 11:26:45 -0700 | [diff] [blame] | 290 | ifneq ($(strip $(LOCAL_SANITIZE_RECOVER)),) |
| 291 | recover_arg := $(subst $(space),$(comma),$(LOCAL_SANITIZE_RECOVER)), |
Dan Albert | 4111d48 | 2015-04-16 18:08:44 -0700 | [diff] [blame] | 292 | my_cflags += -fsanitize-recover=$(recover_arg) |
| 293 | endif |
Evgenii Stepanov | 202c7a7 | 2016-07-07 10:56:39 -0700 | [diff] [blame] | 294 | |
Vishwath Mohan | 8dcfdce | 2017-01-18 17:50:29 -0800 | [diff] [blame] | 295 | ifneq ($(my_sanitize_diag),) |
| 296 | notrap_arg := $(subst $(space),$(comma),$(my_sanitize_diag)), |
Evgenii Stepanov | 202c7a7 | 2016-07-07 10:56:39 -0700 | [diff] [blame] | 297 | my_cflags += -fno-sanitize-trap=$(notrap_arg) |
| 298 | # Diagnostic requires a runtime library, unless ASan or TSan are also enabled. |
| 299 | ifeq ($(filter address thread,$(my_sanitize)),) |
| 300 | # Does not have to be the first DT_NEEDED unlike ASan. |
| 301 | my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY) |
| 302 | endif |
| 303 | endif |