From: Raihaan Shouhell Date: Sun, 14 Apr 2024 07:44:40 +0000 (+0800) Subject: feat: Add sloppiness for .incbin handling (#1423) X-Git-Tag: v4.10~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed9812c011e7255704f241caf677e87faf2fd5f7;p=thirdparty%2Fccache.git feat: Add sloppiness for .incbin handling (#1423) Code to address some issues in #1421. --- diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index 3372187f..9e74030c 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -1045,6 +1045,11 @@ preprocessing first. different directories, with the tradeoff of potentially getting an incorrect directory in the `.gcno` file. *gcno_cwd* also disables hashing of the current working directory if `-fprofile-abs-path` is used. +*incbin*:: + By default, ccache will ignore all files containing an `.incbin` directive. + While this is the correct behaviour as ccache does not detect incbin changes, + this restriction can make some projects difficult to cache. This sloppiness + will pretend the `.incbin` directive doesn't exist and simply allow caching. *include_file_ctime*:: By default, ccache will disable caching if a source code file has a status change time (ctime) after the start of the ccache invocation. This diff --git a/src/ccache/Config.cpp b/src/ccache/Config.cpp index 5d99f8d9..bb2c4ac2 100644 --- a/src/ccache/Config.cpp +++ b/src/ccache/Config.cpp @@ -293,6 +293,8 @@ parse_sloppiness(const std::string& value) result.insert(core::Sloppy::file_stat_matches_ctime); } else if (token == "gcno_cwd") { result.insert(core::Sloppy::gcno_cwd); + } else if (token == "incbin") { + result.insert(core::Sloppy::incbin); } else if (token == "include_file_ctime") { result.insert(core::Sloppy::include_file_ctime); } else if (token == "include_file_mtime") { @@ -333,6 +335,9 @@ format_sloppiness(core::Sloppiness sloppiness) if (sloppiness.contains(core::Sloppy::gcno_cwd)) { result += "gcno_cwd, "; } + if (sloppiness.contains(core::Sloppy::incbin)) { + result += "incbin, "; + } if (sloppiness.contains(core::Sloppy::include_file_ctime)) { result += "include_file_ctime, "; } diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 6a3a4fbb..60bb154e 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -570,6 +570,16 @@ process_preprocessed_file(Context& ctx, Hash& hash, const std::string& path) && ((q[7] == ' ' && (q[8] == '"' || (q[8] == '\\' && q[9] == '"'))) || q[7] == '"')) { + // Instead of bailing we ignore changes as sloppy incbin handling is + // enabled + if (ctx.config.sloppiness().contains(core::Sloppy::incbin)) { + LOG_RAW( + "Found potential unsupported .inc" + "bin directive in source code " + "but continuing due to enabled sloppy incbin handling"); + q += sizeof(incbin_directive); + continue; + } // 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 diff --git a/src/ccache/core/Sloppiness.hpp b/src/ccache/core/Sloppiness.hpp index 9afc08a5..98f0fe4b 100644 --- a/src/ccache/core/Sloppiness.hpp +++ b/src/ccache/core/Sloppiness.hpp @@ -53,6 +53,8 @@ enum class Sloppy : uint32_t { gcno_cwd = 1U << 11, // Ignore -frandom-seed=*string*. random_seed = 1U << 12, + // Enables sloppy handling of incbin + incbin = 1U << 13, }; using Sloppiness = util::BitSet;