<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Windows implementation of `bool llvm::sys::fs::equivalent(file_status, file_status)` uses time when file was last accessed to determine identity"
   href="https://bugs.llvm.org/show_bug.cgi?id=51053">51053</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Windows implementation of `bool llvm::sys::fs::equivalent(file_status, file_status)` uses time when file was last accessed to determine identity
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Support Libraries
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>tfbogdan@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>