[LLD][COFF] Retry pathStr directly in LinkerDriver::enqueuePath before findFileIfNew (#230249)

On Windows XLA CI builds, lld-link occasionally fails with hundreds of
undefined symbol errors for symbols defined in an object file that was
passed on the linker command line, without reporting any error opening
that object file.

Before calling LinkerDriver::enqueuePath, callers check findFileIfNew or
findLibIfNew. If the input file already exists on disk, findFileIfNew
records the file's unique ID in visitedFiles so the same file is not
linked twice.

On 64-bit Windows, enqueuePath opens the file asynchronously via
createFutureForFile. When the main thread later calls future->get(), if
that initial open failed (for example, due to a transient file-sharing
error on Windows when many async tasks open files concurrently, or when
an existing file lacks read permissions), enqueuePath enters its
fallback path.

That fallback path was written for /winsysroot, where a file path might
not resolve until /winsysroot search directories are added later, so it
calls findFileIfNew(pathStr) again. However, if the file already existed
on disk when enqueuePath was first called, its unique ID is already in
visitedFiles. Calling findFileIfNew(pathStr) a second time sees that the
file was already visited, returns nullopt as if it were a duplicate
input, and returns early. As a result, lld-link silently drops the
object file from the link without retrying the open or reporting a
"could not open" error, and the link later fails with missing symbols.

To fix this, when future->get() fails, first retry opening pathStr
directly with MemoryBuffer::getFile. Only if that still fails and
findFile(pathStr) resolves to a different path than pathStr (the
deferred /winsysroot search path case) do we call findFileIfNew. If
retrying pathStr still fails and no new path was found, lld-link now
falls through and reports the "could not open" error instead of silently
ignoring the file.

GitOrigin-RevId: dcac7b6cdde92581e0cfe0f4207b9e5e20a833cb
2 files changed
tree: 60ac134b8fadb798da7182a8342bb69bbbcaa4e5
  1. cmake/
  2. COFF/
  3. Common/
  4. docs/
  5. ELF/
  6. include/
  7. MachO/
  8. MinGW/
  9. test/
  10. tools/
  11. unittests/
  12. utils/
  13. wasm/
  14. .clang-format
  15. .clang-tidy
  16. .gitignore
  17. CMakeLists.txt
  18. LICENSE.TXT
  19. Maintainers.md
  20. README.md
README.md

LLVM Linker (lld)

This directory and its subdirectories contain source code for the LLVM Linker, a modular cross platform linker which is built as part of the LLVM compiler infrastructure project.

lld is open source software. You may freely distribute it under the terms of the license agreement found in LICENSE.txt.

Benchmarking

In order to make sure various developers can evaluate patches over the same tests, we create a collection of self contained programs.

It is hosted at https://s3-us-west-2.amazonaws.com/linker-tests/lld-speed-test.tar.xz

The current sha256 is 10eec685463d5a8bbf08d77f4ca96282161d396c65bd97dc99dbde644a31610f.