From: Joel Galenson Date: Sun, 2 Dec 2018 19:27:21 +0000 (-0800) Subject: Support multiple -fsanitize-blacklist arguments (#330) X-Git-Tag: v3.6~49 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2d89df03f3d855b7f723efcc12340fdf67fd778;p=thirdparty%2Fccache.git Support multiple -fsanitize-blacklist arguments (#330) 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. --- diff --git a/src/ccache.c b/src/ccache.c index b30dcbbb8..bed4e3c65 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -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; diff --git a/test/suites/sanitize_blacklist.bash b/test/suites/sanitize_blacklist.bash index a2411e9bc..fbe70f88d 100644 --- a/test/suites/sanitize_blacklist.bash +++ b/test/suites/sanitize_blacklist.bash @@ -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 }