]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Support multiple -fsanitize-blacklist arguments (#330)
authorJoel Galenson <jgalenson@gmail.com>
Sun, 2 Dec 2018 19:27:21 +0000 (11:27 -0800)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 2 Dec 2018 19:27:21 +0000 (20:27 +0100)
This modifies the code to support multiple -fsanitize-blacklist
arguments, which prevents ccache from incorrectly using a cached
result when one of the blacklist files has changed.

This fixes #318.

src/ccache.c
test/suites/sanitize_blacklist.bash

index b30dcbbb8fb646cf9e0aefc3119e506453914e61..bed4e3c65f42da59cefff8e2320cfcf40b59a4b8 100644 (file)
@@ -237,7 +237,10 @@ static bool profile_use = false;
 static bool profile_generate = false;
 
 // Sanitize blacklist
-static char *sanitize_blacklist = NULL;
+static char **sanitize_blacklists = NULL;
+
+// Size of sanitize_blacklists
+static size_t sanitize_blacklists_len = 0;
 
 // Whether we are using a precompiled header (either via -include, #include or
 // clang's -include-pch or -include-pth).
@@ -1710,7 +1713,8 @@ calculate_common_hash(struct args *args, struct hash *hash)
        }
 
        // Possibly hash the sanitize blacklist file path.
-       if (sanitize_blacklist) {
+       for (size_t i = 0; i < sanitize_blacklists_len; i++) {
+               char *sanitize_blacklist = sanitize_blacklists[i];
                cc_log("Hashing sanitize blacklist %s", sanitize_blacklist);
                hash_delimiter(hash, "sanitizeblacklist");
                if (!hash_file(hash, sanitize_blacklist)) {
@@ -2576,7 +2580,9 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
                        continue;
                }
                if (str_startswith(argv[i], "-fsanitize-blacklist=")) {
-                       sanitize_blacklist = x_strdup(argv[i] + 21);
+                       sanitize_blacklists = x_realloc(sanitize_blacklists,
+                                (sanitize_blacklists_len + 1) * sizeof(char *));
+                       sanitize_blacklists[sanitize_blacklists_len++] = x_strdup(argv[i] + 21);
                        args_add(stripped_args, argv[i]);
                        continue;
                }
@@ -3298,7 +3304,12 @@ 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;
+       for (size_t i = 0; i < sanitize_blacklists_len; i++) {
+               free(sanitize_blacklists[i]);
+               sanitize_blacklists[i] = NULL;
+       }
+       free(sanitize_blacklists); sanitize_blacklists = NULL;
+       sanitize_blacklists_len = 0;
        free(included_pch_file); included_pch_file = NULL;
        args_free(orig_args); orig_args = NULL;
        free(input_file); input_file = NULL;
index a2411e9bcbd67b332b000f675b2d21247855d4fa..fbe70f88db51447cd75c99b47d67e9316b99aed6 100644 (file)
@@ -7,8 +7,9 @@ SUITE_sanitize_blacklist_PROBE() {
 }
 
 SUITE_sanitize_blacklist_SETUP() {
-    generate_code 1 test1.c
+    generate_code 2 test1.c
     echo "fun:foo" >blacklist.txt
+    echo "fun_1:foo" >blacklist2.txt
 
     unset CCACHE_NODIRECT
 }
@@ -55,4 +56,31 @@ SUITE_sanitize_blacklist() {
     fi
 
     expect_stat 'error hashing extra file' 1
+
+    # -------------------------------------------------------------------------
+    TEST "Multiple -fsanitize-blacklist"
+
+    $REAL_COMPILER -c -fsanitize-blacklist=blacklist2.txt -fsanitize-blacklist=blacklist.txt test1.c
+
+    $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist2.txt -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=blacklist2.txt -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_2:foo" >blacklist2.txt
+
+    $CCACHE_COMPILE -c -fsanitize-blacklist=blacklist2.txt -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=blacklist2.txt -fsanitize-blacklist=blacklist.txt test1.c
+    expect_stat 'cache hit (direct)' 2
+    expect_stat 'cache miss' 2
+    expect_stat 'files in cache' 4
 }