This is an archive of the discontinued LLVM Phabricator instance.

[lld][COFF] Add -print-search-paths for debugging.
ClosedPublic

Authored by thieta on Jul 12 2023, 12:25 AM.

Details

Summary

While working on adding more implicit search paths to the
lld COFF driver, it was helpful to have a way to print all
the search paths, both for debugging and for testing without
having to create very complicated test cases.

This is a simple arg that just prints the search paths and exits.

Diff Detail

Event Timeline

thieta created this revision.Jul 12 2023, 12:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2023, 12:25 AM
thieta requested review of this revision.Jul 12 2023, 12:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 12 2023, 12:25 AM
thieta edited the summary of this revision. (Show Details)Jul 12 2023, 12:27 AM
thieta added reviewers: hans, mstorsjo, rnk, MaskRay, phosek.
thieta updated this revision to Diff 539469.Jul 12 2023, 3:22 AM
thieta edited the summary of this revision. (Show Details)
hans added a comment.Jul 12 2023, 3:38 AM

Seems handy to me. We could also add this kind of info to the /verbose output, but having a separate option is probably more convenient.

lld/COFF/Options.td
301

My ocd noticed that this section of flags seems to be alphabetical.

lld/test/COFF/print-search-paths.s
8

Those backslashes will probably be forward slashes when this test runs on non-Windows.

Seems handy to me. We could also add this kind of info to the /verbose output, but having a separate option is probably more convenient.

Yeah, I considered using /verbose first, but it's pretty crowded, and it was harder to see the output when parsing real files. I can add it to verbose *also* if we think that's good?

lld/COFF/Options.td
301

Will fix!

lld/test/COFF/print-search-paths.s
8

Ah good point. Is there a good facility in Filecheck to match the correct slashes?

mstorsjo added inline comments.Jul 12 2023, 4:11 AM
lld/test/COFF/print-search-paths.s
8

Lots of tests have explicit regexes for it (see e.g. clang/test/Driver), like {{[/\\\\]}}. It's an absolute pain to both write and read though.

hans added inline comments.Jul 12 2023, 4:14 AM
lld/test/COFF/print-search-paths.s
8

No, I believe the way to do is it with regexes: {{[/\\]}}

thieta updated this revision to Diff 539518.Jul 12 2023, 5:46 AM
thieta added inline comments.Jul 12 2023, 5:47 AM
lld/test/COFF/print-search-paths.s
8

It's beautiful!

Side-note: maybe we should have a flag to FileCheck or something to allow it to match both or some kind of subst macro.

thieta marked 4 inline comments as done.Jul 12 2023, 5:48 AM
hans accepted this revision.Jul 12 2023, 5:54 AM

lgtm

This revision is now accepted and ready to land.Jul 12 2023, 5:54 AM
hans added a comment.Jul 12 2023, 6:31 AM

By the way, do we have a github issue tracking the whole https://discourse.llvm.org/t/improve-autolinking-of-compiler-rt-and-libc-on-windows-with-lld-link/71392/ situation? If so it would be nice to reference it in the commit.

By the way, do we have a github issue tracking the whole https://discourse.llvm.org/t/improve-autolinking-of-compiler-rt-and-libc-on-windows-with-lld-link/71392/ situation? If so it would be nice to reference it in the commit.

https://github.com/llvm/llvm-project/issues/63827

Will link all the commits to this.

@mstorsjo are you good with this diff?

MaskRay added inline comments.Jul 12 2023, 9:58 AM
lld/COFF/Driver.cpp
2065

If we want to behave more like ld.lld, --print-* does not quit early. If we want to behave more like clang driver, options like --print-target-triple quit early. I think the ld.lld style makes more sense.

thieta added inline comments.Jul 12 2023, 12:01 PM
lld/COFF/Driver.cpp
2065

So print and not exit until the linker normally exits? That seems fine to me, unless anyone objects to that I'll make that change tomorrow.

No objections from me, looks reasonable.

Just make sure the test passes on both unix and Windows - which I believe the premerge CI should cover here. There's always a bit of fiddliness regarding absolute paths and literally checking for matches; e.g. if the tool would happen to renormalize path separator style within that section, that would break. But I believe we use that pattern in a few other places as well so it's most probably fine.

thieta updated this revision to Diff 539866.Jul 13 2023, 12:13 AM
thieta updated this revision to Diff 539878.Jul 13 2023, 12:49 AM

Removed the early exit to behave similar to ld.lld, fixed the tests so they work with this behavior and then I tested all on linux and windows and it seems to work correctly! I think this is good to land.

phosek accepted this revision.Jul 13 2023, 1:46 AM

LGTM

This revision was automatically updated to reflect the committed changes.