Thomas Otto [Sun, 24 Nov 2019 21:27:26 +0000 (22:27 +0100)]
Windows define and include restructuring (#492)
Set the _WIN32_WINNT macro only once in the generated config.h.
Include <windows.h> only once in system.hpp, unless these includes
are in third party libs - however third party includes themselves
should always be behind internal includes. Therefore also make
system.hpp the first include everywhere.
Erik Johansson [Sun, 17 Nov 2019 20:31:49 +0000 (21:31 +0100)]
Add handling of __TIMESTAMP__ macro (#488)
__TIMESTAMP__ is expanded by the pre-processor to asctime() of the source
file's modification time. Handle __TIMESTAMP__ similar to __DATE__ and include
asctime(modification time) in the hash when __TIMESTAMP__ is detected in the
source code.
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.
Luboš Luňák [Thu, 14 Nov 2019 19:17:22 +0000 (20:17 +0100)]
Allow -fmodules in direct depend mode (#482)
Clang creates the internal on-disk representation of modules
in the background on demand as necessary. This means that ccache does
not need to cache that, all that it needs to cache is the actual
compilation result and the dependencies. Which in the case of modules
includes also the module.modulemap files, and Clang outputs such
dependencies correctly only in the depend mode, in the preprocessed
output there is no way to find out the module dependencies.
Therefore support -fmodules in direct depend mode by more or less
ignoring it. Tested with source build of LLVM/Clang configured
with -DLLVM_ENABLE_MODULES=On (and the build actually occassionally
fails because of module problems, but that happens regardless of ccache).
See also pull request #130 (and this reuses the tests from there).
Erik Johansson [Wed, 23 Oct 2019 18:52:49 +0000 (20:52 +0200)]
Add AVX2 variant of check_for_temporal_macros (#476)
By using AVX (Advanced Vector Extensions) the search for __DATE__ and __TIME__
in the input source becomes much faster. On my machine, ccache spends ~4.9e6
cycles in check_for_temporal_macros when compiling src/ccache.cpp. With USE_AVX
set that figure goes down to ~6.7e5.
Compiling all of ccache with -mavx2 makes the unittest crash with "Illegal
instruction: 4" when run on travis (Mac OS X). My guess is that -mavx2 makes
clang generate code that uses instructions that doesn't work on the CPUs used
on the build server (see [0]).
Instead compile only check_for_temporal_macros_avx2 with -mavx2 as we can
control when that function is called (i.e. only do it when the cpu supports
it).
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 [Sat, 19 Oct 2019 10:43:39 +0000 (12:43 +0200)]
Improve functions related to (l)stat-ing
Introduced a Stat class that represents a “struct stat”. The class
replaces the utility functions x_lstat, x_stat, file_size_on_disk and
is_symlink, and it provides an easier to use interface than the macros
associated with stat structs.
Joel Rosdahl [Tue, 8 Oct 2019 19:58:07 +0000 (21:58 +0200)]
Recompress in parallel
Recompression is now done by a thread pool with one thread per logical
CPU. There is also a read-ahead to let the main thread do some directory
I/O while the CPUs are busy.
Joel Rosdahl [Wed, 2 Oct 2019 12:24:19 +0000 (14:24 +0200)]
Refactor result/manifest reading/writing
* Converted compression code into C++ interfaces and implementations.
* Extracted code for reading/writing results/manifests into
reader/writer classes.
* C++-ified result/manifest parsing code.
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 [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.