Skip to content

Commit

Permalink
[Support] [Windows] Don't check file access time in equivalent(file_s…
Browse files Browse the repository at this point in the history
…tatus, file_status)

The sys::fs::equivalent(file_status, file_status) function is meant to
judge whether two file_status structs denote the same individual file.
On Unix, this is implemented by only comparing the st_dev and st_ino
numbers (from stat), ignoring all other fields.

On Windows, lacking reliable fields corresponding to st_dev and st_ino,
equivalent(file_status, file_status) compares essentially all fields.
However, since 1e39ef3
(https://reviews.llvm.org/D18456), file_status also contains the file
access time.

Including the file access time in equivalent(file_status, file_status)
makes it possible to spuriously break. In particular, when invoking
equivalent(Twine, Twine), with two paths, there's a race condition - the
function calls status() on both input paths. Even if the two paths
are the same, the comparison can fail, if the file was accessed
between the two status() calls.

Thus, it seems like the inclusion of the access time in
equivalent(file_status, file_status) was a mistake.

This race condition can cause spurious failures when linking with
LLD/ELF, where LLD uses equivalent() to check whether a file
exists within a specific sysroot, and that sysroot is accessed by other
processes concurrently.

This fixes downstream issue
msys2/MINGW-packages#15695.

Differential Revision: https://reviews.llvm.org/D144172
  • Loading branch information
rvogg authored and mstorsjo committed Feb 17, 2023
1 parent 389bfbd commit a1e80c6
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions llvm/lib/Support/Windows/Path.inc
Expand Up @@ -650,8 +650,6 @@ bool equivalent(file_status A, file_status B) {
return A.FileIndexHigh == B.FileIndexHigh &&
A.FileIndexLow == B.FileIndexLow && A.FileSizeHigh == B.FileSizeHigh &&
A.FileSizeLow == B.FileSizeLow &&
A.LastAccessedTimeHigh == B.LastAccessedTimeHigh &&
A.LastAccessedTimeLow == B.LastAccessedTimeLow &&
A.LastWriteTimeHigh == B.LastWriteTimeHigh &&
A.LastWriteTimeLow == B.LastWriteTimeLow &&
A.VolumeSerialNumber == B.VolumeSerialNumber;
Expand Down

0 comments on commit a1e80c6

Please sign in to comment.