ports/devel/llvm12/files/patch-clang_lib_Driver_ToolChains_FreeBSD.cpp
Mark Johnston f8617a2466 devel/llvm12: Add patches to enable kernel sanitizers on FreeBSD
I use CROSS_TOOLCHAIN quite frequently, but can't do so when building
kernels with KASAN or KMSAN enabled since these patches didn't make it
into LLVM 12.  This diff just backports them to the port. I believe this
is low-risk and thus is acceptable for the port, as opposed to waiting
for LLVM 13.

Differential Revision:	https://reviews.freebsd.org/D31316
2021-07-30 19:12:59 +01:00

33 lines
1.2 KiB
C++

[Driver] Default to libc++ on FreeBSD
Downstream may naively translate between DSL and LLVM target
triple. If OS version is lost in the process then Clang would
default to a version that's no longer supported by OS vendor.
https://reviews.llvm.org/D77776
--- clang/lib/Driver/ToolChains/FreeBSD.cpp.orig 2021-06-28 16:23:38 UTC
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -466,6 +466,7 @@ bool FreeBSD::IsUnwindTablesDefault(const ArgList &Arg
bool FreeBSD::isPIEDefault() const { return getSanitizerArgs().requiresPIE(); }
SanitizerMask FreeBSD::getSupportedSanitizers() const {
+ const bool IsAArch64 = getTriple().getArch() == llvm::Triple::aarch64;
const bool IsX86 = getTriple().getArch() == llvm::Triple::x86;
const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64;
const bool IsMIPS64 = getTriple().isMIPS64();
@@ -484,8 +485,13 @@ SanitizerMask FreeBSD::getSupportedSanitizers() const
Res |= SanitizerKind::Fuzzer;
Res |= SanitizerKind::FuzzerNoLink;
}
- if (IsX86_64)
+ if (IsAArch64 || IsX86_64) {
+ Res |= SanitizerKind::KernelAddress;
+ Res |= SanitizerKind::KernelMemory;
+ }
+ if (IsX86_64) {
Res |= SanitizerKind::Memory;
+ }
return Res;
}