summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders F Björklund <anders.f.bjorklund@gmail.com>2018-04-22 11:49:32 +0200
committerJoel Rosdahl <joel@rosdahl.net>2018-05-07 19:50:44 +0200
commitb94a70af6771bb2f263e34fb9c7a977429d961f8 (patch)
tree80db34e28581ed6f9fd2e49129c0b24fdbe2d7d7
parent5779e97652ec8b87a0629b7127ad5cc398a35ba3 (diff)
downloadccache-b94a70af6771bb2f263e34fb9c7a977429d961f8.tar.gz
Add the sanitize blacklist contents to the hash
-rw-r--r--src/ccache.c19
-rwxr-xr-xtest/run1
-rw-r--r--test/suites/sanitize_blacklist.bash58
3 files changed, 78 insertions, 0 deletions
diff --git a/src/ccache.c b/src/ccache.c
index bef33698..c5497dea 100644
--- a/src/ccache.c
+++ b/src/ccache.c
@@ -225,6 +225,9 @@ static char *profile_dir = NULL;
static bool profile_use = false;
static bool profile_generate = false;
+// Sanitize blacklist
+static char *sanitize_blacklist = NULL;
+
// Whether we are using a precompiled header (either via -include, #include or
// clang's -include-pch or -include-pth).
static bool using_precompiled_header = false;
@@ -1655,6 +1658,16 @@ calculate_common_hash(struct args *args, struct mdfour *hash)
}
}
+ // Possibly hash the sanitize blacklist file path.
+ if (sanitize_blacklist) {
+ cc_log("Hashing sanitize blacklist %s", sanitize_blacklist);
+ hash_delimiter(hash, "sanitizeblacklist");
+ if (!hash_file(hash, sanitize_blacklist)) {
+ stats_update(STATS_BADEXTRAFILE);
+ failed();
+ }
+ }
+
if (!str_eq(conf->extra_files_to_hash, "")) {
char *p = x_strdup(conf->extra_files_to_hash);
char *q = p;
@@ -2502,6 +2515,11 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
args_add(stripped_args, argv[i]);
continue;
}
+ if (str_startswith(argv[i], "-fsanitize-blacklist=")) {
+ sanitize_blacklist = x_strdup(argv[i] + 21);
+ args_add(stripped_args, argv[i]);
+ continue;
+ }
if (str_startswith(argv[i], "--sysroot=")) {
char *relpath = make_relative_path(x_strdup(argv[i] + 10));
char *option = format("--sysroot=%s", relpath);
@@ -3207,6 +3225,7 @@ cc_reset(void)
free(debug_prefix_maps); debug_prefix_maps = NULL;
debug_prefix_maps_len = 0;
free(profile_dir); profile_dir = NULL;
+ free(sanitize_blacklist); sanitize_blacklist = NULL;
free(included_pch_file); included_pch_file = NULL;
args_free(orig_args); orig_args = NULL;
free(input_file); input_file = NULL;
diff --git a/test/run b/test/run
index 82a80541..0bbb21c4 100755
--- a/test/run
+++ b/test/run
@@ -364,6 +364,7 @@ nocpp2
cpp1
multi_arch
serialize_diagnostics
+sanitize_blacklist
debug_prefix_map
masquerading
hardlink
diff --git a/test/suites/sanitize_blacklist.bash b/test/suites/sanitize_blacklist.bash
new file mode 100644
index 00000000..a2411e9b
--- /dev/null
+++ b/test/suites/sanitize_blacklist.bash
@@ -0,0 +1,58 @@
+SUITE_sanitize_blacklist_PROBE() {
+ touch test.c blacklist.txt
+ if ! $REAL_COMPILER -c -fsanitize-blacklist=blacklist.txt \
+ test.c 2>/dev/null; then
+ echo "-fsanitize-blacklist not supported by compiler"
+ fi
+}
+
+SUITE_sanitize_blacklist_SETUP() {
+ generate_code 1 test1.c
+ echo "fun:foo" >blacklist.txt
+
+ unset CCACHE_NODIRECT
+}
+
+SUITE_sanitize_blacklist() {
+ # -------------------------------------------------------------------------
+ TEST "Compile OK"
+
+ $REAL_COMPILER -c -fsanitize-blacklist=blacklist.txt test1.c
+
+ $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c
+ expect_stat 'cache hit (direct)' 0
+ expect_stat 'cache miss' 1
+ expect_stat 'files in cache' 2
+
+ $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c
+ expect_stat 'cache hit (direct)' 1
+ expect_stat 'cache miss' 1
+ expect_stat 'files in cache' 2
+
+ echo "fun:bar" >blacklist.txt
+
+ $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c
+ expect_stat 'cache hit (direct)' 1
+ expect_stat 'cache miss' 2
+ expect_stat 'files in cache' 4
+
+ $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c
+ expect_stat 'cache hit (direct)' 2
+ expect_stat 'cache miss' 2
+ expect_stat 'files in cache' 4
+
+ # -------------------------------------------------------------------------
+ TEST "Compile failed"
+
+ if $REAL_COMPILER -c -fsanitize-blacklist=nosuchfile.txt test1.c 2>expected.stderr; then
+ test_failed "Expected an error compiling test1.c"
+ fi
+
+ rm blacklist.txt
+
+ if $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist.txt test1.c 2>expected.stderr; then
+ test_failed "Expected an error compiling test1.c"
+ fi
+
+ expect_stat 'error hashing extra file' 1
+}