This is an archive of the discontinued LLVM Phabricator instance.

[COFF] Add vfsoverlay flag
ClosedPublic

Authored by abrachet on May 17 2022, 8:31 AM.

Details

Summary

This patch adds a new flag vfsoverlay similar to clang’s ivfsoverlay flag. This is helpful when compiling on case sensitive file systems when cross compiling to Windows. Particularly when compiling third party code containing #pragma comment(“linker”, “/defaultlib:...”) which can’t be easily changed.

Diff Detail

Event Timeline

abrachet created this revision.May 17 2022, 8:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 8:31 AM
abrachet requested review of this revision.May 17 2022, 8:31 AM
smeenai resigned from this revision.May 17 2022, 5:59 PM

In the LLVM Windows toolchain, we work around this by creating a directory of symlinks: https://github.com/llvm/llvm-project/blob/8527f32f0a16a77edb0b53a5ab8074e518eeff54/llvm/cmake/platforms/WinMsvc.cmake#L133-L157. A VFS overlay would be a nicer solution, and I'm excited to have this supported. I'll leave the review to @rnk and @mstorsjo though.

rnk added a subscriber: ayzhao.

This seems reasonable to me, but surely this is not the complete list of places where we must use the VFS?

I added folks with cross-compilation & case (in)sensitivity experience to the review. +@ayzhao as well.

Looks alright to me.

I'll mention that you can get this working without an overlay with ciopfs (https://source.chromium.org/chromium/chromium/src/+/main:build/vs_toolchain.py;l=494?q=ciopfs), but this is an ok approach as well.

abrachet updated this revision to Diff 432027.May 25 2022, 9:33 AM

Fix test on windows

This seems reasonable to me, but surely this is not the complete list of places where we must use the VFS?

Not sure where else it would be useful. Specifically I thought this would be useful because /defaultlib can be specified in source code through pragma comment which might be harder to change than build flags. If folks have any other ideas of where it would be useful to look in the vfs I would be happy to add them.

@rnk @hans @thakis Is it OK with you if we land this?

hans added a comment.Jun 28 2022, 7:19 AM

Seems good to me in principle, I just have a few nits.

Have you checked whether this affects the performance when linking something large-ish without the vfs overlay?

lld/COFF/Driver.cpp
453

Is the explicit SmallString constructor call needed, or would just path = getFilename(...) work?

458

Ditto.

1367

nit: I think return nullptr would be more common llvm style.

1371

Shouldn't we give the user an error message?

1374

Ditto if this fails.

lld/test/COFF/vfsoverlay.test
7

Can we have tests cases for when the /vfsoverlay file doesn't exist or is invalid?

abrachet updated this revision to Diff 442652.Jul 6 2022, 11:47 AM
abrachet marked 6 inline comments as done.

Better error handling

Have you checked whether this affects the performance when linking something large-ish without the vfs overlay?

I did not, but can if you believe it could reasonably affect performance. My thinking is that this only adds an if statement to each findFile invocation, which for COFF seems to be very rare, and even for ld.lld which would end up searching for files much more frequently, the cost that one check per findFile doesn't seem high.

lld/COFF/Driver.cpp
453

That makes the SmallString ctor fail with an assertion "Attempting to reference an element of the vector in an operation that invalidates it"

hans accepted this revision.Jul 11 2022, 3:40 AM

lgtm

This revision is now accepted and ready to land.Jul 11 2022, 3:40 AM
This revision was landed with ongoing or failed builds.Jul 11 2022, 2:32 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 2:32 PM