4 # Add the necessary sanitizer flags if requested
5 .if ${MK_ASAN} == "yes" && ${NO_SHARED:Uno:tl} == "no"
6 SANITIZER_CFLAGS+= -fsanitize=address -fPIC
7 # TODO: remove this once all basic errors have been fixed:
8 # https://github.com/google/sanitizers/wiki/AddressSanitizer#faq
9 SANITIZER_CFLAGS+= -fsanitize-recover=address
10 SANITIZER_LDFLAGS+= -fsanitize=address
12 .endif # ${MK_ASAN} == "yes"
14 .if ${MK_UBSAN} == "yes" && ${NO_SHARED:Uno:tl} == "no"
15 # Unlike the other sanitizers, UBSan could also work for static libraries.
16 # However, this currently results in linker errors (even with the
17 # -fsanitize-minimal-runtime flag), so only enable it for dynamically linked
19 SANITIZER_CFLAGS+= -fsanitize=undefined
20 SANITIZER_CFLAGS+= -fsanitize-recover=undefined
21 SANITIZER_LDFLAGS+= -fsanitize=undefined
23 .endif # ${MK_UBSAN} == "yes"
25 .if !defined(BOOTSTRAPPING) && ${_use_sanitizers} != "no" && \
26 ${COMPILER_TYPE} != "clang"
27 .error "Sanitizer instrumentation currently only supported with clang"
30 # For libraries we only instrument the shared and PIE libraries by setting
31 # SHARED_CFLAGS instead of CFLAGS. We do this since static executables are not
32 # compatible with the santizers (interceptors do not work).
33 .if ${_use_sanitizers} != "no"
34 .include "../../lib/libclang_rt/compiler-rt-vars.mk"
35 .if target(__<bsd.lib.mk>__)
36 SHARED_CFLAGS+= ${SANITIZER_CFLAGS}
37 SOLINKOPTS+= ${SANITIZER_LDFLAGS}
38 LDFLAGS:= ${LDFLAGS:N-Wl,-no-undefined:N-Wl,--no-undefined}
40 CFLAGS+= ${SANITIZER_CFLAGS}
41 LDFLAGS+= ${SANITIZER_LDFLAGS}
43 .endif # ${_use_sanitizers} != "no"