From: Joel Rosdahl Date: Sun, 7 Feb 2021 12:32:26 +0000 (+0100) Subject: Only dup2 stderr into $UNCACHED_ERR_FD for preprocessor/compiler X-Git-Tag: v4.2.1~35 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c4284c78e9ff286ee5208f449af4c2aaba062d37;p=thirdparty%2Fccache.git Only dup2 stderr into $UNCACHED_ERR_FD for preprocessor/compiler Ccache dup2s the stderr FD and publishes the resulting FD number in $UNCACHED_ERR_FD for usage by e.g. distcc. This is done any executed child process. As noted by Sam Varshavchik on the ccache mailing list, this leads to an unfortunate and complex problem in combination with GNU Make, LTO linking and the Linux PTY driver: https://www.mail-archive.com/ccache@lists.samba.org/msg01516.html Since UNCACHED_ERR_FD is only relevant when running the preprocessor or compiler, let’s only dup2 stderr when executing those, i.e. not when falling back to just running the wrapped command such as the linker. --- diff --git a/src/ccache.cpp b/src/ccache.cpp index 10724c95d..1183ef9d8 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -2369,10 +2369,6 @@ do_cache_compilation(Context& ctx, const char* const* argv) throw Failure(Statistic::cache_miss); } - MTR_BEGIN("main", "set_up_uncached_err"); - set_up_uncached_err(); - MTR_END("main", "set_up_uncached_err"); - LOG("Command line: {}", Util::format_argv_for_logging(argv)); LOG("Hostname: {}", Util::get_hostname()); LOG("Working directory: {}", ctx.actual_cwd); @@ -2390,6 +2386,8 @@ do_cache_compilation(Context& ctx, const char* const* argv) throw Failure(*processed.error); } + set_up_uncached_err(); + if (ctx.config.depend_mode() && (!ctx.args_info.generating_dependencies || ctx.args_info.output_dep == "/dev/null" diff --git a/test/suites/base.bash b/test/suites/base.bash index e16741ce1..2ed268642 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -1357,7 +1357,7 @@ fi # ------------------------------------------------------------------------- if ! $HOST_OS_WINDOWS; then - TEST "UNCACHED_ERR_FD" + TEST "UNCACHED_ERR_FD set when executing preprocessor and compiler" cat >compiler.sh <<'EOF' #!/bin/sh @@ -1389,6 +1389,14 @@ EOF fi fi +if ! $HOST_OS_WINDOWS; then + TEST "UNCACHED_ERR_FD not set when falling back to the original command" + # ------------------------------------------------------------------------- + + $CCACHE bash -c 'echo $UNCACHED_ERR_FD' >uncached_err_fd.txt + expect_content uncached_err_fd.txt "" +fi + # ------------------------------------------------------------------------- TEST "Invalid boolean environment configuration options"