When hard link mode is enabled, ccache ≥3.6 unlinks the output file
before writing to it as a workaround for a bug in Clang (#331). This
unfortunately means that /dev/null will be removed when building as root
(don’t do that, BTW) with hard link mode enabled and /dev/null as the
the output file. A similar problem exists if the dependency file is
/dev/null, regardless of hard link mode.
Fix this by not unlinking the output file if it’s /dev/null and by not
copying files to /dev/null at all. (There is no need to handle other
non-regular output files since /dev/null is the only allowed non-regular
output file.)
Fixes #564.
static void
do_copy_or_link_file_from_cache(const char *source, const char *dest, bool copy)
{
+ if (str_eq(dest, "/dev/null")) {
+ cc_log("Skipping copy from %s to %s", source, dest);
+ return;
+ }
+
int ret;
bool do_link = !copy && conf->hard_link && !file_is_compressed(source);
if (do_link) {
args_add(args, "-o");
args_add(args, output_obj);
- if (conf->hard_link) {
+ if (conf->hard_link && !str_eq(output_obj, "/dev/null")) {
+ // This is a workaround for https://bugs.llvm.org/show_bug.cgi?id=39782.
x_unlink(output_obj);
}