From: Joel Rosdahl Date: Tue, 17 Oct 2023 19:36:35 +0000 (+0200) Subject: fix: Make handling of Clang config options more robust X-Git-Tag: v4.9~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=270433590edcb89b58255b4d8f28ce4b3c2ea7b1;p=thirdparty%2Fccache.git fix: Make handling of Clang config options more robust Closes #1335. --- diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index b46ddf64b..22788cb9d 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -391,7 +391,9 @@ process_option_arg(const Context& ctx, // These are always too hard. if (compopt_too_hard(arg) || util::starts_with(arg, "-fdump-") - || util::starts_with(arg, "-MJ") || util::starts_with(arg, "-Yc")) { + || util::starts_with(arg, "-MJ") || util::starts_with(arg, "-Yc") + || util::starts_with(arg, "--config-system-dir=") + || util::starts_with(arg, "--config-user-dir=")) { LOG("Compiler option {} is unsupported", args[i]); return Statistic::unsupported_compiler_option; } diff --git a/src/ccache.cpp b/src/ccache.cpp index e34c94b8c..71eefb409 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1743,6 +1743,14 @@ hash_argument(const Context& ctx, } else { path = args[i].substr(eq_pos + 1); } + + if (args[i] == "--config" && path.find('/') == std::string::npos) { + // --config FILE without / in FILE: the file is searched for in Clang's + // user/system/executable directories. + LOG("Argument to compiler option {} is too hard", args[i]); + return tl::unexpected(Statistic::unsupported_compiler_option); + } + DirEntry dir_entry(path, DirEntry::LogOnError::yes); if (dir_entry.is_regular_file()) { // If given an explicit specs file, then hash that file, but don't @@ -1750,6 +1758,9 @@ hash_argument(const Context& ctx, hash.hash_delimiter("specs"); TRY(hash_compiler(ctx, hash, dir_entry, path, false)); return {}; + } else { + LOG("While processing {}: {} is missing", args[i], path); + return tl::unexpected(Statistic::bad_compiler_arguments); } } @@ -1801,12 +1812,16 @@ static tl::expected, Failure> get_manifest_key(Context& ctx, Hash& hash) { // Hash environment variables that affect the preprocessor output. - const char* envvars[] = {"CPATH", - "C_INCLUDE_PATH", - "CPLUS_INCLUDE_PATH", - "OBJC_INCLUDE_PATH", - "OBJCPLUS_INCLUDE_PATH", // clang - nullptr}; + const char* envvars[] = { + "CPATH", + "C_INCLUDE_PATH", + "CPLUS_INCLUDE_PATH", + "OBJC_INCLUDE_PATH", + "OBJCPLUS_INCLUDE_PATH", // Clang + "CLANG_CONFIG_FILE_SYSTEM_DIR", // Clang + "CLANG_CONFIG_FILE_USER_DIR", // Clang + nullptr, + }; for (const char** p = envvars; *p; ++p) { const char* v = getenv(*p); if (v) {