Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 30 Jul 2021 18:14:14 GMT
From:      Brooks Davis <brooks@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: f8617a246623 - main - devel/llvm12: Add patches to enable kernel sanitizers on FreeBSD
Message-ID:  <202107301814.16UIEEUV058708@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by brooks:

URL: https://cgit.FreeBSD.org/ports/commit/?id=f8617a24662331dd03d72d4bc36a0238ec54d119

commit f8617a24662331dd03d72d4bc36a0238ec54d119
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2021-07-30 18:03:38 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2021-07-30 18:12:59 +0000

    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
---
 devel/llvm12/Makefile                              |  2 +-
 .../patch-clang_lib_Driver_ToolChains_FreeBSD.cpp  | 33 ++++++++++++++++++++++
 .../files/patch-clang_test_Driver_fsanitize.c      | 16 +++++++++++
 ...Transforms_Instrumentation_AddressSanitizer.cpp | 26 +++++++++++++++++
 4 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/devel/llvm12/Makefile b/devel/llvm12/Makefile
index 57f6aeb8fcb4..5d4e7b48d8d8 100644
--- a/devel/llvm12/Makefile
+++ b/devel/llvm12/Makefile
@@ -1,6 +1,6 @@
 PORTNAME=	llvm
 DISTVERSION=	12.0.1
-PORTREVISION=	0
+PORTREVISION=	1
 CATEGORIES=	devel lang
 MASTER_SITES=	https://github.com/llvm/llvm-project/releases/download/llvmorg-${DISTVERSION:S/rc/-rc/}/ \
 		https://${PRE_}releases.llvm.org/${LLVM_RELEASE}/${RCDIR}
diff --git a/devel/llvm12/files/patch-clang_lib_Driver_ToolChains_FreeBSD.cpp b/devel/llvm12/files/patch-clang_lib_Driver_ToolChains_FreeBSD.cpp
new file mode 100644
index 000000000000..4c13ad977b21
--- /dev/null
+++ b/devel/llvm12/files/patch-clang_lib_Driver_ToolChains_FreeBSD.cpp
@@ -0,0 +1,33 @@
+[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;
+ }
+ 
diff --git a/devel/llvm12/files/patch-clang_test_Driver_fsanitize.c b/devel/llvm12/files/patch-clang_test_Driver_fsanitize.c
new file mode 100644
index 000000000000..0c616740ceca
--- /dev/null
+++ b/devel/llvm12/files/patch-clang_test_Driver_fsanitize.c
@@ -0,0 +1,16 @@
+--- clang/test/Driver/fsanitize.c.orig	2021-06-28 16:23:38 UTC
++++ clang/test/Driver/fsanitize.c
+@@ -689,7 +689,13 @@
+ // RUN: %clang -target x86_64-unknown-cloudabi -fsanitize=safe-stack %s -### 2>&1 | FileCheck %s -check-prefix=SAFESTACK-CLOUDABI
+ // SAFESTACK-CLOUDABI: "-fsanitize=safe-stack"
+ 
++// RUN: %clang -target x86_64--freebsd -fsanitize=kernel-address %s -### 2>&1 | FileCheck %s -check-prefix=KERNEL-ADDRESS-FREEBSD
++// RUN: %clang -target aarch64--freebsd -fsanitize=kernel-address %s -### 2>&1 | FileCheck %s -check-prefix=KERNEL-ADDRESS-FREEBSD
++// KERNEL-ADDRESS-FREEBSD: "-fsanitize=kernel-address"
+ 
++// RUN: %clang -target x86_64--freebsd -fsanitize=kernel-memory %s -### 2>&1 | FileCheck %s -check-prefix=KERNEL-MEMORY-FREEBSD
++// RUN: %clang -target aarch64--freebsd -fsanitize=kernel-memory %s -### 2>&1 | FileCheck %s -check-prefix=KERNEL-MEMORY-FREEBSD
++// KERNEL-MEMORY-FREEBSD: "-fsanitize=kernel-memory"
+ 
+ // * NetBSD; please keep ordered as in Sanitizers.def *
+ 
diff --git a/devel/llvm12/files/patch-llvm_lib_Transforms_Instrumentation_AddressSanitizer.cpp b/devel/llvm12/files/patch-llvm_lib_Transforms_Instrumentation_AddressSanitizer.cpp
new file mode 100644
index 000000000000..dd0b84559177
--- /dev/null
+++ b/devel/llvm12/files/patch-llvm_lib_Transforms_Instrumentation_AddressSanitizer.cpp
@@ -0,0 +1,26 @@
+--- llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp.orig	2021-06-28 16:23:38 UTC
++++ llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+@@ -108,6 +108,7 @@ static const uint64_t kAArch64_ShadowOffset64 = 1ULL <
+ static const uint64_t kRISCV64_ShadowOffset64 = 0x20000000;
+ static const uint64_t kFreeBSD_ShadowOffset32 = 1ULL << 30;
+ static const uint64_t kFreeBSD_ShadowOffset64 = 1ULL << 46;
++static const uint64_t kFreeBSDKasan_ShadowOffset64 = 0xdffff7c000000000;
+ static const uint64_t kNetBSD_ShadowOffset32 = 1ULL << 30;
+ static const uint64_t kNetBSD_ShadowOffset64 = 1ULL << 46;
+ static const uint64_t kNetBSDKasan_ShadowOffset64 = 0xdfff900000000000;
+@@ -484,9 +485,12 @@ static ShadowMapping getShadowMapping(Triple &TargetTr
+       Mapping.Offset = kPPC64_ShadowOffset64;
+     else if (IsSystemZ)
+       Mapping.Offset = kSystemZ_ShadowOffset64;
+-    else if (IsFreeBSD && !IsMIPS64)
+-      Mapping.Offset = kFreeBSD_ShadowOffset64;
+-    else if (IsNetBSD) {
++    else if (IsFreeBSD && !IsMIPS64) {
++      if (IsKasan)
++        Mapping.Offset = kFreeBSDKasan_ShadowOffset64;
++      else
++        Mapping.Offset = kFreeBSD_ShadowOffset64;
++    } else if (IsNetBSD) {
+       if (IsKasan)
+         Mapping.Offset = kNetBSDKasan_ShadowOffset64;
+       else



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202107301814.16UIEEUV058708>