diff --git a/lib/libclang_rt/compiler-rt-vars.mk b/lib/libclang_rt/compiler-rt-vars.mk index 974a553e379c..c270009e5d50 100644 --- a/lib/libclang_rt/compiler-rt-vars.mk +++ b/lib/libclang_rt/compiler-rt-vars.mk @@ -1,24 +1,27 @@ CLANG_SUBDIR=clang/12.0.1 CLANGDIR= /usr/lib/${CLANG_SUBDIR} SANITIZER_LIBDIR= ${CLANGDIR}/lib/freebsd # armv[67] is a bit special since we allow a soft-floating version via # CPUTYPE matching *soft*. This variant may not actually work though. .if ${MACHINE_ARCH:Marmv[67]*} != "" && \ (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "") CRTARCH?= armhf .else CRTARCH?= ${MACHINE_ARCH:S/amd64/x86_64/:C/hf$//:S/mipsn32/mips64/} .endif .if ${COMPILER_TYPE} == "clang" # The only way to set the path to the sanitizer libraries with clang is to # override the resource directory. # Note: lib/freebsd is automatically appended to the -resource-dir value. -SANITIZER_LDFLAGS= -resource-dir=${SYSROOT}${CLANGDIR} +SANITIZER_LDFLAGS+= -resource-dir=${SYSROOT}${CLANGDIR} # Also set RPATH to ensure that the dynamically linked runtime libs are found. SANITIZER_LDFLAGS+= -Wl,--enable-new-dtags SANITIZER_LDFLAGS+= -Wl,-rpath,${SANITIZER_LIBDIR} -.else +.elif ${COMPILER_TYPE} != "none" +# This file can be included with COMPILER_TYPE=none during the cleandir phase, +# only emit an error when trying to compile with an unsupported compiler such +# as GCC. .error "Unknown link flags for -fsanitize=... COMPILER_TYPE=${COMPILER_TYPE}" .endif diff --git a/share/mk/bsd.sanitizer.mk b/share/mk/bsd.sanitizer.mk index 56d010767906..567b1da2afde 100644 --- a/share/mk/bsd.sanitizer.mk +++ b/share/mk/bsd.sanitizer.mk @@ -1,43 +1,43 @@ .include -.include "../../lib/libclang_rt/compiler-rt-vars.mk" _use_sanitizers= no # Add the necessary sanitizer flags if requested .if ${MK_ASAN} == "yes" && ${NO_SHARED:Uno:tl} == "no" SANITIZER_CFLAGS+= -fsanitize=address -fPIC # 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 .endif # ${MK_ASAN} == "yes" .if ${MK_UBSAN} == "yes" && ${NO_SHARED:Uno:tl} == "no" # Unlike the other sanitizers, UBSan could also work for static libraries. # 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 && \ +.if !defined(BOOTSTRAPPING) && ${_use_sanitizers} != "no" && \ ${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" +.include "../../lib/libclang_rt/compiler-rt-vars.mk" .if target(____) SHARED_CFLAGS+= ${SANITIZER_CFLAGS} SOLINKOPTS+= ${SANITIZER_LDFLAGS} LDFLAGS:= ${LDFLAGS:N-Wl,-no-undefined:N-Wl,--no-undefined} .else CFLAGS+= ${SANITIZER_CFLAGS} LDFLAGS+= ${SANITIZER_LDFLAGS} .endif .endif # ${_use_sanitizers} != "no"