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.
Details
Diff Detail
Event Timeline
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
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?
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.
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.
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.
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).
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. |
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.
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.
Don't most options of this type use the _EQ suffix? Might be nice to follow the convention.