[PATCH] D96573: [Clang][ASan] Teach Clang to not emit ASan module destructors when compiling with `-mkernel` or `-fapple-kext`.
Dan Liew via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 11 19:38:44 PST 2021
delcypher created this revision.
delcypher added reviewers: arphaman, kubamracek, yln, aralisza, kcc, vitalybuka.
delcypher requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
rdar://71609176
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D96573
Files:
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/darwin-asan-mkernel-kext.c
Index: clang/test/Driver/darwin-asan-mkernel-kext.c
===================================================================
--- /dev/null
+++ 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"
Index: clang/lib/Driver/SanitizerArgs.cpp
===================================================================
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -825,6 +825,12 @@
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());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96573.323214.patch
Type: text/x-patch
Size: 1590 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210212/a33cd7fb/attachment.bin>
More information about the cfe-commits
mailing list