1##############################################
2## Perform configuration steps for sanitizers.
3##############################################
4
5my_sanitize := $(strip $(LOCAL_SANITIZE))
6my_sanitize_diag := $(strip $(LOCAL_SANITIZE_DIAG))
7
8my_global_sanitize :=
9my_global_sanitize_diag :=
10ifdef LOCAL_IS_HOST_MODULE
11  ifneq ($($(my_prefix)OS),windows)
12    my_global_sanitize := $(strip $(SANITIZE_HOST))
13
14    # SANITIZE_HOST=true is a deprecated way to say SANITIZE_HOST=address.
15    my_global_sanitize := $(subst true,address,$(my_global_sanitize))
16  endif
17else
18  my_global_sanitize := $(strip $(SANITIZE_TARGET))
19  my_global_sanitize_diag := $(strip $(SANITIZE_TARGET_DIAG))
20endif
21
22# Disable global integer_overflow in excluded paths.
23ifneq ($(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
32endif
33
34# Global integer sanitization doesn't support static modules.
35ifeq ($(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))
38endif
39ifeq ($(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))
42endif
43
44# Disable global CFI in excluded paths
45ifneq ($(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
54endif
55
56# Disable global memtag_heap in excluded paths
57ifneq ($(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
66endif
67
68ifneq ($(my_global_sanitize),)
69  my_sanitize := $(my_global_sanitize) $(my_sanitize)
70endif
71ifneq ($(my_global_sanitize_diag),)
72  my_sanitize_diag := $(my_global_sanitize_diag) $(my_sanitize_diag)
73endif
74
75# The sanitizer specified in the product configuration wins over the previous.
76ifneq ($(SANITIZER.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG),)
77  my_sanitize := $(SANITIZER.$(TARGET_PRODUCT).$(LOCAL_MODULE).CONFIG)
78  ifeq ($(my_sanitize),never)
79    my_sanitize :=
80    my_sanitize_diag :=
81  endif
82endif
83
84ifndef 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 :=
89    my_sanitize_diag :=
90  endif
91endif
92
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.
95ifneq (,$(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 :=
100      my_sanitize_diag :=
101    endif
102  endif
103endif
104
105# Don't apply sanitizers to NDK code.
106ifdef LOCAL_SDK_VERSION
107  my_sanitize :=
108  my_global_sanitize :=
109  my_sanitize_diag :=
110endif
111
112# Never always wins.
113ifeq ($(LOCAL_SANITIZE),never)
114  my_sanitize :=
115  my_sanitize_diag :=
116endif
117
118# Enable CFI in included paths.
119ifeq ($(filter cfi, $(my_sanitize)),)
120  combined_include_paths := $(CFI_INCLUDE_PATHS) \
121                            $(PRODUCT_CFI_INCLUDE_PATHS)
122  combined_exclude_paths := $(CFI_EXCLUDE_PATHS) \
123                            $(PRODUCT_CFI_EXCLUDE_PATHS)
124
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)
130    endif
131  endif
132endif
133
134# Enable memtag_heap in included paths (for Arm64 only).
135ifeq ($(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)
141    combined_exclude_paths := $(MEMTAG_HEAP_EXCLUDE_PATHS) \
142                              $(PRODUCT_MEMTAG_HEAP_EXCLUDE_PATHS)
143
144    ifeq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_exclude_paths)),\
145          $(filter $(dir)%,$(LOCAL_PATH)))),)
146      ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_sync_include_paths)),\
147             $(filter $(dir)%,$(LOCAL_PATH)))),)
148        my_sanitize := memtag_heap $(my_sanitize)
149        my_sanitize_diag := memtag_heap $(my_sanitize_diag)
150      else ifneq ($(strip $(foreach dir,$(subst $(comma),$(space),$(combined_async_include_paths)),\
151             $(filter $(dir)%,$(LOCAL_PATH)))),)
152        my_sanitize := memtag_heap $(my_sanitize)
153      endif
154    endif
155  endif
156endif
157
158# If CFI is disabled globally, remove it from my_sanitize.
159ifeq ($(strip $(ENABLE_CFI)),false)
160  my_sanitize := $(filter-out cfi,$(my_sanitize))
161  my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag))
162endif
163
164# Also disable CFI if ASAN is enabled.
165ifneq ($(filter address,$(my_sanitize)),)
166  my_sanitize := $(filter-out cfi,$(my_sanitize))
167  my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag))
168endif
169
170# Disable memtag for host targets. Host executables in AndroidMk files are
171# deprecated, but some partners still have them floating around.
172ifdef LOCAL_IS_HOST_MODULE
173  my_sanitize := $(filter-out memtag_heap,$(my_sanitize))
174  my_sanitize_diag := $(filter-out memtag_heap,$(my_sanitize_diag))
175endif
176
177# Disable sanitizers which need the UBSan runtime for host targets.
178ifdef LOCAL_IS_HOST_MODULE
179  my_sanitize := $(filter-out cfi,$(my_sanitize))
180  my_sanitize_diag := $(filter-out cfi,$(my_sanitize_diag))
181  my_sanitize := $(filter-out signed-integer-overflow unsigned-integer-overflow integer_overflow,$(my_sanitize))
182  my_sanitize_diag := $(filter-out signed-integer-overflow unsigned-integer-overflow integer_overflow,$(my_sanitize_diag))
183endif
184
185# Support for local sanitize blacklist paths.
186ifneq ($(my_sanitize)$(my_global_sanitize),)
187  ifneq ($(LOCAL_SANITIZE_BLOCKLIST),)
188    my_cflags += -fsanitize-blacklist=$(LOCAL_PATH)/$(LOCAL_SANITIZE_BLOCKLIST)
189  endif
190endif
191
192# Disable integer_overflow if LOCAL_NOSANITIZE=integer.
193ifneq ($(filter integer_overflow, $(my_global_sanitize) $(my_sanitize)),)
194  ifneq ($(filter integer, $(strip $(LOCAL_NOSANITIZE))),)
195    my_sanitize := $(filter-out integer_overflow,$(my_sanitize))
196    my_sanitize_diag := $(filter-out integer_overflow,$(my_sanitize_diag))
197  endif
198endif
199
200my_nosanitize = $(strip $(LOCAL_NOSANITIZE))
201ifneq ($(my_nosanitize),)
202  my_sanitize := $(filter-out $(my_nosanitize),$(my_sanitize))
203endif
204
205ifneq ($(filter arm x86 x86_64,$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)),)
206  my_sanitize := $(filter-out hwaddress,$(my_sanitize))
207  my_sanitize := $(filter-out memtag_heap,$(my_sanitize))
208endif
209
210ifneq ($(filter hwaddress,$(my_sanitize)),)
211  my_sanitize := $(filter-out address,$(my_sanitize))
212  my_sanitize := $(filter-out thread,$(my_sanitize))
213  my_sanitize := $(filter-out cfi,$(my_sanitize))
214endif
215
216ifneq ($(filter hwaddress,$(my_sanitize)),)
217  my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)HWADDRESS_SANITIZER_RUNTIME_LIBRARY)
218  ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
219    ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
220      my_static_libraries := $(my_static_libraries) \
221                             $($(LOCAL_2ND_ARCH_VAR_PREFIX)HWADDRESS_SANITIZER_STATIC_LIBRARY) \
222                             libdl
223    endif
224  endif
225endif
226
227ifneq ($(filter memtag_heap,$(my_sanitize)),)
228  # Add memtag ELF note.
229  ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
230    ifneq ($(filter memtag_heap,$(my_sanitize_diag)),)
231      my_whole_static_libraries += note_memtag_heap_sync
232    else
233      my_whole_static_libraries += note_memtag_heap_async
234    endif
235  endif
236  # This is all that memtag_heap does - it is not an actual -fsanitize argument.
237  # Remove it from the list.
238  my_sanitize := $(filter-out memtag_heap,$(my_sanitize))
239endif
240
241my_sanitize_diag := $(filter-out memtag_heap,$(my_sanitize_diag))
242
243# TSAN is not supported on 32-bit architectures. For non-multilib cases, make
244# its use an error. For multilib cases, don't use it for the 32-bit case.
245ifneq ($(filter thread,$(my_sanitize)),)
246  ifeq ($(my_32_64_bit_suffix),32)
247    ifeq ($(my_module_multilib),both)
248        my_sanitize := $(filter-out thread,$(my_sanitize))
249    else
250        $(error $(LOCAL_PATH): $(LOCAL_MODULE): TSAN cannot be used for 32-bit modules.)
251    endif
252  else
253    my_shared_libraries += $(TSAN_RUNTIME_LIBRARY)
254  endif
255endif
256
257ifneq ($(filter safe-stack,$(my_sanitize)),)
258  ifeq ($(my_32_64_bit_suffix),32)
259    my_sanitize := $(filter-out safe-stack,$(my_sanitize))
260  endif
261endif
262
263# Disable Scudo if ASan or TSan is enabled.
264ifneq ($(filter address thread hwaddress,$(my_sanitize)),)
265  my_sanitize := $(filter-out scudo,$(my_sanitize))
266endif
267
268# Or if disabled globally.
269ifeq ($(PRODUCT_DISABLE_SCUDO),true)
270  my_sanitize := $(filter-out scudo,$(my_sanitize))
271endif
272
273# Undefined symbols can occur if a non-sanitized library links
274# sanitized static libraries. That's OK, because the executable
275# always depends on the ASan runtime library, which defines these
276# symbols.
277ifneq ($(filter address thread,$(strip $(SANITIZE_TARGET))),)
278  ifndef LOCAL_IS_HOST_MODULE
279    ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES)
280      ifeq ($(my_sanitize),)
281        my_allow_undefined_symbols := true
282      endif
283    endif
284  endif
285endif
286
287ifneq ($(filter default-ub,$(my_sanitize)),)
288  my_sanitize := $(CLANG_DEFAULT_UB_CHECKS)
289endif
290
291ifneq ($(filter fuzzer,$(my_sanitize)),)
292  # SANITIZE_TARGET='fuzzer' actually means to create the fuzzer coverage
293  # information, not to link against the fuzzer main().
294  my_sanitize := $(filter-out fuzzer,$(my_sanitize))
295  my_sanitize += fuzzer-no-link
296
297  # TODO(b/131771163): Disable LTO for fuzzer builds. Note that Cfi causes
298  # dependency on LTO.
299  my_sanitize := $(filter-out cfi,$(my_sanitize))
300  my_cflags += -fno-lto
301  my_ldflags += -fno-lto
302
303  # TODO(b/133876586): Disable experimental pass manager for fuzzer builds.
304  my_cflags += -fno-experimental-new-pass-manager
305endif
306
307ifneq ($(filter integer_overflow,$(my_sanitize)),)
308  # Respect LOCAL_NOSANITIZE for integer-overflow flags.
309  ifeq ($(filter signed-integer-overflow, $(strip $(LOCAL_NOSANITIZE))),)
310    my_sanitize += signed-integer-overflow
311  endif
312  ifeq ($(filter unsigned-integer-overflow, $(strip $(LOCAL_NOSANITIZE))),)
313    my_sanitize += unsigned-integer-overflow
314  endif
315  my_cflags += $(INTEGER_OVERFLOW_EXTRA_CFLAGS)
316
317  # Check for diagnostics mode.
318  ifneq ($(filter integer_overflow,$(my_sanitize_diag)),)
319    ifneq ($(filter SHARED_LIBRARIES EXECUTABLES,$(LOCAL_MODULE_CLASS)),)
320      ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
321        my_sanitize_diag += signed-integer-overflow
322        my_sanitize_diag += unsigned-integer-overflow
323      else
324        $(call pretty-error,Make cannot apply integer overflow diagnostics to static binary.)
325      endif
326    else
327      $(call pretty-error,Make cannot apply integer overflow diagnostics to static library.)
328    endif
329  endif
330  my_sanitize := $(filter-out integer_overflow,$(my_sanitize))
331endif
332
333# Makes sure integer_overflow diagnostics is removed from the diagnostics list
334# even if integer_overflow is not set for some reason.
335ifneq ($(filter integer_overflow,$(my_sanitize_diag)),)
336  my_sanitize_diag := $(filter-out integer_overflow,$(my_sanitize_diag))
337endif
338
339ifneq ($(my_sanitize),)
340  fsanitize_arg := $(subst $(space),$(comma),$(my_sanitize))
341  my_cflags += -fsanitize=$(fsanitize_arg)
342  my_asflags += -fsanitize=$(fsanitize_arg)
343
344  # When fuzzing, we wish to crash with diagnostics on any bug.
345  ifneq ($(filter fuzzer-no-link,$(my_sanitize)),)
346    my_cflags += -fno-sanitize-trap=all
347    my_cflags += -fno-sanitize-recover=all
348    my_ldflags += -fsanitize=fuzzer-no-link
349  else ifdef LOCAL_IS_HOST_MODULE
350    my_cflags += -fno-sanitize-recover=all
351    my_ldflags += -fsanitize=$(fsanitize_arg)
352  else
353    my_cflags += -fsanitize-trap=all
354    my_cflags += -ftrap-function=abort
355    ifneq ($(filter address thread,$(my_sanitize)),)
356      my_cflags += -fno-sanitize-trap=address,thread
357      my_shared_libraries += libdl
358    endif
359  endif
360endif
361
362ifneq ($(filter cfi,$(my_sanitize)),)
363  # __cfi_check needs to be built as Thumb (see the code in linker_cfi.cpp).
364  # LLVM is not set up to do this on a function basis, so force Thumb on the
365  # entire module.
366  LOCAL_ARM_MODE := thumb
367  my_cflags += $(CFI_EXTRA_CFLAGS)
368  my_asflags += $(CFI_EXTRA_ASFLAGS)
369  # Only append the default visibility flag if -fvisibility has not already been
370  # set to hidden.
371  ifeq ($(filter -fvisibility=hidden,$(LOCAL_CFLAGS)),)
372    my_cflags += -fvisibility=default
373  endif
374  my_ldflags += $(CFI_EXTRA_LDFLAGS)
375  my_arflags += --plugin $(LLVM_PREBUILTS_PATH)/../lib64/LLVMgold.so
376
377  ifeq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
378        my_ldflags := $(filter-out -fsanitize-cfi-cross-dso,$(my_ldflags))
379        my_cflags := $(filter-out -fsanitize-cfi-cross-dso,$(my_cflags))
380  else
381        # Apply the version script to non-static executables
382        my_ldflags += -Wl,--version-script,build/soong/cc/config/cfi_exports.map
383        LOCAL_ADDITIONAL_DEPENDENCIES += build/soong/cc/config/cfi_exports.map
384  endif
385endif
386
387# If local or global modules need ASAN, add linker flags.
388ifneq ($(filter address,$(my_global_sanitize) $(my_sanitize)),)
389  my_ldflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_LDFLAGS)
390  ifdef LOCAL_IS_HOST_MODULE
391    # -nodefaultlibs (provided with libc++) prevents the driver from linking
392    # libraries needed with -fsanitize=address. http://b/18650275 (WAI)
393    my_ldflags += -Wl,--no-as-needed
394  else
395    # Add asan libraries unless LOCAL_MODULE is the asan library.
396    # ASan runtime library must be the first in the link order.
397    ifeq (,$(filter $(LOCAL_MODULE),$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RUNTIME_LIBRARY)))
398      my_shared_libraries := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_RUNTIME_LIBRARY) \
399                             $(my_shared_libraries)
400    endif
401
402    # Do not add unnecessary dependency in shared libraries.
403    ifeq ($(LOCAL_MODULE_CLASS),SHARED_LIBRARIES)
404      my_ldflags += -Wl,--as-needed
405    endif
406
407    ifneq ($(filter EXECUTABLES NATIVE_TESTS,$(LOCAL_MODULE_CLASS)),)
408      ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
409        my_linker := $($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER)
410        # Make sure linker_asan get installed.
411        $(LOCAL_INSTALLED_MODULE) : | $(PRODUCT_OUT)$($(LOCAL_2ND_ARCH_VAR_PREFIX)ADDRESS_SANITIZER_LINKER_FILE)
412      endif
413    endif
414  endif
415endif
416
417# If local module needs ASAN, add compiler flags.
418ifneq ($(filter address,$(my_sanitize)),)
419  # Frame pointer based unwinder in ASan requires ARM frame setup.
420  LOCAL_ARM_MODE := arm
421  my_cflags += $(ADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS)
422  ifndef LOCAL_IS_HOST_MODULE
423    my_cflags += -mllvm -asan-globals=0
424  endif
425endif
426
427# If local module needs HWASAN, add compiler flags.
428ifneq ($(filter hwaddress,$(my_sanitize)),)
429  my_cflags += $(HWADDRESS_SANITIZER_CONFIG_EXTRA_CFLAGS)
430endif
431
432# Use minimal diagnostics when integer overflow is enabled; never do it for HOST modules
433ifeq ($(LOCAL_IS_HOST_MODULE),)
434  # Pre-emptively add UBSAN minimal runtime incase a static library dependency requires it
435  ifeq ($(filter STATIC_LIBRARIES,$(LOCAL_MODULE_CLASS)),)
436    ifndef LOCAL_SDK_VERSION
437      my_static_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_MINIMAL_RUNTIME_LIBRARY)
438      my_ldflags += -Wl,--exclude-libs,$($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_MINIMAL_RUNTIME_LIBRARY).a
439    endif
440  endif
441  ifneq ($(filter unsigned-integer-overflow signed-integer-overflow integer,$(my_sanitize)),)
442    ifeq ($(filter unsigned-integer-overflow signed-integer-overflow integer,$(my_sanitize_diag)),)
443      ifeq ($(filter cfi,$(my_sanitize_diag)),)
444        ifeq ($(filter address hwaddress fuzzer-no-link,$(my_sanitize)),)
445          my_cflags += -fsanitize-minimal-runtime
446          my_cflags += -fno-sanitize-trap=integer
447          my_cflags += -fno-sanitize-recover=integer
448        endif
449      endif
450    endif
451  endif
452endif
453
454# For Scudo, we opt for the minimal runtime, unless some diagnostics are enabled.
455ifneq ($(filter scudo,$(my_sanitize)),)
456  ifeq ($(filter unsigned-integer-overflow signed-integer-overflow integer cfi,$(my_sanitize_diag)),)
457    my_cflags += -fsanitize-minimal-runtime
458  endif
459  ifneq ($(filter -fsanitize-minimal-runtime,$(my_cflags)),)
460    my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)SCUDO_MINIMAL_RUNTIME_LIBRARY)
461  else
462    my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)SCUDO_RUNTIME_LIBRARY)
463  endif
464endif
465
466ifneq ($(strip $(LOCAL_SANITIZE_RECOVER)),)
467  recover_arg := $(subst $(space),$(comma),$(LOCAL_SANITIZE_RECOVER)),
468  my_cflags += -fsanitize-recover=$(recover_arg)
469endif
470
471ifneq ($(strip $(LOCAL_SANITIZE_NO_RECOVER)),)
472  no_recover_arg := $(subst $(space),$(comma),$(LOCAL_SANITIZE_NO_RECOVER)),
473  my_cflags += -fno-sanitize-recover=$(no_recover_arg)
474endif
475
476ifneq ($(my_sanitize_diag),)
477  # TODO(vishwath): Add diagnostic support for static executables once
478  # we switch to clang-4393122 (which adds the static ubsan runtime
479  # that this depends on)
480  ifneq ($(LOCAL_FORCE_STATIC_EXECUTABLE),true)
481    notrap_arg := $(subst $(space),$(comma),$(my_sanitize_diag)),
482    my_cflags += -fno-sanitize-trap=$(notrap_arg)
483    # Diagnostic requires a runtime library, unless ASan or TSan are also enabled.
484    ifeq ($(filter address thread scudo hwaddress,$(my_sanitize)),)
485      # Does not have to be the first DT_NEEDED unlike ASan.
486      my_shared_libraries += $($(LOCAL_2ND_ARCH_VAR_PREFIX)UBSAN_RUNTIME_LIBRARY)
487    endif
488  endif
489endif
490
491# http://b/119329758, Android core does not boot up with this sanitizer yet.
492# Previously sanitized modules might not pass new implicit-integer-sign-change check.
493# Disable this check unless it has been explicitly specified.
494ifneq ($(findstring fsanitize,$(my_cflags)),)
495  ifneq ($(findstring integer,$(my_cflags)),)
496    ifeq ($(findstring sanitize=implicit-integer-sign-change,$(my_cflags)),)
497      my_cflags += -fno-sanitize=implicit-integer-sign-change
498    endif
499  endif
500endif
501
502# http://b/177566116, libc++ may crash with this sanitizer.
503# Disable this check unless it has been explicitly specified.
504ifneq ($(findstring fsanitize,$(my_cflags)),)
505  ifneq ($(findstring integer,$(my_cflags)),)
506    ifeq ($(findstring sanitize=unsigned-shift-base,$(my_cflags)),)
507      my_cflags += -fno-sanitize=unsigned-shift-base
508    endif
509  endif
510endif
511