[PATCH] D32064: [asan] Disable ASan global-GC depending on the target and compiler flags
Evgeniy Stepanov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 13 18:21:14 PDT 2017
eugenis updated this revision to Diff 95254.
eugenis retitled this revision from "[asan] Disable ASan global-GC depending on the target and CGOpts" to "[asan] Disable ASan global-GC depending on the target and compiler flags".
Repository:
rL LLVM
https://reviews.llvm.org/D32064
Files:
lib/Driver/SanitizerArgs.cpp
test/Driver/asan-gc.c
Index: test/Driver/asan-gc.c
===================================================================
--- /dev/null
+++ test/Driver/asan-gc.c
@@ -0,0 +1,14 @@
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-data-sections -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address -fno-integrated-as -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITHOUT-GC
+
+// RUN: %clang -target x86_64-apple-macosx10.11.0 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC
+// RUN: %clang -target x86_64-apple-macosx10.11.0 -fsanitize=address -fno-integrated-as %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC
+
+// RUN: %clang -target x86_64-pc-windows-msvc19.0.24215 -fsanitize=address %s -### 2>&1 | FileCheck %s --check-prefix=WITHOUT-GC
+// RUN: %clang -target x86_64-pc-windows-msvc19.0.24215 -fsanitize=address -fdata-sections %s -### 2>&1 | FileCheck %s --check-prefix=WITH-GC
+
+
+// WITHOUT-GC: "-mllvm" "-asan-globals-live-support=0"
+// WITH-GC-NOT: -asan-globals-live-support=0
Index: lib/Driver/SanitizerArgs.cpp
===================================================================
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -618,6 +618,29 @@
CmdArgs.push_back(Args.MakeArgString(LinkerOptionFlag));
}
+// Check if ASan should use GC-friendly instrumentation for globals.
+// First of all, there is no point if -fdata-sections is off (expect for MachO,
+// where this is not a factor). Also, on ELF this feature requires an assembler
+// extension that only works with -integrated-as at the moment.
+static bool useAsanGlobalsGC(const ToolChain &TC,
+ const llvm::opt::ArgList &Args) {
+ bool IntegratedAs = TC.useIntegratedAs();
+ bool DataSections =
+ Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
+ tools::isUseSeparateSections(TC.getTriple()));
+
+ switch (TC.getTriple().getObjectFormat()) {
+ case llvm::Triple::MachO:
+ return true;
+ case llvm::Triple::COFF:
+ return DataSections;
+ case llvm::Triple::ELF:
+ return DataSections && IntegratedAs;
+ default:
+ return false;
+ }
+}
+
void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs,
types::ID InputType) const {
@@ -745,6 +768,11 @@
Sanitizers.Mask & CFIClasses)
<< "-fvisibility=";
}
+
+ if (Sanitizers.has(Address) && !useAsanGlobalsGC(TC, Args)) {
+ CmdArgs.push_back("-mllvm");
+ CmdArgs.push_back("-asan-globals-live-support=0");
+ }
}
SanitizerMask parseArgValues(const Driver &D, const llvm::opt::Arg *A,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32064.95254.patch
Type: text/x-patch
Size: 3038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170414/da917ee6/attachment-0001.bin>
More information about the cfe-commits
mailing list