The reason for reverting is that the change introduced a nasty bug: the
dependency file will get an incorrect object file location if 1) build
directory != source directory and 2) -MF is not specified explictly by
the user.
Details: The dependency file is created by the preprocessor pass which
does not have access to the final output file name, so the preprocessor
uses the default object location derived from the source file location
instead.
Note that this partly reverts a compatibility improvement for EDG-based
compilers (see issue #460).
It should be possible to pass the dependency arguments to the compiler
instead of the preprocessor to make -MD/-MMD without -MQ work, but
that’s too risky to be done as a bug fix.
Joel Rosdahl [Sun, 29 Dec 2019 18:21:39 +0000 (19:21 +0100)]
Remove the unify mode
The unify mode has not received enough attention and has at least these
bugs:
1. The direct mode doesn’t work if the unify mode is enabled. This is
because the unify mode doesn’t call into process_preprocessed_file
which stores the paths and hashes of included files needed by the
direct mode.
2. The .incbin directive detection has no effect when using the unify
mode. This is again because the unify mode doesn’t use
process_preprocessed_file which is where the .incbin detection takes
place.
3. The unifier’s tokenizer doesn’t understand C++11 raw string literals.
4. The unifier ignores comments, but comments may have semantic meaning
to modern compilers, e.g. “fall through” comments.
Bugs 3 and 4 are fixable by improving the unifier’s tokenization
algorithm, but since it’s a bit tricky it likely won’t be worth the
effort, especially not as a bug fix.
Bugs 1 and 2 are also fixable by unifying the two code paths, but that’s
a non-trivial effort.
In addition to the bugs, I believe that the usefullness of the unify
mode is low:
* It’s only applicable when not using -g.
* It won't be enabled for C++ unless somebody fixes bug 3.
* It can make line numbers in warning messages and __LINE__ expansions
incorrect.
* Since comments should not be ignored, the unify mode can only make a
difference for some types of whitespace changes, like adding or
removing blank lines or changing a+b to a + b. (a + b is already
normalized to a + b by the preprocessor.)
Therefore I’ll just remove the unify mode to fix the bugs.
Joel Rosdahl [Sat, 16 Nov 2019 21:59:33 +0000 (22:59 +0100)]
Always include input file path in direct mode hash
The “file_macro sloppiness” mode is a way of opting out of inclusion of
the input file path in the direct mode hash. This can produce a false
cache hit in the following scenario:
- a/r.h exists.
- a/x.c has #include "r.h".
- b/x.c is identical to a/x.c.
- Compiling a/x.c records a/r.h in the manifest.
- Compiling b/x.c results in a false cache hit since a/x.c and b/x.c
share manifests and a/r.h exists.
Therefore, ditch the file_macro sloppiness mode so that the input file
path is always included in the direct mode hash.
This bug has existed ever since the file_macro sloppiness was introduced
in eb5d9bd3beb5 (ccache 3.0). It has remained undetected since
compilations tend to use .d files and ccache before 3.7.5 added an
implicit “-MQ <output_file_path>” argument, thus in practice including
the output file path in the hash and therefore making manifests unique
when the object file path mirrors the source file path. However, ccache
3.7.5 no longer adds the implicit -MQ option, thus exposing the bug.
Russell King [Thu, 31 Oct 2019 16:30:22 +0000 (16:30 +0000)]
stats: Fix statistics update with full filesystem
The statistics file update does not check for write errors correctly
as stdio files are normally buffered. This means that data can be
written to the stdio buffer but not written out until fclose().
Hence, it is imperative that the fclose() return value is also
checked.
If either fprintf() or fclose() fail, clean up the temporary file,
rather than littering the filesystem with needless temporary files.
Igor Pylypiv [Mon, 10 Jun 2019 20:52:35 +0000 (13:52 -0700)]
Fix possible NULL pointer dereference (#433)
cppcheck:
[src/manifest.c:270] -> [src/manifest.c:269]: (warning)
Either the condition '!errmsg' is redundant or there is possible null pointer
dereference: errmsg.
Joel Rosdahl [Mon, 21 Oct 2019 18:06:22 +0000 (20:06 +0200)]
Don’t fail fatally if temporary cpp_stderr file is missing
If the temporary cpp_stderr file is missing when the compilation command
has finished then either some user removed it or ccache removed it in
clean_up_internal_tempdir (since the compilation took more than hour or
the system clock was adjusted?). In either case, let’s just fall back to
running the real compiler instead of failing fatally.
Joel Rosdahl [Tue, 17 Sep 2019 20:37:57 +0000 (22:37 +0200)]
Include compiler-only arguments in the hash
After 5d8585b5 (#312), arguments that are not considered affecting the
preprocessor output won’t be passed to the preprocessor. -Werror and
-Wno-error are also not passed to the preprocessor so that options not
properly marked as “compiler only” will only trigger warnings, not
errors. This was a workaround for Clang complaining about unused
arguments in the preprocessor step performed by ccache.
However, it also introduced a regression: -Werror and the other options
were excluded from the hash as well. This means that
cc -c file_with_warnings.c
would be cached by ccache, including the warning message. A later
cc -Werror -c file_with_warnings.c
call would then be a cache hit, resulting in a compilation warning
instead of an error.
This commit fixes the problem by also including the compiler-only
arguments in the hash.
Joel Rosdahl [Sun, 15 Sep 2019 19:32:50 +0000 (21:32 +0200)]
Only enable more warnings in dev mode when requested
21ded3ae enabled “more warnings” in dev mode unconditionally, but that
doesn’t play well in dev builds with a Clang version older than the one
used in Travis-CI since the “-Wno-foo” options may be unknown. Instead
of doing feature tests for those options, just enable “more warnings”
when --enable-more-warnings is specified and specify it for Travis-CI
builds.
Joel Rosdahl [Thu, 12 Sep 2019 18:50:46 +0000 (20:50 +0200)]
Support GCC 9’s -gz=[type] option
-gz[=type] neither disables nor enables generation of debug info, so
don’t enable the fallback behavior of hashing the current directory when
seeing -gz[=type] alone.
Joel Rosdahl [Fri, 19 Jul 2019 07:22:04 +0000 (09:22 +0200)]
Don’t pass -Werror and compilation-only options to the preprocessor
Clang emits warnings when it sees unused options, so when ccache runs
the Clang preprocessor separately, options that are not used by the
preprocessor will produce warnings. This means that the user may get
warnings which would not be present when not using ccache. And if
-Werror is present then the preprocessing step fails, which needless to
say is not optimal.
To work around this:
* Options known to have the above mentioned problem are not passed to
the preprocessor.
* In addition, -Werror is also not passed to the preprocessor so that
options not properly marked as “compiler only” will only trigger
warnings, not errors.
Luboš Luňák [Mon, 20 May 2019 19:18:16 +0000 (21:18 +0200)]
Fix PCH detection in depend mode (+test improvements) (#427)
* do not refer to Clang's PTH in tests
The PTH feature has been removed (https://reviews.llvm.org/D54547)
and according to the commit it has never really been used. Maybe this
made sense somewhen in the past, but now those .pth files must be PCHs
internally. This commit actually just changes the .pth extensions
to .pch to avoid confusion, technically nothing should change
except for filenames.
* try to share PCH tests between GCC and Clang
Clang is supposed to be a drop-in for GCC, so in general it should
be able to handle everything GCC can. That's not completely true
in practice, there are differences, but it doesn't make sense
to completely duplicate a testcase just because there are some
differences. So start creating a shared common base for the PCH
tests and do separately only tests that act differently.
* more sharing of PCH tests between GCC and Clang
There's e.g. no need to do all kinds of complex tests with both
.gch and .pch with Clang, except for checking that Clang finds
one of them if none is specified explicitly.
* log also when pch usage is detect from pragma pch_preprocess
* try harder to verify in tests that ccache detects PCH changes
Some of the tests did that, e.g. those 'file changed', but e.g. the cached
.gch creation did not. So try to intentionally change the .gch/.h and test
that it leads to a cache miss. Otherwise there might be a hit simply
because ccache failed to detect PCH usage and ignores the .gch completely.
* clean up #include vs -fpch-preprocess in pch tests
As the manpage says, -fpch-preprocess is needed only with the #include
form, otherwise it's pointless.
* do not mention sloppiness in pch tests, only no sloppiness
Since sloppiness is normally required, so no point in stating the obvious.
* test also -include-pch with clang
* hash also pch introduced only using -include
GCC does not output the pch in the .d dependencies file, so without
this there would be false cache hits.
* be consistent about sloppiness in pch tests
create pch -> pch_defines
use pch -> time_macros
* test CCACHE_PCH_EXTSUM more thoroughly and also with -include
* pch test for .gch file being in an extra directory
* doc corrections for how to use PCH with ccache
- ccache will fail to properly detect that -include a.h means using
a.h.gch if it requires using path from -I (they are not searched)
- -fpch-preprocess does nothing with Clang, it doesn't output
pragma GCC pch_preprocess and so #include form for PCHs doesn't work
* explain better problems of -MD/-MMD in depend mode
Joel Rosdahl [Wed, 1 May 2019 12:51:45 +0000 (14:51 +0200)]
Improve fix in #400 to handle more cases
The dependency file name can come from e.g. DEPENDENCIES_OUTPUT as well,
so hash information about a /dev/null .d file after the argument
processing loop instead.
Joel Rosdahl [Wed, 1 May 2019 11:58:18 +0000 (13:58 +0200)]
Bail out on “-MF /dev/null”
This is an alternative fix for #397, based on the observation/assumption
that using “-MF /dev/null” is only ever used as part of a compiler probe
call in combination with “-c /dev/null -o /dev/null”, so there is little
reason to cache the result. The advantage of just bailing out is to
reduce the number of special cases we have to handle.
this is useful for determining the length of the generated argument string
* correctly handle @file syntax on Windows
the @file syntax means that the process reads command arguments from the
specified file. this is commonly used in order to shorten commands which
would otherwise be longer than the maximum length limit: many build systems
do this in all cases to avoid hitting this limit.
when a command exceeds 8192 characters on on Windows, ccache now writes
the parsed/modified arguments to a tmpfile and then runs the command using
that tmpfile with @tmpfile in order to preserve this mechanism and avoid hitting
the length limit
Joel Rosdahl [Mon, 22 Apr 2019 13:22:07 +0000 (15:22 +0200)]
Fix minitrace.c compilation error with GCC 7.3
The error/warning looks like this:
src/minitrace.c: In function ‘mtr_flush’:
src/minitrace.c:256:54: error: ‘%.*s’ directive output may be truncated writing up to 700 bytes into a region of size 252 [-Werror=format-truncation=]
snprintf(arg_buf, ARRAY_SIZE(arg_buf), "\"%s\":\"%.*s\"", raw->arg_name, 700, raw->a_str);
^~~~
In file included from /usr/include/stdio.h:862:0,
from src/minitrace.c:9:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64:10: note: ‘__builtin___snprintf_chk’ output 6 or more bytes (assuming 706) into a destination of size 256
return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
__bos (__s), __fmt, __va_arg_pack ());
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~