[llvm-bugs] [Bug 51053] New: Windows implementation of `bool llvm::sys::fs::equivalent(file_status, file_status)` uses time when file was last accessed to determine identity

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jul 11 05:53:07 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51053

            Bug ID: 51053
           Summary: Windows implementation of `bool
                    llvm::sys::fs::equivalent(file_status, file_status)`
                    uses time when file was last accessed to determine
                    identity
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Support Libraries
          Assignee: unassignedbugs at nondot.org
          Reporter: tfbogdan at gmail.com
                CC: llvm-bugs at lists.llvm.org

This was observed when cross compiling for Linux, specifically in the link
stage when using lld. When a lot of linker instances are running at once,
`ScriptParser::ScriptParser` from the ELF lld flavor may incorrectly determine
that a library is not under `sysroot` and then later fail to prepend `sysroot`
to it's dependencies paths in `ScriptParser::addFile`. As a result, the link
process would fail with a lot of errors of the form: 

`Cannot open /lib64/libpthread.so`

The current implementation of the path equivalence function on Windows is
exactly this:
```
bool llvm::sys::fs::equivalent(file_status A, file_status B) {
  assert(status_known(A) && status_known(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;
}
```

This wraps the above
```
std::error_code llvm::sys::fs::equivalent(const Twine &A, const Twine &B, bool
&result) {
  file_status fsA, fsB;
  if (std::error_code ec = status(A, fsA))
    return ec;
  if (std::error_code ec = status(B, fsB))
    return ec;
  result = equivalent(fsA, fsB);
  return std::error_code();
}
```

Two file_status instances are created back to back and then most of their
attributes are equality compared. Another process accessing the path while this
function is evaluated can lead to the access time of the path to be different
and then the function would erroneously report that two paths are not
equivalent even when they are. 

It should be sufficient to use the file index and volume serial number to
reliably determine path equivalence, as even a write operation to a file would
not change it's identity.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210711/9524984f/attachment-0001.html>


More information about the llvm-bugs mailing list