Building and Using Out-of-Tree LLVM Plugins

I am currently working on a small plugin that preferably would work on as many platforms possible.

While I had no problem to get the plugin working with either clang and opt I encountered problems with the Rust compiler.

After tracking down every potential problem, I found the problem:

By default rustc statically links the libLLVM into the binary itself, causing various problems. Rebuilding the Rust compiler to use a shared libLLVM in the end resolved the problem.

As it is not always possible to change the toolchain, I was wondering how it would be possible to support “default” installation of compilers that statically link the libLLVM. I had following options in mind but I do not know if they are actually feasible as I lack some knowledge:

  • link the libLLVM statically to the plugin (might lead to problems when loading the plugin on other platforms)
  • provide a shared libLLVM that the plugin can access

Is any of these variants feasible to work?