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 | my_global_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 9 | my_global_sanitize_diag := |
Dan Willemsen | f063839 | 2018-09-04 22:25:22 -0700 | [diff] [blame] | 10 | ifdef LOCAL_IS_HOST_MODULE |
| 11 | ifneq ($($(my_prefix)OS),windows) |
| 12 | my_global_sanitize := $(strip $(SANITIZE_HOST)) |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 13 | |
Dan Willemsen | f063839 | 2018-09-04 22:25:22 -0700 | [diff] [blame] | 14 | # SANITIZE_HOST=true is a deprecated way to say SANITIZE_HOST=address. |
| 15 | my_global_sanitize := $(subst true,address,$(my_global_sanitize)) |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 16 | endif |
Dan Willemsen | f063839 | 2018-09-04 22:25:22 -0700 | [diff] [blame] | 17 | else |
| 18 | my_global_sanitize := $(strip $(SANITIZE_TARGET)) |
| 19 | my_global_sanitize_diag := $(strip $(SANITIZE_TARGET_DIAG)) |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 20 | endif |
| 21 | |
Ivan Lozano | b4749cb | 2017-07-21 10:33:32 -0700 | [diff] [blame] | 22 | # Disable global integer_overflow in excluded paths. |
| 23 | ifneq ($(filter integer_overflow, $(my_global_sanitize)),) |
| 24 | combined_exclude_paths := $(INTEGER_OVERFLOW_EXCLUDE_PATHS) \ |
| 25 | $(PRODUCT_INTEGER_OVERFLOW_EXCLUDE_PATHS) |
| 26 | |
| 27 | ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_exclude_paths)),\ |
| 28 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 29 | my_global_sanitize := $(filter-out integer_overflow,$(my_global_sanitize)) |
| 30 | my_global_sanitize_diag := $(filter-out integer_overflow,$(my_global_sanitize_diag)) |
| 31 | endif |
| 32 | endif |
| 33 | |
Ivan Lozano | 702e8bd | 2018-03-15 14:49:20 -0700 | [diff] [blame] | 34 | # Global integer sanitization doesn't support static modules. |
| 35 | ifeq ($(filter SHARED_LIBRARIES EXECUTABLES,$(LOCAL_MODULE_CLASS)),) |
| 36 | my_global_sanitize := $(filter-out integer_overflow,$(my_global_sanitize)) |
| 37 | my_global_sanitize_diag := $(filter-out integer_overflow,$(my_global_sanitize_diag)) |
| 38 | endif |
| 39 | ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
| 40 | my_global_sanitize := $(filter-out integer_overflow,$(my_global_sanitize)) |
| 41 | my_global_sanitize_diag := $(filter-out integer_overflow,$(my_global_sanitize_diag)) |
| 42 | endif |
| 43 | |
Vishwath Mohan | 23b2d2e | 2017-10-31 02:25:16 -0700 | [diff] [blame] | 44 | # Disable global CFI in excluded paths |
| 45 | ifneq ($(filter cfi, $(my_global_sanitize)),) |
| 46 | combined_exclude_paths := $(CFI_EXCLUDE_PATHS) \ |
| 47 | $(PRODUCT_CFI_EXCLUDE_PATHS) |
| 48 | |
| 49 | ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_exclude_paths)),\ |
| 50 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 51 | my_global_sanitize := $(filter-out cfi,$(my_global_sanitize)) |
| 52 | my_global_sanitize_diag := $(filter-out cfi,$(my_global_sanitize_diag)) |
| 53 | endif |
| 54 | endif |
| 55 | |
Evgenii Stepanov | 3330b2f | 2021-01-13 12:14:55 -0800 | [diff] [blame] | 56 | # Disable global memtag_heap in excluded paths |
| 57 | ifneq ($(filter memtag_heap, $(my_global_sanitize)),) |
| 58 | combined_exclude_paths := $(MEMTAG_HEAP_EXCLUDE_PATHS) \ |
| 59 | $(PRODUCT_MEMTAG_HEAP_EXCLUDE_PATHS) |
| 60 | |
| 61 | ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_exclude_paths)),\ |
| 62 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 63 | my_global_sanitize := $(filter-out memtag_heap,$(my_global_sanitize)) |
| 64 | my_global_sanitize_diag := $(filter-out memtag_heap,$(my_global_sanitize_diag)) |
| 65 | endif |
| 66 | endif |
| 67 | |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 68 | ifneq ($(my_global_sanitize),) |
Evgenii Stepanov | 71faa19 | 2016-05-19 17:45:21 -0700 | [diff] [blame] | 69 | my_sanitize := $(my_global_sanitize) $(my_sanitize) |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 70 | endif |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 71 | ifneq ($(my_global_sanitize_diag),) |
| 72 | my_sanitize_diag := $(my_global_sanitize_diag) $(my_sanitize_diag) |
| 73 | endif |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 74 | |
Andreas Gampe | 6b30d77 | 2016-06-27 15:15:31 -0700 | [diff] [blame] | 75 | # The sanitizer specified in the product configuration wins over the previous. |
| 76 | ifneq ($(SANITIZER.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG),) |
| 77 | my_sanitize := $(SANITIZER.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG) |
| 78 | ifeq ($(my_sanitize),never) |
| 79 | my_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 80 | my_sanitize_diag := |
Andreas Gampe | 6b30d77 | 2016-06-27 15:15:31 -0700 | [diff] [blame] | 81 | endif |
| 82 | endif |
| 83 | |
Colin Cross | 2361842 | 2016-11-02 15:05:21 -0700 | [diff] [blame] | 84 | ifndef LOCAL_IS_HOST_MODULE |
| 85 | # Add a filter point for 32-bit vs 64-bit sanitization (to lighten the burden) |
| 86 | SANITIZE_TARGET_ARCH ?= $(TARGET_ARCH) $(TARGET_2ND_ARCH) |
| 87 | ifeq ($(filter $(SANITIZE_TARGET_ARCH),$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) |
| 88 | my_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 89 | my_sanitize_diag := |
Colin Cross | 2361842 | 2016-11-02 15:05:21 -0700 | [diff] [blame] | 90 | endif |
Andreas Gampe | cd25740 | 2016-06-20 17:36:49 -0700 | [diff] [blame] | 91 | endif |
| 92 | |
Andreas Gampe | 3d3b0c9 | 2016-06-20 17:46:29 -0700 | [diff] [blame] | 93 | # Add a filter point based on module owner (to lighten the burden). The format is a space- or |
| 94 | # colon-separated list of owner names. |
| 95 | ifneq (,$(SANITIZE_NEVER_BY_OWNER)) |
| 96 | ifneq (,$(LOCAL_MODULE_OWNER)) |
| 97 | ifneq (,$(filter $(LOCAL_MODULE_OWNER),$(subst :, ,$(SANITIZE_NEVER_BY_OWNER)))) |
| 98 | $(warning Not sanitizing $(LOCAL_MODULE) based on module owner.) |
| 99 | my_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 100 | my_sanitize_diag := |
Andreas Gampe | 3d3b0c9 | 2016-06-20 17:46:29 -0700 | [diff] [blame] | 101 | endif |
| 102 | endif |
| 103 | endif |
| 104 | |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 105 | # Don't apply sanitizers to NDK code. |
| 106 | ifdef LOCAL_SDK_VERSION |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 107 | my_sanitize := |
Dan Willemsen | f761c0f | 2016-06-28 16:47:43 -0700 | [diff] [blame] | 108 | my_global_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 109 | my_sanitize_diag := |
Dan Albert | 27ccb75 | 2015-04-16 16:21:02 -0700 | [diff] [blame] | 110 | endif |
| 111 | |
Dan Albert | 4c40141 | 2015-08-19 20:13:33 -0700 | [diff] [blame] | 112 | # Never always wins. |
| 113 | ifeq ($(LOCAL_SANITIZE),never) |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 114 | my_sanitize := |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 115 | my_sanitize_diag := |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 116 | endif |
| 117 | |
Elvis Chien | 064d91c | 2021-04-14 17:02:29 +0800 | [diff] [blame] | 118 | # Enable CFI in included paths. |
Vishwath Mohan | 23b2d2e | 2017-10-31 02:25:16 -0700 | [diff] [blame] | 119 | ifeq ($(filter cfi, $(my_sanitize)),) |
Elvis Chien | 064d91c | 2021-04-14 17:02:29 +0800 | [diff] [blame] | 120 | combined_include_paths := $(CFI_INCLUDE_PATHS) \ |
| 121 | $(PRODUCT_CFI_INCLUDE_PATHS) |
| 122 | combined_exclude_paths := $(CFI_EXCLUDE_PATHS) \ |
| 123 | $(PRODUCT_CFI_EXCLUDE_PATHS) |
Vishwath Mohan | 23b2d2e | 2017-10-31 02:25:16 -0700 | [diff] [blame] | 124 | |
Elvis Chien | 064d91c | 2021-04-14 17:02:29 +0800 | [diff] [blame] | 125 | ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_include_paths)),\ |
| 126 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 127 | ifeq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_exclude_paths)),\ |
| 128 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 129 | my_sanitize := cfi $(my_sanitize) |
Vishwath Mohan | 6106a4e | 2018-05-24 18:04:25 -0700 | [diff] [blame] | 130 | endif |
Vishwath Mohan | 23b2d2e | 2017-10-31 02:25:16 -0700 | [diff] [blame] | 131 | endif |
| 132 | endif |
| 133 | |
Evgenii Stepanov | 3330b2f | 2021-01-13 12:14:55 -0800 | [diff] [blame] | 134 | # Enable memtag_heap in included paths (for Arm64 only). |
| 135 | ifeq ($(filter memtag_heap, $(my_sanitize)),) |
| 136 | ifneq ($(filter arm64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) |
| 137 | combined_sync_include_paths := $(MEMTAG_HEAP_SYNC_INCLUDE_PATHS) \ |
| 138 | $(PRODUCT_MEMTAG_HEAP_SYNC_INCLUDE_PATHS) |
| 139 | combined_async_include_paths := $(MEMTAG_HEAP_ASYNC_INCLUDE_PATHS) \ |
| 140 | $(PRODUCT_MEMTAG_HEAP_ASYNC_INCLUDE_PATHS) |
Evgenii Stepanov | 13bc227 | 2021-04-09 14:52:33 -0700 | [diff] [blame] | 141 | combined_exclude_paths := $(MEMTAG_HEAP_EXCLUDE_PATHS) \ |
| 142 | $(PRODUCT_MEMTAG_HEAP_EXCLUDE_PATHS) |
Evgenii Stepanov | 80b53b8 | 2023-06-08 15:40:39 -0700 | [diff] [blame^] | 143 | ifneq ($(PRODUCT_MEMTAG_HEAP_SKIP_DEFAULT_PATHS),true) |
| 144 | combined_sync_include_paths += $(PRODUCT_MEMTAG_HEAP_SYNC_DEFAULT_INCLUDE_PATHS) |
| 145 | combined_async_include_paths += $(PRODUCT_MEMTAG_HEAP_ASYNC_DEFAULT_INCLUDE_PATHS) |
| 146 | endif |
Evgenii Stepanov | 3330b2f | 2021-01-13 12:14:55 -0800 | [diff] [blame] | 147 | |
Evgenii Stepanov | 13bc227 | 2021-04-09 14:52:33 -0700 | [diff] [blame] | 148 | ifeq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_exclude_paths)),\ |
| 149 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 150 | ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_sync_include_paths)),\ |
| 151 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 152 | my_sanitize := memtag_heap $(my_sanitize) |
| 153 | my_sanitize_diag := memtag_heap $(my_sanitize_diag) |
| 154 | else ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_async_include_paths)),\ |
| 155 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 156 | my_sanitize := memtag_heap $(my_sanitize) |
| 157 | endif |
Evgenii Stepanov | 3330b2f | 2021-01-13 12:14:55 -0800 | [diff] [blame] | 158 | endif |
| 159 | endif |
| 160 | endif |
| 161 | |
Hang Lu | e235ded | 2022-08-29 14:42:34 +0800 | [diff] [blame] | 162 | # Enable HWASan in included paths. |
| 163 | ifeq ($(filter hwaddress, $(my_sanitize)),) |
| 164 | combined_include_paths := $(HWASAN_INCLUDE_PATHS) \ |
| 165 | $(PRODUCT_HWASAN_INCLUDE_PATHS) |
| 166 | |
| 167 | ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_include_paths)),\ |
| 168 | $(filter $(dir)%,$(LOCAL_PATH)))),) |
| 169 | my_sanitize := hwaddress $(my_sanitize) |
| 170 | endif |
| 171 | endif |
| 172 | |
Vishwath Mohan | 8dcfdce | 2017-01-18 17:50:29 -0800 | [diff] [blame] | 173 | # If CFI is disabled globally, remove it from my_sanitize. |
Vishwath Mohan | 45665b4 | 2017-01-24 13:20:28 -0800 | [diff] [blame] | 174 | ifeq ($(strip $(ENABLE_CFI)),false) |
Vishwath Mohan | 8dcfdce | 2017-01-18 17:50:29 -0800 | [diff] [blame] | 175 | my_sanitize := $(filter-out cfi,$(my_sanitize)) |
| 176 | my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag)) |
| 177 | endif |
| 178 | |
Florian Mayer | 548a2ad | 2022-08-31 22:25:55 +0000 | [diff] [blame] | 179 | # Also disable CFI and MTE if ASAN is enabled. |
Vishwath Mohan | c026f6d | 2017-04-20 07:39:13 -0700 | [diff] [blame] | 180 | ifneq ($(filter address,$(my_sanitize)),) |
| 181 | my_sanitize := $(filter-out cfi,$(my_sanitize)) |
Florian Mayer | 548a2ad | 2022-08-31 22:25:55 +0000 | [diff] [blame] | 182 | my_sanitize := $(filter-out memtag_stack,$(my_sanitize)) |
| 183 | my_sanitize := $(filter-out memtag_heap,$(my_sanitize)) |
Vishwath Mohan | c026f6d | 2017-04-20 07:39:13 -0700 | [diff] [blame] | 184 | my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag)) |
| 185 | endif |
| 186 | |
Mitch Phillips | b71a875 | 2021-05-19 11:29:02 -0700 | [diff] [blame] | 187 | # Disable memtag for host targets. Host executables in AndroidMk files are |
| 188 | # deprecated, but some partners still have them floating around. |
| 189 | ifdef LOCAL_IS_HOST_MODULE |
Florian Mayer | 548a2ad | 2022-08-31 22:25:55 +0000 | [diff] [blame] | 190 | my_sanitize := $(filter-out memtag_heap memtag_stack,$(my_sanitize)) |
| 191 | my_sanitize_diag := $(filter-out memtag_heap memtag_stack,$(my_sanitize_diag)) |
Mitch Phillips | b71a875 | 2021-05-19 11:29:02 -0700 | [diff] [blame] | 192 | endif |
| 193 | |
Ivan Lozano | 702e8bd | 2018-03-15 14:49:20 -0700 | [diff] [blame] | 194 | # Disable sanitizers which need the UBSan runtime for host targets. |
Vishwath Mohan | 96a130b | 2017-11-17 11:19:36 -0800 | [diff] [blame] | 195 | ifdef LOCAL_IS_HOST_MODULE |
| 196 | my_sanitize := $(filter-out cfi,$(my_sanitize)) |
| 197 | my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag)) |
Ivan Lozano | 702e8bd | 2018-03-15 14:49:20 -0700 | [diff] [blame] | 198 | my_sanitize := $(filter-out signed-integer-overflow unsigned-integer-overflow integer_overflow,$(my_sanitize)) |
| 199 | my_sanitize_diag := $(filter-out signed-integer-overflow unsigned-integer-overflow integer_overflow,$(my_sanitize_diag)) |
Vishwath Mohan | 96a130b | 2017-11-17 11:19:36 -0800 | [diff] [blame] | 200 | endif |
| 201 | |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 202 | # Support for local sanitize blacklist paths. |
| 203 | ifneq ($(my_sanitize)$(my_global_sanitize),) |
Pirama Arumuga Nainar | 5655833 | 2020-07-30 15:18:07 -0700 | [diff] [blame] | 204 | ifneq ($(LOCAL_SANITIZE_BLOCKLIST),) |
| 205 | my_cflags += -fsanitize-blacklist=$(LOCAL_PATH)/$(LOCAL_SANITIZE_BLOCKLIST) |
| 206 | endif |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 207 | endif |
| 208 | |
Ivan Lozano | b4749cb | 2017-07-21 10:33:32 -0700 | [diff] [blame] | 209 | # Disable integer_overflow if LOCAL_NOSANITIZE=integer. |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 210 | ifneq ($(filter integer_overflow, $(my_global_sanitize) $(my_sanitize)),) |
| 211 | ifneq ($(filter integer, $(strip $(LOCAL_NOSANITIZE))),) |
| 212 | my_sanitize := $(filter-out integer_overflow,$(my_sanitize)) |
| 213 | my_sanitize_diag := $(filter-out integer_overflow,$(my_sanitize_diag)) |
| 214 | endif |
| 215 | endif |
| 216 | |
Evgenii Stepanov | 4282366 | 2016-05-12 13:07:17 -0700 | [diff] [blame] | 217 | my_nosanitize = $(strip $(LOCAL_NOSANITIZE)) |
| 218 | ifneq ($(my_nosanitize),) |
| 219 | my_sanitize := $(filter-out $(my_nosanitize),$(my_sanitize)) |
| 220 | endif |
| 221 | |
Evgenii Stepanov | 8841a7f | 2018-07-27 11:54:32 -0700 | [diff] [blame] | 222 | ifneq ($(filter arm x86 x86_64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),) |
| 223 | my_sanitize := $(filter-out hwaddress,$(my_sanitize)) |
Evgenii Stepanov | 3330b2f | 2021-01-13 12:14:55 -0800 | [diff] [blame] | 224 | my_sanitize := $(filter-out memtag_heap,$(my_sanitize)) |
Florian Mayer | 548a2ad | 2022-08-31 22:25:55 +0000 | [diff] [blame] | 225 | my_sanitize := $(filter-out memtag_stack,$(my_sanitize)) |
Evgenii Stepanov | 8841a7f | 2018-07-27 11:54:32 -0700 | [diff] [blame] | 226 | endif |
| 227 | |
| 228 | ifneq ($(filter hwaddress,$(my_sanitize)),) |
| 229 | my_sanitize := $(filter-out address,$(my_sanitize)) |
Florian Mayer | 548a2ad | 2022-08-31 22:25:55 +0000 | [diff] [blame] | 230 | my_sanitize := $(filter-out memtag_stack,$(my_sanitize)) |
| 231 | my_sanitize := $(filter-out memtag_heap,$(my_sanitize)) |
Evgenii Stepanov | 8841a7f | 2018-07-27 11:54:32 -0700 | [diff] [blame] | 232 | my_sanitize := $(filter-out thread,$(my_sanitize)) |
Evgenii Stepanov | 88a95a3 | 2018-12-04 17:06:45 -0800 | [diff] [blame] | 233 | my_sanitize := $(filter-out cfi,$(my_sanitize)) |
Evgenii Stepanov | 8841a7f | 2018-07-27 11:54:32 -0700 | [diff] [blame] | 234 | endif |
| 235 | |
| 236 | ifneq ($(filter hwaddress,$(my_sanitize)),) |
| 237 | my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)HWADDRESS_SANITIZER_RUNTIME_LIBRARY) |
Evgenii Stepanov | ed90746 | 2018-11-01 15:43:14 -0700 | [diff] [blame] | 238 | ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) |
Evgenii Stepanov | 8841a7f | 2018-07-27 11:54:32 -0700 | [diff] [blame] | 239 | ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
Ryan Prichard | acf8b0f | 2019-10-21 20:47:53 -0700 | [diff] [blame] | 240 | my_static_libraries := $(my_static_libraries) \ |
| 241 | $($(LOCAL_2ND_ARCH_VAR_PREFIX)HWADDRESS_SANITIZER_STATIC_LIBRARY) \ |
| 242 | libdl |
Evgenii Stepanov | 8841a7f | 2018-07-27 11:54:32 -0700 | [diff] [blame] | 243 | endif |
| 244 | endif |
| 245 | endif |
| 246 | |
Florian Mayer | 548a2ad | 2022-08-31 22:25:55 +0000 | [diff] [blame] | 247 | ifneq ($(filter memtag_heap memtag_stack,$(my_sanitize)),) |
| 248 | ifneq ($(filter memtag_heap,$(my_sanitize_diag)),) |
| 249 | my_cflags += -fsanitize-memtag-mode=sync |
| 250 | my_sanitize_diag := $(filter-out memtag_heap,$(my_sanitize_diag)) |
| 251 | else |
| 252 | my_cflags += -fsanitize-memtag-mode=async |
Florian Mayer | fe3e537 | 2022-08-31 18:37:51 +0000 | [diff] [blame] | 253 | endif |
Florian Mayer | 548a2ad | 2022-08-31 22:25:55 +0000 | [diff] [blame] | 254 | endif |
| 255 | |
Florian Mayer | 2a67626 | 2023-06-07 15:02:22 -0700 | [diff] [blame] | 256 | # Ignore SANITIZE_TARGET_DIAG=memtag_heap without SANITIZE_TARGET=memtag_heap |
| 257 | # This can happen if a condition above filters out memtag_heap from |
| 258 | # my_sanitize. It is easier to handle all of these cases here centrally. |
| 259 | ifneq ($(filter memtag_heap,$(my_sanitize_diag)),) |
| 260 | my_sanitize_diag := $(filter-out memtag_heap,$(my_sanitize_diag)) |
| 261 | endif |
| 262 | |
Florian Mayer | 548a2ad | 2022-08-31 22:25:55 +0000 | [diff] [blame] | 263 | ifneq ($(filter memtag_heap,$(my_sanitize)),) |
| 264 | my_cflags += -fsanitize=memtag-heap |
Evgenii Stepanov | 3330b2f | 2021-01-13 12:14:55 -0800 | [diff] [blame] | 265 | my_sanitize := $(filter-out memtag_heap,$(my_sanitize)) |
| 266 | endif |
| 267 | |
Florian Mayer | 548a2ad | 2022-08-31 22:25:55 +0000 | [diff] [blame] | 268 | ifneq ($(filter memtag_stack,$(my_sanitize)),) |
| 269 | my_cflags += -fsanitize=memtag-stack |
| 270 | my_cflags += -march=armv8a+memtag |
| 271 | my_ldflags += -march=armv8a+memtag |
| 272 | my_asflags += -march=armv8a+memtag |
| 273 | my_sanitize := $(filter-out memtag_stack,$(my_sanitize)) |
| 274 | endif |
Evgenii Stepanov | 3330b2f | 2021-01-13 12:14:55 -0800 | [diff] [blame] | 275 | |
Dan Albert | a6311b7 | 2015-07-30 10:17:33 -0700 | [diff] [blame] | 276 | # TSAN is not supported on 32-bit architectures. For non-multilib cases, make |
| 277 | # its use an error. For multilib cases, don't use it for the 32-bit case. |
| 278 | ifneq ($(filter thread,$(my_sanitize)),) |
| 279 | ifeq ($(my_32_64_bit_suffix),32) |
| 280 | ifeq ($(my_module_multilib),both) |
| 281 | my_sanitize := $(filter-out thread,$(my_sanitize)) |
| 282 | else |
| 283 | $(error $(LOCAL_PATH): $(LOCAL_MODULE): TSAN cannot be used for 32-bit modules.) |
| 284 | endif |
Yabin Cui | e77c32e | 2017-10-19 14:33:58 -0700 | [diff] [blame] | 285 | else |
| 286 | my_shared_libraries += $(TSAN_RUNTIME_LIBRARY) |
Dan Albert | a6311b7 | 2015-07-30 10:17:33 -0700 | [diff] [blame] | 287 | endif |
| 288 | endif |
| 289 | |
Evgenii Stepanov | 7dcb8b8 | 2016-05-06 18:15:57 -0700 | [diff] [blame] | 290 | ifneq ($(filter safe-stack,$(my_sanitize)),) |
| 291 | ifeq ($(my_32_64_bit_suffix),32) |
| 292 | my_sanitize := $(filter-out safe-stack,$(my_sanitize)) |
| 293 | endif |
| 294 | endif |
| 295 | |
Kostya Kortchinsky | 2cfa997 | 2018-06-14 11:02:15 -0700 | [diff] [blame] | 296 | # Disable Scudo if ASan or TSan is enabled. |
Evgenii Stepanov | 8841a7f | 2018-07-27 11:54:32 -0700 | [diff] [blame] | 297 | ifneq ($(filter address thread hwaddress,$(my_sanitize)),) |
Kostya Kortchinsky | 2cfa997 | 2018-06-14 11:02:15 -0700 | [diff] [blame] | 298 | my_sanitize := $(filter-out scudo,$(my_sanitize)) |
| 299 | endif |
| 300 | |
Kostya Kortchinsky | 0273240 | 2019-02-01 09:06:42 -0800 | [diff] [blame] | 301 | # Or if disabled globally. |
Anton Hansson | 8dab0a6 | 2019-03-28 15:45:40 +0000 | [diff] [blame] | 302 | ifeq ($(PRODUCT_DISABLE_SCUDO),true) |
Kostya Kortchinsky | 0273240 | 2019-02-01 09:06:42 -0800 | [diff] [blame] | 303 | my_sanitize := $(filter-out scudo,$(my_sanitize)) |
| 304 | endif |
| 305 | |
Evgenii Stepanov | 5adfcb1 | 2015-06-25 16:38:25 -0700 | [diff] [blame] | 306 | # Undefined symbols can occur if a non-sanitized library links |
| 307 | # sanitized static libraries. That's OK, because the executable |
| 308 | # always depends on the ASan runtime library, which defines these |
| 309 | # symbols. |
Evgenii Stepanov | 912b51f | 2016-05-19 17:49:51 -0700 | [diff] [blame] | 310 | ifneq ($(filter address thread,$(strip $(SANITIZE_TARGET))),) |
Evgenii Stepanov | 5adfcb1 | 2015-06-25 16:38:25 -0700 | [diff] [blame] | 311 | ifndef LOCAL_IS_HOST_MODULE |
| 312 | ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES) |
| 313 | ifeq ($(my_sanitize),) |
| 314 | my_allow_undefined_symbols := true |
| 315 | endif |
| 316 | endif |
| 317 | endif |
| 318 | endif |
| 319 | |
Dan Albert | b5b2ffe | 2015-04-16 18:07:07 -0700 | [diff] [blame] | 320 | ifneq ($(filter default-ub,$(my_sanitize)),) |
| 321 | my_sanitize := $(CLANG_DEFAULT_UB_CHECKS) |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 322 | endif |
| 323 | |
Mitch Phillips | ee8f4a0 | 2019-05-01 14:37:33 -0700 | [diff] [blame] | 324 | ifneq ($(filter fuzzer,$(my_sanitize)),) |
| 325 | # SANITIZE_TARGET='fuzzer' actually means to create the fuzzer coverage |
| 326 | # information, not to link against the fuzzer main(). |
| 327 | my_sanitize := $(filter-out fuzzer,$(my_sanitize)) |
| 328 | my_sanitize += fuzzer-no-link |
Mitch Phillips | d51048a | 2022-03-02 01:25:22 +0000 | [diff] [blame] | 329 | |
| 330 | # TODO(b/131771163): Disable LTO for fuzzer builds. Note that Cfi causes |
| 331 | # dependency on LTO. |
| 332 | my_sanitize := $(filter-out cfi,$(my_sanitize)) |
| 333 | my_cflags += -fno-lto |
| 334 | my_ldflags += -fno-lto |
Ivan Krasin | 74b32b8 | 2015-09-18 11:54:43 -0700 | [diff] [blame] | 335 | endif |
| 336 | |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 337 | ifneq ($(filter integer_overflow,$(my_sanitize)),) |
Ivan Lozano | 702e8bd | 2018-03-15 14:49:20 -0700 | [diff] [blame] | 338 | # Respect LOCAL_NOSANITIZE for integer-overflow flags. |
| 339 | ifeq ($(filter signed-integer-overflow, $(strip $(LOCAL_NOSANITIZE))),) |
| 340 | my_sanitize += signed-integer-overflow |
| 341 | endif |
| 342 | ifeq ($(filter unsigned-integer-overflow, $(strip $(LOCAL_NOSANITIZE))),) |
| 343 | my_sanitize += unsigned-integer-overflow |
| 344 | endif |
| 345 | my_cflags += $(INTEGER_OVERFLOW_EXTRA_CFLAGS) |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 346 | |
Ivan Lozano | 702e8bd | 2018-03-15 14:49:20 -0700 | [diff] [blame] | 347 | # Check for diagnostics mode. |
| 348 | ifneq ($(filter integer_overflow,$(my_sanitize_diag)),) |
| 349 | ifneq ($(filter SHARED_LIBRARIES EXECUTABLES,$(LOCAL_MODULE_CLASS)),) |
| 350 | ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
Ivan Lozano | 911cb99 | 2018-02-21 13:41:05 -0800 | [diff] [blame] | 351 | my_sanitize_diag += signed-integer-overflow |
| 352 | my_sanitize_diag += unsigned-integer-overflow |
Ivan Lozano | 702e8bd | 2018-03-15 14:49:20 -0700 | [diff] [blame] | 353 | else |
| 354 | $(call pretty-error,Make cannot apply integer overflow diagnostics to static binary.) |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 355 | endif |
Ivan Lozano | 702e8bd | 2018-03-15 14:49:20 -0700 | [diff] [blame] | 356 | else |
| 357 | $(call pretty-error,Make cannot apply integer overflow diagnostics to static library.) |
Ivan Lozano | 4a36373 | 2017-06-28 09:11:26 -0700 | [diff] [blame] | 358 | endif |
| 359 | endif |
| 360 | my_sanitize := $(filter-out integer_overflow,$(my_sanitize)) |
| 361 | endif |
| 362 | |
| 363 | # Makes sure integer_overflow diagnostics is removed from the diagnostics list |
| 364 | # even if integer_overflow is not set for some reason. |
| 365 | ifneq ($(filter integer_overflow,$(my_sanitize_diag)),) |
| 366 | my_sanitize_diag := $(filter-out integer_overflow,$(my_sanitize_diag)) |
| 367 | endif |
| 368 | |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 369 | ifneq ($(my_sanitize),) |
Stephen Hines | e8119e9 | 2015-11-09 16:32:11 -0800 | [diff] [blame] | 370 | fsanitize_arg := $(subst $(space),$(comma),$(my_sanitize)) |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 371 | my_cflags += -fsanitize=$(fsanitize_arg) |
Evgenii Stepanov | 9b82b3f | 2018-08-31 12:57:26 -0700 | [diff] [blame] | 372 | my_asflags += -fsanitize=$(fsanitize_arg) |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 373 | |
Mitch Phillips | ee8f4a0 | 2019-05-01 14:37:33 -0700 | [diff] [blame] | 374 | # When fuzzing, we wish to crash with diagnostics on any bug. |
| 375 | ifneq ($(filter fuzzer-no-link,$(my_sanitize)),) |
| 376 | my_cflags += -fno-sanitize-trap=all |
| 377 | my_cflags += -fno-sanitize-recover=all |
| 378 | my_ldflags += -fsanitize=fuzzer-no-link |
| 379 | else ifdef LOCAL_IS_HOST_MODULE |
Dan Albert | abf4bc9 | 2015-06-16 23:27:34 -0700 | [diff] [blame] | 380 | my_cflags += -fno-sanitize-recover=all |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 381 | my_ldflags += -fsanitize=$(fsanitize_arg) |
Dan Albert | abf4bc9 | 2015-06-16 23:27:34 -0700 | [diff] [blame] | 382 | else |
Evgenii Stepanov | 71faa19 | 2016-05-19 17:45:21 -0700 | [diff] [blame] | 383 | my_cflags += -fsanitize-trap=all |
| 384 | my_cflags += -ftrap-function=abort |
Evgenii Stepanov | 55f73e6 | 2016-05-12 13:07:36 -0700 | [diff] [blame] | 385 | ifneq ($(filter address thread,$(my_sanitize)),) |
Evgenii Stepanov | 71faa19 | 2016-05-19 17:45:21 -0700 | [diff] [blame] | 386 | my_cflags += -fno-sanitize-trap=address,thread |
Evgenii Stepanov | 55f73e6 | 2016-05-12 13:07:36 -0700 | [diff] [blame] | 387 | my_shared_libraries += libdl |
| 388 | endif |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 389 | endif |
| 390 | endif |
| 391 | |
Evgenii Stepanov | 202c7a7 | 2016-07-07 10:56:39 -0700 | [diff] [blame] | 392 | ifneq ($(filter cfi,$(my_sanitize)),) |
Evgenii Stepanov | 81bea1b | 2017-01-20 14:12:08 -0800 | [diff] [blame] | 393 | # __cfi_check needs to be built as Thumb (see the code in linker_cfi.cpp). |
| 394 | # LLVM is not set up to do this on a function basis, so force Thumb on the |
| 395 | # entire module. |
| 396 | LOCAL_ARM_MODE := thumb |
Vishwath Mohan | 5b69c06 | 2017-02-14 07:55:37 -0800 | [diff] [blame] | 397 | my_cflags += $(CFI_EXTRA_CFLAGS) |
Evgenii Stepanov | 9b82b3f | 2018-08-31 12:57:26 -0700 | [diff] [blame] | 398 | my_asflags += $(CFI_EXTRA_ASFLAGS) |
Vishwath Mohan | 85f7244 | 2017-11-01 09:21:20 +0000 | [diff] [blame] | 399 | # Only append the default visibility flag if -fvisibility has not already been |
| 400 | # set to hidden. |
| 401 | ifeq ($(filter -fvisibility=hidden,$(LOCAL_CFLAGS)),) |
| 402 | my_cflags += -fvisibility=default |
| 403 | endif |
Vishwath Mohan | 5b69c06 | 2017-02-14 07:55:37 -0800 | [diff] [blame] | 404 | my_ldflags += $(CFI_EXTRA_LDFLAGS) |
Evgenii Stepanov | e1b96f3 | 2017-01-23 16:57:38 -0800 | [diff] [blame] | 405 | my_arflags += --plugin $(LLVM_PREBUILTS_PATH)/../lib64/LLVMgold.so |
Vishwath Mohan | 85f7244 | 2017-11-01 09:21:20 +0000 | [diff] [blame] | 406 | |
| 407 | ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
| 408 | my_ldflags := $(filter-out -fsanitize-cfi-cross-dso,$(my_ldflags)) |
| 409 | my_cflags := $(filter-out -fsanitize-cfi-cross-dso,$(my_cflags)) |
| 410 | else |
| 411 | # Apply the version script to non-static executables |
| 412 | my_ldflags += -Wl,--version-script,build/soong/cc/config/cfi_exports.map |
| 413 | LOCAL_ADDITIONAL_DEPENDENCIES += build/soong/cc/config/cfi_exports.map |
| 414 | endif |
Evgenii Stepanov | 202c7a7 | 2016-07-07 10:56:39 -0700 | [diff] [blame] | 415 | endif |
| 416 | |
Chih-Hung Hsieh | ad741e6 | 2016-03-09 14:54:55 -0800 | [diff] [blame] | 417 | # If local or global modules need ASAN, add linker flags. |
| 418 | ifneq ($(filter address,$(my_global_sanitize) $(my_sanitize)),) |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 419 | my_ldflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS) |
| 420 | ifdef LOCAL_IS_HOST_MODULE |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 421 | # -nodefaultlibs (provided with libc++) prevents the driver from linking |
| 422 | # libraries needed with -fsanitize=address. http://b/18650275 (WAI) |
Dan Albert | 1f0d530 | 2015-04-28 14:55:50 -0700 | [diff] [blame] | 423 | my_ldflags += -Wl,--no-as-needed |
Dan Albert | 4ae5d4b | 2014-10-31 16:23:08 -0700 | [diff] [blame] | 424 | else |
Chih-Hung Hsieh | ad741e6 | 2016-03-09 14:54:55 -0800 | [diff] [blame] | 425 | # Add asan libraries unless LOCAL_MODULE is the asan library. |
Evgenii Stepanov | f0b15e1 | 2015-04-24 16:34:47 -0700 | [diff] [blame] | 426 | # ASan runtime library must be the first in the link order. |
Chih-Hung Hsieh | ad741e6 | 2016-03-09 14:54:55 -0800 | [diff] [blame] | 427 | ifeq (,$(filter $(LOCAL_MODULE),$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RUNTIME_LIBRARY))) |
| 428 | my_shared_libraries := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RUNTIME_LIBRARY) \ |
| 429 | $(my_shared_libraries) |
| 430 | endif |
Chih-Hung Hsieh | ad741e6 | 2016-03-09 14:54:55 -0800 | [diff] [blame] | 431 | |
| 432 | # Do not add unnecessary dependency in shared libraries. |
| 433 | ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES) |
| 434 | my_ldflags += -Wl,--as-needed |
| 435 | endif |
Ying Wang | a05e222 | 2015-08-17 16:13:24 -0700 | [diff] [blame] | 436 | |
Mikhail Naganov | aa73cef | 2018-12-20 15:55:08 -0800 | [diff] [blame] | 437 | ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) |
Colin Cross | d08699e | 2016-07-17 15:28:07 -0700 | [diff] [blame] | 438 | ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
| 439 | my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER) |
| 440 | # Make sure linker_asan get installed. |
Logan Chien | c6d2cf8 | 2019-01-31 17:07:50 +0800 | [diff] [blame] | 441 | $(LOCAL_INSTALLED_MODULE) : | $(PRODUCT_OUT)$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER_FILE) |
Colin Cross | d08699e | 2016-07-17 15:28:07 -0700 | [diff] [blame] | 442 | endif |
| 443 | endif |
Dan Albert | 08cca28 | 2014-12-11 18:56:26 -0800 | [diff] [blame] | 444 | endif |
| 445 | endif |
| 446 | |
Chih-Hung Hsieh | ad741e6 | 2016-03-09 14:54:55 -0800 | [diff] [blame] | 447 | # If local module needs ASAN, add compiler flags. |
| 448 | ifneq ($(filter address,$(my_sanitize)),) |
| 449 | # Frame pointer based unwinder in ASan requires ARM frame setup. |
| 450 | LOCAL_ARM_MODE := arm |
| 451 | my_cflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS) |
| 452 | ifndef LOCAL_IS_HOST_MODULE |
| 453 | my_cflags += -mllvm -asan-globals=0 |
| 454 | endif |
| 455 | endif |
| 456 | |
Evgenii Stepanov | aec1ffc | 2018-08-28 13:52:08 -0700 | [diff] [blame] | 457 | # If local module needs HWASAN, add compiler flags. |
| 458 | ifneq ($(filter hwaddress,$(my_sanitize)),) |
| 459 | my_cflags += $(HWADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS) |
Florian Mayer | 97222e1 | 2023-06-01 14:16:28 -0700 | [diff] [blame] | 460 | |
| 461 | ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),) |
| 462 | ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
| 463 | my_linker := /system/bin/linker_hwasan64 |
| 464 | endif |
| 465 | endif |
| 466 | |
Evgenii Stepanov | aec1ffc | 2018-08-28 13:52:08 -0700 | [diff] [blame] | 467 | endif |
| 468 | |
Dan Willemsen | 58634e1 | 2020-03-06 18:09:06 -0800 | [diff] [blame] | 469 | # Use minimal diagnostics when integer overflow is enabled; never do it for HOST modules |
| 470 | ifeq ($(LOCAL_IS_HOST_MODULE),) |
Ivan Lozano | 911cb99 | 2018-02-21 13:41:05 -0800 | [diff] [blame] | 471 | # Pre-emptively add UBSAN minimal runtime incase a static library dependency requires it |
| 472 | ifeq ($(filter STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)),) |
| 473 | ifndef LOCAL_SDK_VERSION |
| 474 | my_static_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_MINIMAL_RUNTIME_LIBRARY) |
Ivan Lozano | e508169 | 2018-05-11 14:09:36 -0700 | [diff] [blame] | 475 | my_ldflags += -Wl,--exclude-libs,$($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_MINIMAL_RUNTIME_LIBRARY).a |
Ivan Lozano | 911cb99 | 2018-02-21 13:41:05 -0800 | [diff] [blame] | 476 | endif |
| 477 | endif |
| 478 | ifneq ($(filter unsigned-integer-overflow signed-integer-overflow integer,$(my_sanitize)),) |
Kostya Kortchinsky | 47c10eb | 2018-10-11 08:56:12 -0700 | [diff] [blame] | 479 | ifeq ($(filter unsigned-integer-overflow signed-integer-overflow integer,$(my_sanitize_diag)),) |
Ivan Lozano | 911cb99 | 2018-02-21 13:41:05 -0800 | [diff] [blame] | 480 | ifeq ($(filter cfi,$(my_sanitize_diag)),) |
Mitch Phillips | ee8f4a0 | 2019-05-01 14:37:33 -0700 | [diff] [blame] | 481 | ifeq ($(filter address hwaddress fuzzer-no-link,$(my_sanitize)),) |
Ivan Lozano | 911cb99 | 2018-02-21 13:41:05 -0800 | [diff] [blame] | 482 | my_cflags += -fsanitize-minimal-runtime |
| 483 | my_cflags += -fno-sanitize-trap=integer |
| 484 | my_cflags += -fno-sanitize-recover=integer |
| 485 | endif |
| 486 | endif |
| 487 | endif |
| 488 | endif |
| 489 | endif |
| 490 | |
Kostya Kortchinsky | 47c10eb | 2018-10-11 08:56:12 -0700 | [diff] [blame] | 491 | # For Scudo, we opt for the minimal runtime, unless some diagnostics are enabled. |
| 492 | ifneq ($(filter scudo,$(my_sanitize)),) |
| 493 | ifeq ($(filter unsigned-integer-overflow signed-integer-overflow integer cfi,$(my_sanitize_diag)),) |
| 494 | my_cflags += -fsanitize-minimal-runtime |
| 495 | endif |
| 496 | ifneq ($(filter -fsanitize-minimal-runtime,$(my_cflags)),) |
| 497 | my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)SCUDO_MINIMAL_RUNTIME_LIBRARY) |
| 498 | else |
| 499 | my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)SCUDO_RUNTIME_LIBRARY) |
| 500 | endif |
| 501 | endif |
| 502 | |
Dan Albert | 9f17655 | 2015-04-28 11:26:45 -0700 | [diff] [blame] | 503 | ifneq ($(strip $(LOCAL_SANITIZE_RECOVER)),) |
| 504 | recover_arg := $(subst $(space),$(comma),$(LOCAL_SANITIZE_RECOVER)), |
Dan Albert | 4111d48 | 2015-04-16 18:08:44 -0700 | [diff] [blame] | 505 | my_cflags += -fsanitize-recover=$(recover_arg) |
| 506 | endif |
Evgenii Stepanov | 202c7a7 | 2016-07-07 10:56:39 -0700 | [diff] [blame] | 507 | |
Ivan Lozano | 5fb2de7 | 2018-12-12 10:04:34 -0800 | [diff] [blame] | 508 | ifneq ($(strip $(LOCAL_SANITIZE_NO_RECOVER)),) |
| 509 | no_recover_arg := $(subst $(space),$(comma),$(LOCAL_SANITIZE_NO_RECOVER)), |
| 510 | my_cflags += -fno-sanitize-recover=$(no_recover_arg) |
| 511 | endif |
| 512 | |
Vishwath Mohan | 8dcfdce | 2017-01-18 17:50:29 -0800 | [diff] [blame] | 513 | ifneq ($(my_sanitize_diag),) |
Vishwath Mohan | 85f7244 | 2017-11-01 09:21:20 +0000 | [diff] [blame] | 514 | # TODO(vishwath): Add diagnostic support for static executables once |
| 515 | # we switch to clang-4393122 (which adds the static ubsan runtime |
| 516 | # that this depends on) |
| 517 | ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true) |
| 518 | notrap_arg := $(subst $(space),$(comma),$(my_sanitize_diag)), |
| 519 | my_cflags += -fno-sanitize-trap=$(notrap_arg) |
| 520 | # Diagnostic requires a runtime library, unless ASan or TSan are also enabled. |
Evgenii Stepanov | 8841a7f | 2018-07-27 11:54:32 -0700 | [diff] [blame] | 521 | ifeq ($(filter address thread scudo hwaddress,$(my_sanitize)),) |
Vishwath Mohan | 85f7244 | 2017-11-01 09:21:20 +0000 | [diff] [blame] | 522 | # Does not have to be the first DT_NEEDED unlike ASan. |
| 523 | my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY) |
| 524 | endif |
Evgenii Stepanov | 202c7a7 | 2016-07-07 10:56:39 -0700 | [diff] [blame] | 525 | endif |
| 526 | endif |
Chih-Hung Hsieh | 1871062 | 2018-11-17 20:18:08 -0800 | [diff] [blame] | 527 | |
| 528 | # http://b/119329758, Android core does not boot up with this sanitizer yet. |
| 529 | # Previously sanitized modules might not pass new implicit-integer-sign-change check. |
| 530 | # Disable this check unless it has been explicitly specified. |
| 531 | ifneq ($(findstring fsanitize,$(my_cflags)),) |
| 532 | ifneq ($(findstring integer,$(my_cflags)),) |
| 533 | ifeq ($(findstring sanitize=implicit-integer-sign-change,$(my_cflags)),) |
| 534 | my_cflags += -fno-sanitize=implicit-integer-sign-change |
| 535 | endif |
| 536 | endif |
| 537 | endif |
Yabin Cui | 462c12d | 2021-01-14 14:05:54 -0800 | [diff] [blame] | 538 | |
| 539 | # http://b/177566116, libc++ may crash with this sanitizer. |
| 540 | # Disable this check unless it has been explicitly specified. |
| 541 | ifneq ($(findstring fsanitize,$(my_cflags)),) |
| 542 | ifneq ($(findstring integer,$(my_cflags)),) |
| 543 | ifeq ($(findstring sanitize=unsigned-shift-base,$(my_cflags)),) |
| 544 | my_cflags += -fno-sanitize=unsigned-shift-base |
| 545 | endif |
| 546 | endif |
| 547 | endif |