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.
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.