Olle Liljenzin [Sun, 31 May 2020 10:02:12 +0000 (12:02 +0200)]
Add inode cache for file hashes (#577)
The inode cache is a process shared cache that maps from device, inode,
size, mtime and ctime to saved hash results. The cache is stored
persistently in a single file that is mapped into shared memory by
running processes, allowing computed hash values to be reused both
within and between builds.
The chosen technical solution works for Linux and might work on other POSIX
platforms, but is not meant to be supported on non-POSIX platforms
such as Windows.
Use 'ccache -o inode_cache=true/false' to activate/deactivate the cache.
Joel Rosdahl [Fri, 29 May 2020 18:43:19 +0000 (20:43 +0200)]
Only try to hard link object files to/from the cache
The compiler unlinks the destination object file before writing, but it
apparently doesn’t do that for dependency files. This means that
compilation can corrupt a .d file that shares i-node with a cached .d
file when using the hard link mode. Here is a scenario where this can
happen:
1. There is a test.c which includes test.h.
2. When test.c is compiled, the compiler writes test.d which mentions
test.h and ccache hard links test.d into cache entry 1. test.d and
cache entry 1's .d file now share i-nodes.
3. The include of test.h is removed from test.c.
4. When test.c is compiled again the compiler overwrites test.d with new
content without test.h and ccache hard links test.d into cache entry
2. test.d, cache entry 1 and cache entry 2 now share i-nodes, all of
which contain the new content without test.h.
Since we can’t be sure how the compiler behaves for other types of files
(.dwo, .cov, etc.), only try to to hard link object files.
Joel Rosdahl [Wed, 20 May 2020 19:26:35 +0000 (21:26 +0200)]
Handle all Intel “-xCODE” compiler options correctly
“CODE” in the Intel compiler’s “-xCODE” option for specifying processor
features seems to always start with an uppercase letter, and since GCC’s
language specifications always are lowercase we can just treat uppercase
codes as an ordinary compiler argument.
Joel Rosdahl [Tue, 19 May 2020 18:37:19 +0000 (20:37 +0200)]
Improve temp file handling
- Use Util::create_temp_fd instead of legacy create_tmp_fd.
- Use Context::register_pending_tmp_file instead of unlinking
explicitly.
- Simplified output of merged stderr from preprocessor and compiler.
Joel Rosdahl [Mon, 18 May 2020 06:26:14 +0000 (08:26 +0200)]
Refactor signal handling and process exit code
* Added a SignalHandler class which encapsulates parts related to signal
handling.
* Moved data referenced by the exit functions to Context (compiler PID,
pending temporary files and pending debug log files).
* Let the Context destructor do what the exitfn functionality used to
do.
* Removed the now superfluous exitfn functionality.
Joel Rosdahl [Wed, 13 May 2020 16:43:47 +0000 (18:43 +0200)]
Merge catch2_tests into unittest’s main
The Catch2 runner was previously compiled separately since it’s slow to
compile, but after the removal of the old test framework there should be
little reason to modify unittest/main.cpp often.
Olle Liljenzin [Sun, 3 May 2020 12:11:29 +0000 (14:11 +0200)]
Don't depend on how echo interprets backslash escapes (#588)
The escape sequence '\n' should be translated to a new line character
when printed to version.cpp. Default mode might be implementation
dependent. At least in Fedora /usr/bin/echo defaults to -E. On the
other hand older versions might not support the -e option that enables
backslash escapes where it is not default.
Split the command into two, one for each output line, which should
produce same output on all platforms.
Joel Rosdahl [Thu, 30 Apr 2020 06:29:31 +0000 (08:29 +0200)]
Improve handling of profiling options
Handling of -fprofile-{generate,use}[=path] was implemented in PR #2
(2011). ccache has since then gained support for Clang, which is not
GCC-compatible for -fprofile-{generate,use}[=path]. Furthermore, GCC 9
changed the semantics of -fprofile-{generate,use}=path, making it
incompatible with ccache’s original implementation.
One crucial problem with the implementation is that there is no error
handling when the expected profiling data file cannot be found. This
means that there will be false positives cache hits for Clang and GCC
9+.
Fix this by:
* Checking for different profiling data file locations to handle
different compilers and versions.
* Bailing out if no profiling data file can be found.
Also:
* Implemented support for Clang’s -fprofile-instr-{generate,use}[=path]
options.
* Implemented support for -fauto-profile[=path].
* Removed the conversion of absolute path to the profile directory. 91a2954e says that the directory is rewritten to increase the hit
rate, but I don’t understand how that could be the case.
* Added tests for the profiling options. Exception:
-fauto-profile[=path], since that would require running the perf tool.