[clang] fdce098 - [Clang][ASan] Teach Clang to not emit ASan module destructors when compiling with `-mkernel` or `-fapple-kext`.
Dan Liew via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 25 12:03:58 PST 2021
Author: Dan Liew
Date: 2021-02-25T12:02:21-08:00
New Revision: fdce098b49cb038996441741a7b2ab3652502aec
URL: https://github.com/llvm/llvm-project/commit/fdce098b49cb038996441741a7b2ab3652502aec
DIFF: https://github.com/llvm/llvm-project/commit/fdce098b49cb038996441741a7b2ab3652502aec.diff
LOG: [Clang][ASan] Teach Clang to not emit ASan module destructors when compiling with `-mkernel` or `-fapple-kext`.
rdar://71609176
Differential Revision: https://reviews.llvm.org/D96573
Added:
clang/test/Driver/darwin-asan-mkernel-kext.c
Modified:
clang/lib/Driver/SanitizerArgs.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index a3d5a2f567c5..0f9f5d87696c 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -825,6 +825,12 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
AsanInvalidPointerSub = true;
}
+ if (TC.getTriple().isOSDarwin() &&
+ (Args.hasArg(options::OPT_mkernel) ||
+ Args.hasArg(options::OPT_fapple_kext))) {
+ AsanDtorKind = llvm::AsanDtorKind::None;
+ }
+
if (const auto *Arg =
Args.getLastArg(options::OPT_sanitize_address_destructor_kind_EQ)) {
auto parsedAsanDtorKind = AsanDtorKindFromString(Arg->getValue());
diff --git a/clang/test/Driver/darwin-asan-mkernel-kext.c b/clang/test/Driver/darwin-asan-mkernel-kext.c
new file mode 100644
index 000000000000..7827d2ec3fd1
--- /dev/null
+++ b/clang/test/Driver/darwin-asan-mkernel-kext.c
@@ -0,0 +1,15 @@
+// RUN: %clang -target x86_64-apple-darwin10 -fsanitize=address -mkernel -### \
+// RUN: %s 2>&1 | FileCheck %s
+// RUN: %clang -target x86_64-apple-darwin10 -fsanitize=address -fapple-kext \
+// RUN: -### %s 2>&1 | FileCheck %s
+// RUN: %clang -target x86_64-apple-darwin10 -fsanitize=address -fapple-kext \
+// RUN: -mkernel -### %s 2>&1 | FileCheck %s
+
+// CHECK: "-fsanitize-address-destructor-kind=none"
+
+// Check it's possible to override the driver's decision.
+// RUN: %clang -target x86_64-apple-darwin10 -fsanitize=address -fapple-kext \
+// RUN: -mkernel -### -fsanitize-address-destructor-kind=global %s 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-OVERRIDE %s
+
+// CHECK-OVERRIDE: "-fsanitize-address-destructor-kind=global"
More information about the cfe-commits
mailing list