From: Evgeniy Stepanov Date: Wed, 16 Dec 2015 00:38:42 +0000 (+0000) Subject: [cfi] Exclude ubsan runtime library from non-diag CFI builds (driver changes). X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6016fffcdd063b4c7f031da274c24a8150abe68;p=clang [cfi] Exclude ubsan runtime library from non-diag CFI builds (driver changes). Split the CFI runtime in two: cfi and cfi_diag. The latter includes UBSan runtime to allow printing diagnostics. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@255736 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/SanitizerArgs.h b/include/clang/Driver/SanitizerArgs.h index 66b6f2ed46..c2611b5cd8 100644 --- a/include/clang/Driver/SanitizerArgs.h +++ b/include/clang/Driver/SanitizerArgs.h @@ -55,6 +55,7 @@ class SanitizerArgs { return Sanitizers.has(SanitizerKind::SafeStack); } bool needsCfiRt() const; + bool needsCfiDiagRt() const; bool requiresPIE() const; bool needsUnwindTables() const; diff --git a/lib/Driver/SanitizerArgs.cpp b/lib/Driver/SanitizerArgs.cpp index 82ac2b0258..2fded1c80d 100644 --- a/lib/Driver/SanitizerArgs.cpp +++ b/lib/Driver/SanitizerArgs.cpp @@ -165,7 +165,11 @@ bool SanitizerArgs::needsUbsanRt() const { } bool SanitizerArgs::needsCfiRt() const { - return CfiCrossDso; + return !(Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso; +} + +bool SanitizerArgs::needsCfiDiagRt() const { + return (Sanitizers.Mask & CFI & ~TrapSanitizers.Mask) && CfiCrossDso; } bool SanitizerArgs::requiresPIE() const { diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 01cef9070a..20a1035bd5 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2794,6 +2794,8 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, StaticRuntimes.push_back("safestack"); if (SanArgs.needsCfiRt()) StaticRuntimes.push_back("cfi"); + if (SanArgs.needsCfiDiagRt()) + StaticRuntimes.push_back("cfi_diag"); } // Should be called before we add system libraries (C++ ABI, libstdc++/libc++, diff --git a/test/Driver/sanitizer-ld.c b/test/Driver/sanitizer-ld.c index 0903ddc61c..ad30ca390d 100644 --- a/test/Driver/sanitizer-ld.c +++ b/test/Driver/sanitizer-ld.c @@ -317,7 +317,7 @@ // RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-LINUX %s // CHECK-CFI-CROSS-DSO-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. -// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-LINUX: libclang_rt.cfi- // CHECK-CFI-CROSS-DSO-LINUX-NOT: libclang_rt. // Cross-DSO CFI with diagnostics links just the CFI runtime. @@ -328,7 +328,7 @@ // RUN: | FileCheck --check-prefix=CHECK-CFI-CROSS-DSO-DIAG-LINUX %s // CHECK-CFI-CROSS-DSO-DIAG-LINUX: "{{.*}}ld{{(.exe)?}}" // CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. -// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi +// CHECK-CFI-CROSS-DSO-DIAG-LINUX: libclang_rt.cfi_diag- // CHECK-CFI-CROSS-DSO-DIAG-LINUX-NOT: libclang_rt. // RUN: %clangxx -fsanitize=address %s -### -o %t.o 2>&1 \