It looks like https://zstd.net isn't working anymore, however, http://zstd.net
works and simply redirects to https://facebook.github.io/zstd/ which is served
through https.
Aleksander Salwa [Sat, 20 Mar 2021 18:55:54 +0000 (19:55 +0100)]
win32: Fix handling of long command lines (#816)
What is broken: handling of "execute" with long command parameters (see win32execute).
In more details:
* parameter lpCommandLine was formatted incorrectly (it has to contain app name too)
* temporary file with parameters to the compiler was formatted incorrectly (it
should NOT contain app name; if it contains backslashes, then these
backslashes need to be escaped as double-backslashes)
* wrong location (directory) of temporary files in win32execute
* premature deletion of temporary files in win32execute
Implement a better Stat::stat(), Stat::lstat() for Windows (#819)
`stat()` as implemented in msvcrt.dll (used by mingw-w64) has a number
of flaws:
- `st_ino` is always 0
- other file attributes are queried from the parent directory instead of
the file itself, and so can be incorrect/stale, e.g. if a file is
modified via another hard link.
The implementation in the UCRT is slightly better -- it prefers to query
attributes from the file itself if possible, but it still doesn't
populate `st_ino` and can silently fall back to querying from the parent
directory and giving stale results.
I don't believe the msvcrt.dll source is available (you have to infer
its behaviour from e.g. Process Monitor) but the ucrtbase.dll source
code is available in the Windows 10 SDK.
Write an implementation of `stat`/`lstat` that sidesteps these issues by
using Win32 APIs to query file information. A few implementation notes:
- We do not fall back to querying the parent directory (as the UCRT
`stat()` implementation and [Python's `stat()`][1] do) if we can't get
a handle to the actual file. If we don't have `FILE_READ_ATTRIBUTES`
permissions, we fail with `EACCES` instead of returning
incomplete/stale results fetched from the parent directory.
- Windows-specific `Stat::file_attributes()` / `Stat::reparse_tag()`
added to provide the Win32 file attributes and file reparse tag.
- `lstat()` sets the `S_IFLNK` bit in `st_mode` for symlinks. On
Windows, there are other symlink-like things ("name surrogate reparse
points") such as directory junctions and mountpoints. To identify
these, the caller can check the reparse tag to identify a directory
junction/mountpoint.
- We use Python's mapping of Win32 error codes to C errno.
Joel Rosdahl [Sat, 13 Mar 2021 12:26:03 +0000 (13:26 +0100)]
Only reject -f(no-)color-diagnostics for known GCC compiler
61ce8c44 made it so that ccache rejects -f(no-)color-diagnostics early
for non-Clang compilers. This was needed to avoid false cache hits for
the GCC case, but it had the side effect of rejecting
-fcolor-diagnostics for unknown compilers as well, such as for a
compiler named c++ that in reality is clang++ (which actually accepts
-f(no-)color-diagnostics).
Fix this by simply doing the special case for GCC instead of non-Clang.
This is OK since the speculative handling of color diagnostics options
is only done for GCC and Clang, not for other compiler types.
Joel Rosdahl [Thu, 4 Mar 2021 20:34:07 +0000 (21:34 +0100)]
Write debug log file in most argument processing error scenarios
When the debug mode is enabled, ccache writes the log to
<objectfile>.ccache-log, but that can only be done if the object file
location has been determined. If an unsupported compiler option is
detected, ccache exits early and may not yet have determined the output
object filename.
Fix this by parsing all compiler options, then determining the object
file location and only then return an error from the process_args
function with. This will in practice make the debug mode work for most
invocations. There are still edge cases where it won’t work or will be
potentially confusing, for instance these:
Naturally, no debug log file will be written in the first case. In the
second case no debug log file will be written either since ccache
doesn’t consider a nonexistent file to be an input file. In the third
case the debug log file will be written foo.o.ccache-log but not
bar.o.ccache-log.
Fix Util::read_file truncating files if size_hint is an underestimate (#808)
If the size_hint passed to read_file was an underestimate, or the
platform's `stat()` implementation gives an inaccurate file size (e.g.
MinGW) then `Util::read_file()` would only issue a single `read()` call
instead of reading the entire file.
Joel Rosdahl [Tue, 23 Feb 2021 20:11:58 +0000 (21:11 +0100)]
Handle -frecord-gcc-switches correctly
-frecord-gcc-switches records the full command line in the object file,
so include the original command line in the hash as suggested by
Lawrence Chan.
StdAtomic.cmake: Probe atomic increment as well (#800)
On sparc there are 8-byte atomic loads and stores available in ISA
but not atomic increments. As a result linking fails as:
```
ld: src/libccache_lib.a(InodeCache.cpp.o):
undefined reference to symbol '__atomic_fetch_add_8@@LIBATOMIC_1.0'
ld: sparc-unknown-linux-gnu/8.2.0/libatomic.so.1:
error adding symbols: DSO missing from command line
```
The fix is to add increment into libatomic test.
tested on `sparc-unknown-linux-gnu` target.
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Joel Rosdahl [Sun, 7 Feb 2021 12:32:26 +0000 (13:32 +0100)]
Only dup2 stderr into $UNCACHED_ERR_FD for preprocessor/compiler
Ccache dup2s the stderr FD and publishes the resulting FD number in
$UNCACHED_ERR_FD for usage by e.g. distcc. This is done any executed
child process.
As noted by Sam Varshavchik on the ccache mailing list, this leads to an
unfortunate and complex problem in combination with GNU Make, LTO
linking and the Linux PTY driver:
Since UNCACHED_ERR_FD is only relevant when running the preprocessor or
compiler, let’s only dup2 stderr when executing those, i.e. not when
falling back to just running the wrapped command such as the linker.
Joel Rosdahl [Sat, 30 Jan 2021 18:35:54 +0000 (19:35 +0100)]
Improve handling of SOURCE_DATE_EPOCH
PR #755 (be1ed774) made it so that the value of SOURCE_DATE_EPOCH is
ignored if time_macros sloppiness is set. A downside of this is
naturally that the user has to set sloppiness if SOURCE_DATE_EPOCH is
set in the environment.
Insight: SOURCE_DATE_EPOCH actually only ever changes the result if the
source code contains __DATE__. __TIME__ is not an issue since ccache
disables the direct mode if __TIME__is present and the preprocessor mode
will then see the actual expansion regardless of any SOURCE_DATE_EPOCH
value. Finally, the __TIMESTAMP__ case is not applicable at all since
it’s not affected by SOURCE_DATE_EPOCH.
Therefore, make sure to only hash SOURCE_DATE_EPOCH if we find __DATE__.
The user then does not have to set sloppiness to get direct mode hits
for files that don’t contain __DATE__.
Joel Rosdahl [Sat, 30 Jan 2021 18:17:33 +0000 (19:17 +0100)]
Improve speed of compiler launcher command in UseCcache.cmake
I noticed that the overhead of “cmake -E env” is around 9 ms on my
system. This means that ccache direct mode hits on average have become
twice as slow when building ccache itself on my system.
Improve this by using the standard “env” program if available. Its
overhead is around 1 ms.
Make `is_equal_object_files` more lenient when comparing COFF object
files.
COFF object files contain the original source file name, which was
breaking the cpp1 test. They often contain a timestamp used by the
incremental linker, unless this is explicitly disabled via `/Brepro`
(MSVC) or `-mno-incremental-linker-compatible` (clang).
Test suite fixes and improvements for Windows (#780)
* Tests: properly handle compiler arguments from CC environment variable
* Tests: don't pass test names directly to printf
In some cases test names would be interpreted as invalid arguments to
`printf` instead of a string to be printed, and this resulted in
confusing output on test failure.
* Tests: enable symlink support on Windows
git-bash's `ln -s` defaults to making a copy instead of making a symlink
for compatibility, but it is possible to ask for native Windows symlink
support instead.
Creating symlinks on Windows requires suitable permissions, or that
"Developer Mode" is enabled. (This is true for the Github Actions
Windows runners.)
* Tests: performance fixes for Windows
On Windows, git-bash's emulation of fork/exec is exteremely slow -- on
my machine it's typically around 30ms to spawn /usr/bin/true from a bash
script compared to 2ms on my macOS machine.
This is really noticeable when running ccache tests. This patch fixes
some of the hot code (i.e. code invoked for every test case) to avoid
spawning external commands or creating as many subshells.
* Tests: get more tests passing on Windows
- account for \r\n line endings in --version test
- skip tests that can never succeed on Windows
Joel Rosdahl [Sun, 17 Jan 2021 12:07:01 +0000 (13:07 +0100)]
Don’t cache result if a preprocessed header file is too new
Unless sloppiness is set to ignore mtime/ctime, ccache classifies a
newly created header file as “too new” and then skips it in
do_remember_include_file and returns false, which makes
remember_include_file disable the direct mode. This works as intended
for normal header files whose content is included in the preprocessed
output. However, for a preprocessed header file this doesn’t work well
since its content then isn’t included in the hash, which can lead to
false positive cache hits.
Fix this by not caching the result if a preprocessed header file is too
new, i.e. increment the “can’t use preprocessed header” statistics
counter and fall back to just running the compiler.
doc/MANUAL.adoc: Don't use non-ASCII quotes (#761)
Some locales like "LANG=fr_FR.iso885915@euro make" can't
handle UTF-8 single- and double-quotes:
$ LANG=fr_FR.iso885915@euro make
...
asciidoc: FAILED: MANUAL.adoc: line 529: unexpected error:
...
File "/usr/lib/python3.8/encodings/iso8859_15.py", line 19, in encode
return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u201c'
in position 54: character maps to <undefined>
To avoid it the patch uses ASCII equivalents of symbols.
Azat Khuzhin [Sat, 9 Jan 2021 18:44:30 +0000 (21:44 +0300)]
Ignore SOURCE_DATE_EPOCH under time_macros sloppiness (#755)
SOURCE_DATE_EPOCH will be passed from debhelpers, by extracting last
entry from d/changelog (or current time if there is entries)
And this will not allow to use cache.
Alexander Lanin [Wed, 6 Jan 2021 20:50:41 +0000 (21:50 +0100)]
Fix scanning of headers with Clang-Tidy (#758)
By adding . as an include directory, CMake actually took it literally and files
are included from e.g. src/./AtomicFile.h. However in .clang-tidy headers with
an additional slash (headers from subdirectory third_party) are excluded from
reports.
This commit:
- gets rid of include via .
- fixes some warnings
- disables the rest
Joel Rosdahl [Wed, 6 Jan 2021 20:29:37 +0000 (21:29 +0100)]
Suppress Clang-Tidy warning about including signal.h
sigaddset and similar functions are specified by POSIX to be in signal.h
and the C++ csignal header only contains a subset of the signal.h
declarations.
Add VS2019 build jobs that use clang for the test suite. There are many
test failures on Windows, but these are ignored for now.
Tweak CMake build scripts:
- Fix CI build type handling for MSVC (recognise `/NDEBUG` and not just
`-DNDEBUG`)
- Fix incorrect warnings-as-errors flag for MSVC
- Suppress an additional conversion warning on MSVC
Joel Rosdahl [Mon, 4 Jan 2021 13:30:32 +0000 (14:30 +0100)]
Add debug_dir setting for specifying a directory for debug files
This makes it possible to store debug files outside a transient build
directory. As a bonus, it also allows for getting debug files when the
object file is /dev/null.
Joel Rosdahl [Wed, 6 Jan 2021 18:23:03 +0000 (19:23 +0100)]
Make Util::make_relative_path able to find matches for canonical path (#760)
Scenario:
- /tmp is a symlink to /private/tmp.
- Both apparent and actual CWD is /private/tmp/dir.
- A path (e.g. the object file) on the command line is /tmp/dir/file.o.
- Base directory is set up to match /tmp/dir/file.o.
Ccache then rewrites /tmp/dir/file.o into ../../private/tmp/dir/file.o,
which is correct but not optimal since ./file.o would be a better
relative path. Especially on macOS where, for unknown reasons, the
kernel sometimes disallows opening a file like
../../private/tmp/dir/file.o for writing.
Improve this by letting Util::make_relative_path try to match
real_path(path) against the CWDs and choose the best match.
Joel Rosdahl [Sun, 3 Jan 2021 12:39:57 +0000 (13:39 +0100)]
Fix retrieval of object file when destination is /dev/null
ResultRetriever::on_entry_data assumes that a destination file has been
opened if the entry type is not stderr_output, but that’s incorrect
since on_entry_start doesn’t open a destination file if it’s /dev/null.
An assertion is triggered:
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.