]> granicus.if.org Git - clang/commitdiff
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)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@201391 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e27d257b0a7697ae88209237f3ac7415257acb54..78f6756b9ba9844888994256ddde1ad8f6a86b94 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 c48c061252b3c95c13bb49eed4a6b3f4cb2db6cd..ee64d4213c7a1e610b173f0d0b05add1b1cadd30 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/test/Driver/sanitize_unwind_tables.c b/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