This is an archive of the discontinued LLVM Phabricator instance.

[lld/mac] Print dylib search details with --print-dylib-search or RC_TRACE_DYLIB_SEARCHING
ClosedPublic

Authored by thakis on Jun 9 2021, 12:21 PM.

Details

Summary

For debugging dylib loading, it's useful to have some insight into what
the linker is doing.

ld64 has the undocumented RC_TRACE_DYLIB_SEARCHING env var
for this printing dylib search candidates.

This adds a flag --print-dylib-search to make lld print the seame information.
It's useful for users, but also for writing tests. The output is formatted
slightly differently than ld64, but we still support RC_TRACE_DYLIB_SEARCHING
to offer at least a compatible way to trigger this.

ld64 has both -print_statistics and -trace_symbol_output to enable
diagnostics output. I went with "print" since that seems like a more
straightforward name.

Diff Detail

Unit TestsFailed

Event Timeline

thakis created this revision.Jun 9 2021, 12:21 PM
Herald added a reviewer: gkm. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: dang. · View Herald Transcript
thakis requested review of this revision.Jun 9 2021, 12:21 PM
thakis updated this revision to Diff 350987.Jun 9 2021, 1:15 PM

clang-format

alexander-shaposhnikov added inline comments.
lld/MachO/DriverUtils.cpp
179–182

perhaps, logDylibSearchResult would be a better name ?
also - maybe use StringRef instead of Twine ?

192

dylibPath.str() ?

thakis added inline comments.Jun 9 2021, 1:27 PM
lld/MachO/DriverUtils.cpp
179–182

The last caller in this file passes a Twine, so StringRef doesn't work.

I like the shorter name.

192

This is just moving code around that was here previously. std::string(...) is how you convert a string view to a string in c++17, so I suppose this is consistent with that.

lld/MachO/DriverUtils.cpp
179–182

I think readability of the code matters, not sure if "searchedDylib" is a sufficiently descriptive name

192

quick grepping shows some minor inconsistency even inside lld/MachO. It doesn't change the "functional" side of the problem, but having a consistent code would definitely be a plus. I'm not against any of these methods, but wanted to point this out / so that at least the new code is written in a more consistent way.

int3 accepted this revision.Jun 9 2021, 2:03 PM
int3 added inline comments.
lld/MachO/DriverUtils.cpp
179–182

"logSearchedDylib"? I'm fine with anything, but I'd prefer not to have Java-length verbosity

This revision is now accepted and ready to land.Jun 9 2021, 2:03 PM
thakis added a comment.Jun 9 2021, 3:16 PM

Thanks!

lld/MachO/DriverUtils.cpp
179–182

Maybe didSearchDylib?

int3 added inline comments.Jun 9 2021, 4:25 PM
lld/MachO/DriverUtils.cpp
179–182

eh, that has the same information as searchedDylib but is one character longer :p "log" describes what it's doing at least

thakis updated this revision to Diff 351011.Jun 9 2021, 5:23 PM

try to make test pass on windows

lld/MachO/DriverUtils.cpp
179–182

Ah, naming :)

I don't love "logSearchedDylib". "log" is obviously a verb here, and it logs a "searched dylib", but what's a "searched dylib"? "searched" acts as an adjective here but isn't one and it sounds weird to me. (Then again, I'm not a native speaker – on the third hand, so are others who might read this.) "logDylibSearch" is a bit better but then it's not clear if we log the start or the end of the search. "searchedDylib" is ok since the verb is "search", it's in past tense so it's over, and "dylib" is an ok object. The drawback is that you can read "searched" as an adjective if you squint enough (cf "logSearchedDylib"), and. "didSearchDylib" addresses that.

logDylibSearchResult() feels a bit long compared to our other names.

I think the usual takeaway when you have a list of options where none is obviously the best is that the decision doesn't really matter all that much – especially if it's easy to change later on :) So I think I'll just leave this as is for now, and if anyone feels motivated enough to change it later, go for it.

Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2021, 7:08 PM