Enable generation of unwind tables when building with sanitizers.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 14 Feb 2014 08:56:25 +0000 (08:56 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 14 Feb 2014 08:56:25 +0000 (08:56 +0000)
llvm-svn: 201391

clang/include/clang/Driver/SanitizerArgs.h
clang/lib/Driver/Tools.cpp
clang/test/Driver/sanitize_unwind_tables.c [new file with mode: 0644]

index e27d257..78f6756 100644 (file)
@@ -42,7 +42,8 @@ class SanitizerArgs {
     NeedsLeakDetection = Leak,
     NeedsUbsanRt = Undefined | Integer,
     NotAllowedWithTrap = Vptr,
-    HasZeroBaseShadow = Thread | Memory | DataFlow
+    HasZeroBaseShadow = Thread | Memory | DataFlow,
+    NeedsUnwindTables = Address | Thread | Memory | DataFlow
   };
   unsigned Kind;
 
@@ -73,6 +74,7 @@ class SanitizerArgs {
   bool hasZeroBaseShadow() const {
     return (Kind & HasZeroBaseShadow) || AsanZeroBaseShadow;
   }
+  bool needsUnwindTables() const { return Kind & NeedsUnwindTables; }
   void addArgs(const llvm::opt::ArgList &Args,
                llvm::opt::ArgStringList &CmdArgs) const;
 
index c48c061..ee64d42 100644 (file)
@@ -2536,10 +2536,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
   // complicated ways.
   bool AsynchronousUnwindTables =
-    Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
-                 options::OPT_fno_asynchronous_unwind_tables,
-                 getToolChain().IsUnwindTablesDefault() &&
-                 !KernelOrKext);
+      Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
+                   options::OPT_fno_asynchronous_unwind_tables,
+                   (getToolChain().IsUnwindTablesDefault() ||
+                    getToolChain().getSanitizerArgs().needsUnwindTables()) &&
+                       !KernelOrKext);
   if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
                    AsynchronousUnwindTables))
     CmdArgs.push_back("-munwind-tables");
diff --git a/clang/test/Driver/sanitize_unwind_tables.c b/clang/test/Driver/sanitize_unwind_tables.c
new file mode 100644 (file)
index 0000000..8b78899
--- /dev/null
@@ -0,0 +1,11 @@
+// Sanitizers need to unwind stack at any code location.
+// Test that unwind tables are enabled in supported configurations.
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 |  FileCheck %s
+// RUN: %clang -target i686-linux-gnu -fsanitize=address %s -### 2>&1 |  FileCheck %s
+// RUN: %clang -target arm-linux-androideabi -fsanitize=address %s -### 2>&1 |  FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 |  FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread %s -### 2>&1 |  FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=dataflow %s -### 2>&1 |  FileCheck %s
+
+// CHECK: -munwind-tables