This is an archive of the discontinued LLVM Phabricator instance.

[lld]Enabling loading LLVM pass plugins
ClosedPublic

Authored by efriedma on Mar 9 2020, 3:38 PM.

Details

Summary

Add the relevant magic bits to allow "-mllvm=-load=plugin.so" etc.

This is now using export_executable_symbols_for_plugins, so symbols are only exported if plugins are enabled.

Diff Detail

Event Timeline

efriedma created this revision.Mar 9 2020, 3:38 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2020, 3:38 PM
Herald added a subscriber: mgorny. · View Herald Transcript
vh added a subscriber: vh.Mar 11 2020, 4:22 AM
MaskRay added inline comments.Mar 12 2020, 3:32 PM
lld/tools/lld/CMakeLists.txt
11

Does this CMake function enable -rdynamic (the same as -Wl,--export-dynamic)? It can make the executable much larger because all defined symbols in .symtab will end up in .dynsym and consume a lot of .dynstr space...

efriedma marked an inline comment as done.Mar 12 2020, 4:06 PM
efriedma added inline comments.
lld/tools/lld/CMakeLists.txt
11

Yes. We have to expose all the LLVM symbols so that the plugin can use them (the plugin has to be using the same LLVM as lld itself). We do the same thing in clang.

I guess we could add a CMake option to disable this, if you want a minimal config that doesn't support pass plugins. Not sure how likely it is anyone would use such an option.

jhenderson added inline comments.Mar 13 2020, 1:46 AM
lld/tools/lld/CMakeLists.txt
11

We have a policy whereby users are not allowed to inject their own custom passes into the compilation or link. The latter is currently impossible at the moment, and we'd like to keep it that way internally at least. If there is a compile-time option when building LLD to disable the plugin behaviour, it would be much appreciated by us. I don't think it matters too much from our point of view if it is off or on by default though, though we'd obviously prefer off.

vh marked an inline comment as done.Mar 13 2020, 5:16 AM
vh added inline comments.
lld/tools/lld/CMakeLists.txt
11

I need this option for afl++ (which is included in the Debian, SuSE, Kali etc repos).
If this is made optional and off by default then some distros would have it enabled (the ones that ship afl++) and others not and that would create some confusion.

I am not aware of an lld feature that would people strongly want so they install lld (it has to be selected by hand on most distros I think) so this option might be a reason to :)

andwar added a subscriber: andwar.Mar 17 2020, 2:52 AM

Posted https://reviews.llvm.org/D76527 with new CMake function export_executable_symbols_for_plugins , which only exports symbols if LLVM_ENABLE_PLUGINS is on.

efriedma updated this revision to Diff 252119.Mar 23 2020, 12:24 PM
efriedma retitled this revision from [lld][WIP]Enabling loading LLVM pass plugins to [lld]Enabling loading LLVM pass plugins.
efriedma edited the summary of this revision. (Show Details)
efriedma added a reviewer: MaskRay.

Rebased, address review comments.

MaskRay accepted this revision.Mar 23 2020, 12:40 PM
This revision is now accepted and ready to land.Mar 23 2020, 12:40 PM
This revision was automatically updated to reflect the committed changes.