This is an archive of the discontinued LLVM Phabricator instance.

Fix build warning compiling TestPlugin on Windows and disable Passes plugin stuff on Windows since it fundamentally can't work
ClosedPublic

Authored by thakis on May 18 2018, 11:35 AM.

Details

Summary

Aaron Ballman reported that TestPlugin warned about it using exception handling without /EHsc flag, and that llvmGetPassInfo() had conflicting export attributes (dllimport in the header, dllexport in the source file).

/EHsc is because TestPlugin didn't use the llvm_ cmake functions, so llvm_update_compile_flags didn't get called for the target (llvm_update_compile_flags explicitly passes /Ehs-c-, which fixes the warning). Use add_llvm_loadable_module instead of add_library(... MODULE) to fix this. This also has the side effect of not building the plugin on Windows. That's not a big problem, since before the plugin was built on Windows, but the test didn't attempt to load it, due to -DLLVM_ENABLE_PLUGIN not being passed to PluginsTests.cpp during compilation on Windows. This makes the plugin behavior consistent with e.g. lib/Transforms/Hello/CMakeLists.txt. (This also automatically sets LTDL_SHLIB_EXT correctly.)

The dllimport/dllexport warning is more serious: Since LLVM doesn't generally use export annotations for its code, the only way the plugin could link was by linking in some LLVM libraries both into the test and the dll, so the plugin would call the llvm code in the dll instead of the copy in the main executable. This means globals weren't shared, and things generally can't work. (I think there's a build config where you can build a LLVM.dll which might work, but that wasn't how the test was configured. If that config is used, the dll should still be built, but I haven't checked).

Now that add_llvm_loadable_module is used, LLVM_LINK_COMPONENTS got linked into both executable and plugin on posix too, so unset it after the executable so that the plugin doesn't end up with a 2nd copy of things on posix.

Diff Detail

Event Timeline

thakis created this revision.May 18 2018, 11:35 AM

I'm likely not the right person to review this, I know next to nothing about windows dev.

On the other hand, legacy pass plugins are still enabled currently, and have been re-enabled only recently IIRC. Are those similarly fundamentally broken as well? Or is there anything different there that makes them work?

Adding some more Win32 folks. These changes look reasonable to me, but I'd like some confirmation.

Have plugins ever worked on Windows when building with MSVC? I seem to recall them being disabled there specifically because we don't export and import interfaces from DLLs properly, but I could be remembering wrong.

There is this ancient commit here D18826 that introduced auto-export of all symbols. Shouldn't this work here as well?

There is this ancient commit here D18826 that introduced auto-export of all symbols. Shouldn't this work here as well?

Blech, yes, I believe it could, but I agree with @rnk's original comments on that thread -- we should consider getting serious about properly annotating our API boundaries. Obviously, that is not in scope for this patch. ;-)

I agree with @rnk, too, the question is do we want to enable this in the meantime?

rnk accepted this revision.May 18 2018, 2:24 PM

lgtm

Thanks for resolving this!

Have plugins ever worked on Windows when building with MSVC? I seem to recall them being disabled there specifically because we don't export and import interfaces from DLLs properly, but I could be remembering wrong.

I don't think so. I think over the years people have done crazy stuff with dumpbin and LLVM_ENABLE_DYLIB (or whatever it's called) to make things kind of work, but it's never worked in any of the common build modes.

This revision is now accepted and ready to land.May 18 2018, 2:24 PM

Thanks for the clarification @rnk!

aaron.ballman accepted this revision.May 18 2018, 3:04 PM
In D47082#1105085, @rnk wrote:

lgtm

Thanks for resolving this!

Have plugins ever worked on Windows when building with MSVC? I seem to recall them being disabled there specifically because we don't export and import interfaces from DLLs properly, but I could be remembering wrong.

I don't think so. I think over the years people have done crazy stuff with dumpbin and LLVM_ENABLE_DYLIB (or whatever it's called) to make things kind of work, but it's never worked in any of the common build modes.

Okay, that's what I thought. Thank you for the confirmation -- patch LGTM as well.

thakis closed this revision.May 18 2018, 8:09 PM

r332796, thanks!