From: Joel Rosdahl Date: Tue, 19 Jul 2022 07:52:00 +0000 (+0200) Subject: fix: Avoid false positive cache hits for __asm__(".incbin" " \"file\"") X-Git-Tag: v4.6.2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e2e11f1f49cddfd57c52ff4af3c805a2a72ddd9;p=thirdparty%2Fccache.git fix: Avoid false positive cache hits for __asm__(".incbin" " \"file\"") Regression in #983. Fixes #1120. (cherry picked from commit 7ee6030bc7b2e6ef321c01854f88ce0fd81c4513) --- diff --git a/src/ccache.cpp b/src/ccache.cpp index 94f7c89fe..d9a42c2b7 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -465,8 +465,7 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path) "# 32 \"\" 2\n"; // Note: Intentionally not using the string form to avoid false positive // match by ccache itself. - static const char incbin_prefix[] = { - '.', 'i', 'n', 'c', 'b', 'i', 'n', ' '}; + static const char incbin_directive[] = {'.', 'i', 'n', 'c', 'b', 'i', 'n'}; // Check if we look at a line containing the file name of an included file. // At least the following formats exist (where N is a positive integer): @@ -570,14 +569,16 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path) Statistic::could_not_use_precompiled_header); } p = q; // Everything of interest between p and q has been hashed now. - } else if (strncmp(q, incbin_prefix, sizeof(incbin_prefix)) == 0 - && (q[8] == '"' || (q[8] == '\\' && q[9] == '"'))) { + } else if (strncmp(q, incbin_directive, sizeof(incbin_directive)) == 0 + && ((q[7] == ' ' + && (q[8] == '"' || (q[8] == '\\' && q[9] == '"'))) + || q[7] == '"')) { // An assembler .inc bin (without the space) statement, which could be // part of inline assembly, refers to an external file. If the file // changes, the hash should change as well, but finding out what file to // hash is too hard for ccache, so just bail out. LOG_RAW( - "Found unsupported .inc" + "Found potential unsupported .inc" "bin directive in source code"); return nonstd::make_unexpected( Failure(Statistic::unsupported_code_directive)); diff --git a/test/suites/base.bash b/test/suites/base.bash index 89cddf3e8..8c4622fd8 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -1493,6 +1493,15 @@ EOF expect_stat cache_miss 0 expect_stat unsupported_code_directive 1 + cat <incbin.c +__asm__(".incbin" " \"empty.bin\""); +EOF + + $CCACHE_COMPILE -c incbin.c + expect_stat preprocessed_cache_hit 0 + expect_stat cache_miss 0 + expect_stat unsupported_code_directive 2 + cat <incbin.s .incbin "empty.bin"; EOF @@ -1500,7 +1509,7 @@ EOF $CCACHE_COMPILE -c incbin.s expect_stat preprocessed_cache_hit 0 expect_stat cache_miss 0 - expect_stat unsupported_code_directive 2 + expect_stat unsupported_code_directive 3 cat <incbin.cpp struct A { @@ -1515,7 +1524,7 @@ EOF if $CCACHE_COMPILE -x c++ -c incbin.cpp 2>/dev/null; then expect_stat preprocessed_cache_hit 0 expect_stat cache_miss 1 - expect_stat unsupported_code_directive 2 + expect_stat unsupported_code_directive 3 fi fi