This is an archive of the discontinued LLVM Phabricator instance.

[lld][COFF] Retry failed paths to take advantage of winsysroot search paths
ClosedPublic

Authored by aeubanks on May 31 2023, 8:58 AM.

Details

Summary

With /winsysroot and without /machine, we don't know which paths to add to the search paths.

We do autodetect machine type and add winsysroot search paths in SymbolTable::addFile(), but that happens after all input files are opened. So in the loop where we read files, if we fail to open a file we can retry with the winsysroot search path potentially added by reading a previous file. This will fail if we try to open something in the winsysroot before reading a file that can give us the architecture, but shrug.

Fixes #54409

Diff Detail

Event Timeline

aeubanks created this revision.May 31 2023, 8:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 8:58 AM
aeubanks requested review of this revision.May 31 2023, 8:58 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2023, 8:58 AM
rnk added inline comments.Jun 1 2023, 2:35 PM
lld/COFF/Driver.cpp
252–253

Can you please expand on this comment? The important thing is that, because we retry synchronously here, the order of inputs and symbol resolution doesn't change. This won't work if the first input on the command line comes from the MSVC installation, as you show in the tests, but maybe that's OK. Folks will get in trouble with a command like:

lld-link libcmt.lib myprogram.obj /winsysroot:path/to/install

And, because we ignore LIB when /winsysroot is present, we aren't open to changes in behavior from the environment, right? Basically, if you are using /winsysroot, an input file with an architecture has to come first, or there will be link errors.

lld/test/COFF/winsysroot.test
29

Maybe this isn't a FIXME, this is almost by design.

The last alternative I would consider is scanning the list of inputs, and check the machine of the first one ending in .obj if it is a COFF file.

aeubanks updated this revision to Diff 527633.Jun 1 2023, 2:44 PM

expand comment
remove FIXME

rnk accepted this revision.Jun 1 2023, 2:57 PM

lgtm

This revision is now accepted and ready to land.Jun 1 2023, 2:57 PM
This revision was landed with ongoing or failed builds.Jun 1 2023, 3:41 PM
This revision was automatically updated to reflect the committed changes.