This is an archive of the discontinued LLVM Phabricator instance.

Add -fplugin=name.so option to the driver
ClosedPublic

Authored by john.brawn on Sep 16 2015, 5:09 AM.

Details

Reviewers
compnerd
Summary

This translates to -load name.so in the cc1 command. We can't name the driver option -load, as that means "link against oad", so instead we follow GCC's lead and name the option -fplugin.

Diff Detail

Event Timeline

john.brawn updated this revision to Diff 34885.Sep 16 2015, 5:09 AM
john.brawn retitled this revision from to Allow the -load option in the driver and pass it through to -cc1.
john.brawn updated this object.
john.brawn set the repository for this revision to rL LLVM.
john.brawn added a subscriber: cfe-commits.

Hi John,

Can you expand a bit more on why you need this, what's the use case, and hopefully attach a test for them?

cheers,
--renato

Hi John,

Can you expand a bit more on why you need this, what's the use case, and hopefully attach a test for them?

The use-case is loading llvm plugins that add optimization passes via the PassManagerBuilder::addGlobalExtension mechanism (i.e. just loading the plugin is enough and you don't have to add anything extra to the command-line). Currently you have to do clang -Xclang -load -Xclang plugin.so, and it would be nicer to be able to do clang -load plugin.so.

I'm not sure how to best add a test for this. Maybe I should add another pass to llvm that's built as a plugin like llvm/lib/Transforms/Hello but that uses PassManagerBuilder::addGlobalExtension and have a clang test that runs that?

The use-case is loading llvm plugins that add optimization passes via the PassManagerBuilder::addGlobalExtension mechanism (i.e. just loading the plugin is enough and you don't have to add anything extra to the command-line). Currently you have to do clang -Xclang -load -Xclang plugin.so, and it would be nicer to be able to do clang -load plugin.so.

Right, I'm not familiar with that extension, so I can't really give an opinion. Maybe some of the Clang folks could help? Feel free to find the appropriate people and add them as reviewers, so they're aware of it.

I'm not sure how to best add a test for this. Maybe I should add another pass to llvm that's built as a plugin like llvm/lib/Transforms/Hello but that uses PassManagerBuilder::addGlobalExtension and have a clang test that runs that?

Well, since this is Clang, I think just a simple -### test checking that the flag was passed correctly down to CC1 would be enough, as I assume there are tests already for the flag in CC1 mode.

john.brawn updated this revision to Diff 34977.Sep 17 2015, 4:06 AM

Add a test.

Hi John,

Looks all right to me, but I don't want to approve without someone more familiar with the -load option to agree that this is not an exclusively internal option.

Other than that, I'm happy with it.

cheers,
--renato

While I agree that this makes the option much nicer to use, it collides with the -l flag. Since it was an internal only option until this point, we should rename it before exposing it at the driver level.

While I agree that this makes the option much nicer to use, it collides with the -l flag. Since it was an internal only option until this point, we should rename it before exposing it at the driver level.

Yes, you're right. GCC uses -fplugin=name.so for their plugin interface, which seems reasonable so I'll go with that to avoid having to think up something myself.

john.brawn retitled this revision from Allow the -load option in the driver and pass it through to -cc1 to Add -fplugin=name.so option to the driver.
john.brawn updated this object.

Rename option from -load to -fplugin.

Do you know if GCC requires the = or can you do -fplugin name.so ?

Do you know if GCC requires the = or can you do -fplugin name.so ?

GCC requires the =, or at least GCC 5.1.0 does when I tested it (you get "gcc: error: name.so: No such file or directory" and "gcc: error: unrecognized command line option '-fplugin'" if you do -fplugin name.so).

This comment was removed by rengolin.
compnerd accepted this revision.Sep 18 2015, 8:22 PM
compnerd added a reviewer: compnerd.

Looks fine minus the one thing that needs a quick look at.

include/clang/Driver/Options.td
952

Don't most options of this type use the _EQ suffix? Might be nice to follow the convention.

This revision is now accepted and ready to land.Sep 18 2015, 8:22 PM
thakis added a subscriber: thakis.Sep 19 2015, 3:35 PM

Is the idea that this loads plugins that link against clang's C++ api? That api isn't considered stable, so not having an "official" flag for this always looked by design to me. Also, C++ doesn't make for a good ABI. Also also, this approach fundamentally doesn't work on Windows.

Also also, this approach fundamentally doesn't work on Windows.

I don't think it's supposed to, anyway. :)

Also also, this approach fundamentally doesn't work on Windows.

I don't think it's supposed to, anyway. :)

Actually, I think it can work on Windows. Certainly -fplugin=foo.dll works on windows and the dll is correctly loaded, but the problem is building a dll that does something useful. Currently there's no way to build clang/llvm on windows so that LLVM_ENABLE_PLUGINS is true - setting BUILD_SHARED_LIBS sets it to true, but BUILD_SHARED_LIBS doesn't work (lots of linker errors). However I've managed to hack up a build of clang not using BUILD_SHARED_LIBS where it's possible to build plugin dlls that work (by sprinkling __declspec(dllexport) all over the place), so it doesn't look like there's a fundamental problem here. Also maybe it's possible to use llvm-readobj on the intermediate .lib files to generate a list of symbols to export and put that in a .def file for the link step and not have to do any modification to the source files at all, though I haven't been able to get that to work.

Anyway that's a bit of a digression. I've made naming change to OPT_fplugin_EQ, so I'll check that in.

john.brawn closed this revision.Sep 23 2015, 9:27 AM

Committed in r248378.