mozilla / sccache

Sccache is a ccache-like tool. It is used as a compiler wrapper and avoids compilation when possible. Sccache has the capability to utilize caching in remote storage environments, including various cloud storage options, or alternatively, in local storage.
Apache License 2.0
5.85k stars 552 forks source link

Sccache crashes when run in parallel with /dev/null as the output #594

Open emilio opened 5 years ago

emilio commented 5 years ago

I was trying to reduce a test-case that doesn't compile with #545 + my-changes, but compiles with clang.

So I used creduce by comparing clang and sccache as follows:

#!/usr/bin/env bash                                                                                                                                                                                                                           

FILE=out.cpp
CLANG_COMMAND="/usr/bin/clang++ -x c++ -c $FILE -o /dev/null -DDEBUG=1 -DOS_POSIX=1 -DOS_LINUX=1 -DSTATIC_EXPORTABLE_JS_API -DMOZ_HAS_MOZGLUE -DMOZILLA_INTERNAL_API -DIMPL_LIBXUL -fPIC -DMOZILLA_CLIENT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-sized-deallocation -fno-aligned-new -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-exceptions -fno-strict-aliasing -fno-rtti -fno-exceptions -fno-math-errno -pthread -pipe -g -Os -fno-omit-frame-pointer -funwind-tables -fdiagnostics-color=always"

$CLANG_COMMAND # >/dev/null 2>&1
CLANG_RESULT=$?

echo "clang: $CLANG_RESULT"
if [ $CLANG_RESULT -ne 0 ]; then
  exit 1
fi

sccache $CLANG_COMMAND # >/dev/null 2>&1
SCCACHE_RESULT=$?

echo "sccache: $SCCACHE_RESULT"
if [ $SCCACHE_RESULT -eq 0 ]; then
  exit 1
fi

exit 0

However, it seems like sccache, when run in parallel, may end up trying to create a temporary file in /dev/, and crashes like:

sccache: encountered fatal error
sccache: error : Permission denied (os error 13) at path "/dev/.tmpo4Y0uv"
sccache:  cause: Permission denied (os error 13) at path "/dev/.tmpo4Y0uv"

Workaround is using a different path from /dev/null of course, but it seems like this should work.

sigiesec commented 5 years ago

I remember a similar issue (unrelated to sccache) on some Azure nodes where clang wanted to write temporary files to an inaccessible directory. IIRC we needed to add the -save-temps option to fix that.

luser commented 5 years ago

FYI we had hit a similar issue with MSVC and worked around it by just making sccache refuse to cache compilations that output to nul on Windows: https://github.com/mozilla/sccache/blob/7e9daab24cb88802b2b97f37ae9d3816628bd90c/src/compiler/msvc.rs#L292