Joel Rosdahl [Wed, 30 Dec 2020 20:22:26 +0000 (21:22 +0100)]
Only accept -f(no-)color-diagnostics for Clang
If a non-Clang compiler gets -f(no-)color-diagnostics then bail out and
just execute the compiler. The reason is that we don't include
-f(no-)color-diagnostics in the hash so there can be a false cache hit
in the following scenario:
Joel Rosdahl [Tue, 29 Dec 2020 18:33:54 +0000 (19:33 +0100)]
Remove obsolete (and now incorrect) fallback replacement of realpath(3)
The fallback replacement of realpath(3) (from 8e918ccc) uses readlink(3)
under the assumption that we’re only interested about symlinks, but
that’s no longer the case: we’re using it for normalization purposes as
well. Let’s just remove it. If it turns out that there still are
non-Windows systems that don’t have realpath(3) and that we care about
we’ll figure out something else.
Bash tests were not actually being run on the macOS CI agents because
the version of sed installed there does not understand the `-r` flag:
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
- use `sed -E` instead of `sed -r` as the latter isn't supported by BSD sed.
- export `SDKROOT` in `test/run`. Otherwise it appears at least some
some Apple toolchains (e.g. Xcode 10.3) will pick the _latest_ SDK
installed on the host (e.g.
`/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk`)
instead of using the SDK bundled with the toolchain (e.g.
`/Applications/Xcode_10.3.app/.../MacOSX10.14.sdk`).
The 10.15 SDK is not compatible with Xcode 10.3:
ld: unsupported tapi file type '!tapi-tbd' in YAML file
'/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libSystem.tbd'
for architecture x86_64
clang: error: linker command failed with exit code 1
Improve TemporaryFile implementation for Windows (#736)
On Windows, multiple ccache process could race each other to create,
rename and delete temporary files, because they would attempt to
generate the same sequence of temporary file names
(`tmp.cpp_stdout.iG2Kb7`, `tmp.cpp_stdout.P1kAlM`,
`tmp.cpp_stdout.FzP5tM`, ...).
This is because ccache used mingw-w64's [implementation of mkstemp][1],
which uses `rand()` to generate temporary file names, and ccache was
never seeding the thread-local PRNG used by `rand()`.
Replace ccache's use of `mkstemp()` on Windows with an implementation
based on OpenBSD. This allows us to sidestep mingw-w64's problematic
implementation, and allows us to build using MSVC again. (MSVC's C
standard library does not provide `mkstemp()`.)
Example errors:
- Some ccache process is in the process of deleting a temporary file:
ccache: error: Failed to create temporary file for C:\Users\someuser/.ccache/tmp/tmp.cpp_stdout.FzP5tM: Access is denied.
- Some ccache process has destination file open, so it can't be overwritten:
ccache: error: failed to rename C:\Users\someuser/.ccache/tmp/tmp.cpp_stdout.iG2Kb7 to C:\Users\someuser/.ccache/tmp/tmp.cpp_stdout.iG2Kb7.ii: Access is denied.
- Source file has been deleted by some other ccache process:
ccache: error: failed to rename C:\Users\someuser/.ccache/tmp/tmp.cpp_stdout.P1kAlM to C:\Users\someuser/.ccache/tmp/tmp.cpp_stdout.P1kAlM.ii: The system cannot find the file specified.
Joel Rosdahl [Mon, 21 Dec 2020 18:02:19 +0000 (19:02 +0100)]
Add preprocessed file extension to cpp stdout early
Unless when compiling a preprocessed file directly, ccache creates a
temporary file to store the output of the preprocessor, registers the
file for removal at program exit, renames the file to one with a .i/.ii
extension and then registers that file for removal as well. This works
by chance in practice as long as mkstemp() returns something with low
probability of being reused, but as discussed in #736 it risks failing
when mkstemp() doesn’t behave that way.
Fix this by creating the new name (with the needed extension) using a
hard link so that the original file will outlive the new file, thus
blocking another ccache process from creating a file with the same name
again. To make the new temporary file outlive the old file, also delete
pending temporary files in LIFO order.
Joel Rosdahl [Tue, 8 Dec 2020 20:19:19 +0000 (21:19 +0100)]
Improve incorrect documentation on what cache_dir does
The manual says that cache_dir only takes effect if set by $CCACHE_DIR
or by cache_dir in the secondary (system-wide) configuration file, which
is incorrect. It’s kind of correct for how the primary configuration
file is found, though.
Erik Flodin [Mon, 7 Dec 2020 18:20:31 +0000 (19:20 +0100)]
Improve SIMD detection (#735)
* Try to compile code to detect SSE/AVX support. Just checking if the compiler
supports the flag isn't enough as e.g. Clang on Apple's new ARM silicon seems
to accept the flag but then fails when building.
* Try to detect and enable BLAKE3's Neon support.
* Improve detection of AVX2 target attribute support and remove the explicit
compiler version check that hopefully shouldn't be needed.
Joel Rosdahl [Mon, 7 Dec 2020 06:19:52 +0000 (07:19 +0100)]
Improve mutex handling code structure in InodeCache
InodeCache’s acquire_bucket and release_bucket functions need to be used
together. There is no problem with this currently, but it’s possible
that one may forget to call release_bucket in some code path in the
future.
Improve this by introducing a single InodeCache::with_bucket function
that makes it impossible to misuse the API. This should also make
thread-safety analysis algorithms, e.g. Clang’s
-Wthread-safety-analysis, happy.
Joel Rosdahl [Sat, 5 Dec 2020 18:17:32 +0000 (19:17 +0100)]
Reintroduce dev mode and disable problematic build flags in user mode
In version 3.x, ccache was in “user mode” when building from release
archive sources and “dev mode” otherwise. In “dev mode”, additional
compiler flags like “-Wextra -Wpedantic -Werror” were added, but they
were not present in “user mode” in order not to break end users’ builds.
This behavior was partially lost in the conversion to CMake.
This commit tries to imitate the previous behavior by introducing a
CCACHE_DEV_MODE CMake variable and only enable potentially problematic
compiler flags when it’s set to ON.
Joel Rosdahl [Thu, 19 Nov 2020 20:31:41 +0000 (21:31 +0100)]
Fix bug in depfile when output filename includes special characters
The rewriting of the dependency file content introduced in 2ab31632 just
replaces the object file part of the dependency file with the raw
filename. This is incorrect if the filename includes special characters
such as space or dollar.
Fix this by escaping the filename properly. Note that newlines are not
treated specially since Make cannot handle them anyway.
See also the similar bug fix for the depend mode (but for parsing
instead of escaping in that case) in 1d2b5bf4.
Joel Rosdahl [Mon, 9 Nov 2020 18:35:02 +0000 (19:35 +0100)]
Fix conditional compilation of robust mutex code in inode cache
213d9883 added code for using a “robust mutex” to be able to recover a
mutex left in an inconsistent state. The code is enabled if the
PTHREAD_MUTEX_ROBUST macro is defined. On all Linux systems I have
tested, PTHREAD_MUTEX_ROBUST is not a macro but an enum value, so the
code is dead.
Fix this by adding a configure-time check whether it’s possible to use
pthread_mutexattr_setrobust(..., PTHREAD_MUTEX_ROBUST).
Joel Rosdahl [Sat, 7 Nov 2020 19:25:10 +0000 (20:25 +0100)]
Add possibility of overriding compiler type guess
This commit adds a new compiler_type (CCACHE_COMPILERTYPE) configuration
option which makes it possible to force a compiler type, for instance
from a compiler wrapper script not named like a known compiler.
Joel Rosdahl [Wed, 4 Nov 2020 20:21:41 +0000 (21:21 +0100)]
Add docbook-{xml,xsl} packages to Ubuntu environments
Without docbook-xml and docbook-xsl, xsltproc (run by a2x to create the
ccache.1 man page) fetches stuff from the Internet, making man page
generation very slow.
Joel Rosdahl [Mon, 2 Nov 2020 21:09:56 +0000 (22:09 +0100)]
Retain given color diagnostics options when forcing colored output
ccache currently filters out both -fdiagnostics-color and
-fcolor-diagnostics options when adding -fdiagnostics-color (GCC) or
-fcolor-diagnostics (Clang) to force colored output. The idea in #224
was that only -fdiagnostics-color options should be filtered out when
the compiler is GCC, but -fcolor-diagnostics is also removed, something
which was missed in the code review. This has the unintended side effect
that “ccache gcc -fcolor-diagnostics -c example.c” works since ccache in
effect removes -fcolor-diagnostics in the actual call to the compiler.
The bug can fixed by removing only the compiler-specific options when
forcing colored output, but a more robust method would be to retain all
color diagnostics options as is but exclude them from the input hash.
This commit makes that change and also simplifies the logic for color
diagnostics option handling.
Erik Flodin [Fri, 30 Oct 2020 09:41:58 +0000 (10:41 +0100)]
Disable some AVX features on old Apple clang versions (#704)
Disable avx2 and avx512 support on some apple clang versions as the compile
fails even though the compiler seems to accept the -m flags that are used to
enable the feature.
Joel Rosdahl [Wed, 28 Oct 2020 20:26:42 +0000 (21:26 +0100)]
Restore original umask after finalize_at_exit
If umask (CCACHE_UMASK) has been configured, ccache restores the
original umask before executing external programs so that the configured
umask is only used for files created by ccache itself. After a
refactoring of how flushing of statistics is done
(dd8f65aa5589709ca55bbb782050424a0010e8b8), the original umask is
restored before calling finalize_at_exit. If ccache hasn’t created a
result file (i.e., the result is not a cache miss, for example when
called for linking), finalize_stats_and_trigger_cleanup (called by
finalize_at_exit) chooses a random stats file and implicitly also
creates any missing cache directories. Such cache directories will
therefore be created without applying the configured umask.
Fix this by restoring the original mask after calling finalize_at_exit.
Joel Rosdahl [Tue, 20 Oct 2020 18:49:50 +0000 (20:49 +0200)]
Detect errors in log strings at compile time
fmtlib can detect format string errors at compile time if (1) applying
FMT_STRING to the format string literal and (2) compiling for C++14 or
higher.
Requirement 1 is implemented by introducing a LOG macro which applies
FMT_STRING to the first argument and calls Logging::log (if logging is
enabled). Also added are a companion LOG_RAW macro (since C++11 requires
at least one argument for the “...” part in variadic macros) and a
BULK_LOG macro which calls Logging::bulk_log (if logging is enabled).
Requirement 2 is implemented by setting CMAKE_CXX_STANDARD to 14 for one
CI build with a known C++14-capable compiler. We can’t set it to 14 by
default since we still want the code to be buildable with C++11
compilers.
This will catch errors such as the one fixed by PR #691.
Olle Liljenzin [Mon, 12 Oct 2020 18:53:02 +0000 (20:53 +0200)]
Fix expect_perm to work with SELinux (#681)
Test case CCACHE_UMASK fails when running it in an SELinux context because
/bin/ls adds a trailing dot to the output. Thus truncate the output to expected
length.