Changeset View
Changeset View
Standalone View
Standalone View
share/mk/bsd.sanitizer.mk
- This file was added.
.include <bsd.opts.mk> | |||||||||
.include "../../lib/libclang_rt/compiler-rt-vars.mk" | |||||||||
_use_sanitizers= no | |||||||||
# Add the necessary sanitizer flags if requested | |||||||||
jrtc27: Tabs after your ='s | |||||||||
Done Inline ActionsStyle is probably to use yes/no not 1/0? jrtc27: Style is probably to use yes/no not 1/0? | |||||||||
.if ${MK_ASAN} == "yes" && ${NO_SHARED:Uno:tl} == "no" | |||||||||
SANITIZER_CFLAGS+= -fsanitize=address -fPIC | |||||||||
Done Inline Actions
jrtc27: | |||||||||
# TODO: remove this once all basic errors have been fixed: | |||||||||
# https://github.com/google/sanitizers/wiki/AddressSanitizer#faq | |||||||||
SANITIZER_CFLAGS+= -fsanitize-recover=address | |||||||||
SANITIZER_LDFLAGS+= -fsanitize=address | |||||||||
_use_sanitizers= yes | |||||||||
Not Done Inline ActionsWhat does the linker do with -fsanitize? In my experiments this wasn't needed. markj: What does the linker do with -fsanitize? In my experiments this wasn't needed. | |||||||||
Done Inline ActionsThis ensures that clang adds the require libraries to the linker command line: the ASAN runtime needs to intercept many libc functions (even when libc is built with ASAN instrumentation). And this runtime is linked as a static library if you pass -fsanitize=address. arichardson: This ensures that clang adds the require libraries to the linker command line: the ASAN runtime… | |||||||||
Not Done Inline ActionsI see, I was relying on the fact that we pass CFLAGS when linking. And I see now that -fsanitize* gets stripped from _LDFLAGS. markj: I see, I was relying on the fact that we pass CFLAGS when linking. And I see now that… | |||||||||
Done Inline ActionsIt does seem like most (all?) linker invocation will get the CFLAGS but I feel that adding it to LDFLAGS as well is safer. arichardson: It does seem like most (all?) linker invocation will get the CFLAGS but I feel that adding it… | |||||||||
.endif # ${MK_ASAN} == "yes" | |||||||||
.if ${MK_UBSAN} == "yes" && ${NO_SHARED:Uno:tl} == "no" | |||||||||
# Unlike the other sanitizers, UBSan could also work for static libraries. | |||||||||
Done Inline ActionsDitto jrtc27: Ditto | |||||||||
# However, this currently results in linker errors (even with the | |||||||||
# -fsanitize-minimal-runtime flag), so only enable it for dynamically linked | |||||||||
# code for now. | |||||||||
SANITIZER_CFLAGS+= -fsanitize=undefined | |||||||||
SANITIZER_CFLAGS+= -fsanitize-recover=undefined | |||||||||
SANITIZER_LDFLAGS+= -fsanitize=undefined | |||||||||
_use_sanitizers= yes | |||||||||
.endif # ${MK_UBSAN} == "yes" | |||||||||
.if !defined(BOOTSTRAPPING) && ${_use_sanitizers} != 0 && \ | |||||||||
${COMPILER_TYPE} != "clang" | |||||||||
.error "Sanitizer instrumentation currently only supported with clang" | |||||||||
.endif | |||||||||
# For libraries we only instrument the shared and PIE libraries by setting | |||||||||
# SHARED_CFLAGS instead of CFLAGS. We do this since static executables are not | |||||||||
# compatible with the santizers (interceptors do not work). | |||||||||
.if ${_use_sanitizers} != "no" | |||||||||
.if target(__<bsd.lib.mk>__) | |||||||||
SHARED_CFLAGS+= ${SANITIZER_CFLAGS} | |||||||||
SOLINKOPTS+= ${SANITIZER_LDFLAGS} | |||||||||
LDFLAGS:= ${LDFLAGS:N-Wl,-no-undefined:N-Wl,--no-undefined} | |||||||||
.else | |||||||||
Done Inline ActionsTab jrtc27: Tab | |||||||||
CFLAGS+= ${SANITIZER_CFLAGS} | |||||||||
LDFLAGS+= ${SANITIZER_LDFLAGS} | |||||||||
.endif | |||||||||
.endif # ${_use_sanitizers} != "no" |
Tabs after your ='s