Skip to content

Commit 7429c59

Browse files
committed
Enable generation of unwind tables when building with sanitizers.
llvm-svn: 201391
1 parent b866522 commit 7429c59

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

clang/include/clang/Driver/SanitizerArgs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class SanitizerArgs {
4242
NeedsLeakDetection = Leak,
4343
NeedsUbsanRt = Undefined | Integer,
4444
NotAllowedWithTrap = Vptr,
45-
HasZeroBaseShadow = Thread | Memory | DataFlow
45+
HasZeroBaseShadow = Thread | Memory | DataFlow,
46+
NeedsUnwindTables = Address | Thread | Memory | DataFlow
4647
};
4748
unsigned Kind;
4849

@@ -73,6 +74,7 @@ class SanitizerArgs {
7374
bool hasZeroBaseShadow() const {
7475
return (Kind & HasZeroBaseShadow) || AsanZeroBaseShadow;
7576
}
77+
bool needsUnwindTables() const { return Kind & NeedsUnwindTables; }
7678
void addArgs(const llvm::opt::ArgList &Args,
7779
llvm::opt::ArgStringList &CmdArgs) const;
7880

clang/lib/Driver/Tools.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,10 +2536,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
25362536
// -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
25372537
// complicated ways.
25382538
bool AsynchronousUnwindTables =
2539-
Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
2540-
options::OPT_fno_asynchronous_unwind_tables,
2541-
getToolChain().IsUnwindTablesDefault() &&
2542-
!KernelOrKext);
2539+
Args.hasFlag(options::OPT_fasynchronous_unwind_tables,
2540+
options::OPT_fno_asynchronous_unwind_tables,
2541+
(getToolChain().IsUnwindTablesDefault() ||
2542+
getToolChain().getSanitizerArgs().needsUnwindTables()) &&
2543+
!KernelOrKext);
25432544
if (Args.hasFlag(options::OPT_funwind_tables, options::OPT_fno_unwind_tables,
25442545
AsynchronousUnwindTables))
25452546
CmdArgs.push_back("-munwind-tables");
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Sanitizers need to unwind stack at any code location.
2+
// Test that unwind tables are enabled in supported configurations.
3+
4+
// RUN: %clang -target x86_64-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s
5+
// RUN: %clang -target i686-linux-gnu -fsanitize=address %s -### 2>&1 | FileCheck %s
6+
// RUN: %clang -target arm-linux-androideabi -fsanitize=address %s -### 2>&1 | FileCheck %s
7+
// RUN: %clang -target x86_64-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s
8+
// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread %s -### 2>&1 | FileCheck %s
9+
// RUN: %clang -target x86_64-linux-gnu -fsanitize=dataflow %s -### 2>&1 | FileCheck %s
10+
11+
// CHECK: -munwind-tables

0 commit comments

Comments
 (0)