This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] Avoid doing repeated fuzzy symbol lookup for each iteration. NFC.
ClosedPublic

Authored by mstorsjo on Jun 18 2021, 6:05 AM.

Details

Summary

This is run every time around in the main linker loop. Once a match
has been found, stop trying to rematch such a symbol.

Not sure if this has any actual measurable performance impact though
(SymbolTable::findMangle() iterates over the whole symbol table for
each call and does fuzzy matching on top of that) but this makes the
code more reassuring to read at least. (This is in practice run for def
files listing undecorated stdcall functions to be exported.)

Diff Detail

Event Timeline

mstorsjo requested review of this revision.Jun 18 2021, 6:05 AM
mstorsjo created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2021, 6:05 AM
rnk accepted this revision.Jun 18 2021, 9:52 AM

lgtm

This revision is now accepted and ready to land.Jun 18 2021, 9:52 AM
thakis added a subscriber: thakis.Jun 22 2021, 9:52 AM

Chances are this causes all the red windows boxes on https://chromium-review.googlesource.com/c/chromium/src/+/2976785

Chances are this causes all the red windows boxes on https://chromium-review.googlesource.com/c/chromium/src/+/2976785

Sounds plausible, feel free to revert once you’ve pinpointed it. If you manage to do that, it’d be great to add a test case showing how it broke things too.

I don’t have any direct need for this change per se, but I’m curious about how it broke anything.

rnk added inline comments.Jun 22 2021, 12:04 PM
lld/COFF/Driver.cpp
564

I think I see the issue: suppose there are two rounds of symbol resolution. This function will be called twice, and on the second call, it returns a different result to the caller. The result of this function is used to populate Export.symbolName, which is used to produce an import library, and that's what changes.

mstorsjo added inline comments.Jun 22 2021, 12:09 PM
lld/COFF/Driver.cpp
564

Right, if there are two possible matches for the fuzzy search, one to be more preferred than the other one, but the less preferred one is resolved first, then it would indeed break.

I suppose that can be considered intentional behaviour, so yeah, this should indeed be left reverted then. A testcase showing off this mechanism would be nice to have though.

rnk added inline comments.Jun 22 2021, 12:58 PM
lld/COFF/Driver.cpp
564

Yep, I added a test in rG5bcbc7ee526cea839f, it just took a bit of effort to set up an archive to get a second iteration of symbol resolution.

mstorsjo added inline comments.Jun 22 2021, 1:06 PM
lld/COFF/Driver.cpp
564

Awesome, thanks! Yeah I can imagine that requires a bit of fiddling.