]> granicus.if.org Git - clang/commitdiff
[CFI] Force LLVM to die if the implicit blacklist files cannot be found.
authorPeter Collingbourne <peter@pcc.me.uk>
Mon, 7 May 2018 20:54:05 +0000 (20:54 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Mon, 7 May 2018 20:54:05 +0000 (20:54 +0000)
Currently LLVM CFI tries to use an implicit blacklist file, currently
in /usr/lib64/clang/<version>/share. If the file is not there, LLVM
happily continues, which causes CFI to add checks to files/functions
that are known to fail, generating binaries that fail. This CL causes
LLVM to die (I hope) if it can't find these implicit blacklist files.

Patch by Caroline Tice!

Differential Revision: https://reviews.llvm.org/D46403

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@331674 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/SanitizerArgs.cpp
test/Driver/Inputs/resource_dir_with_cfi_blacklist/share/cfi_blacklist.txt [new file with mode: 0644]
test/Driver/fsanitize-blacklist.c
test/Frontend/dependency-gen.c

index 8fb0ea08fefedc074b4f506e4b3557773d2f02db..bb8ead215254dc0437990cf42057bbd0ab7b9cbc 100644 (file)
@@ -115,6 +115,10 @@ static void addDefaultBlacklists(const Driver &D, SanitizerMask Kinds,
     llvm::sys::path::append(Path, "share", BL.File);
     if (llvm::sys::fs::exists(Path))
       BlacklistFiles.push_back(Path.str());
+    else if (BL.Mask == CFI)
+      // If cfi_blacklist.txt cannot be found in the resource dir, driver
+      // should fail.
+      D.Diag(clang::diag::err_drv_no_such_file) << Path;
   }
 }
 
diff --git a/test/Driver/Inputs/resource_dir_with_cfi_blacklist/share/cfi_blacklist.txt b/test/Driver/Inputs/resource_dir_with_cfi_blacklist/share/cfi_blacklist.txt
new file mode 100644 (file)
index 0000000..e69de29
index 1ad4aa76b6575c7afd96dde8293838f39ac6f836..609b1f0ba206dc30ff24faa9e4bcaaa380cf78ba 100644 (file)
@@ -62,4 +62,8 @@
 // CHECK-ONLY-FIRST-DISABLED: -fsanitize-blacklist={{.*}}.second
 // CHECK-ONLY_FIRST-DISABLED-NOT: good
 
+// If cfi_blacklist.txt cannot be found in the resource dir, driver should fail.
+// RUN: %clang -target x86_64-linux-gnu -fsanitize=cfi -resource-dir=/dev/null %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-MISSING-CFI-BLACKLIST
+// CHECK-MISSING-CFI-BLACKLIST: error: no such file or directory: '{{.*}}/share/cfi_blacklist.txt'
+
 // DELIMITERS: {{^ *"}}
index e4b0feea16a967d325a0d8755851fa6fce4973d7..5ae88219ac15136e00f1fb78d636e11a37be5e3c 100644 (file)
@@ -21,7 +21,7 @@
 // RUN: %clang -MD -MF - %s -fsyntax-only -I ./ | FileCheck -check-prefix=CHECK-SIX %s
 // CHECK-SIX: {{ }}x.h
 // RUN: echo "fun:foo" > %t.blacklist
-// RUN: %clang -MD -MF - %s -fsyntax-only -fsanitize=cfi-vcall -flto -fvisibility=hidden -fsanitize-blacklist=%t.blacklist -I ./ | FileCheck -check-prefix=CHECK-SEVEN %s
+// RUN: %clang -MD -MF - %s -fsyntax-only -resource-dir=%S/../Driver/Inputs/resource_dir_with_cfi_blacklist -fsanitize=cfi-vcall -flto -fvisibility=hidden -fsanitize-blacklist=%t.blacklist -I ./ | FileCheck -check-prefix=CHECK-SEVEN %s
 // CHECK-SEVEN: .blacklist
 // CHECK-SEVEN: {{ }}x.h
 #ifndef INCLUDE_FLAG_TEST