LLVM plugin support in Rust (original) (raw)

Proposal

It is desirable for a number of projects (automatic differentiation via Enzyme for RustML, formal verification, binary checking, annobin, and others) to be able to load LLVM plugins.

There's been a couple of discussions on the topic (https://internals.rust-lang.org/t/should-rustc-support-custom-llvm-plugin/13807) (rust-lang/rust#82734) that appear favorable to potential inclusion, with questions about how this should be safely integrated.

Integration is fairly simple and could be done by simply including the relevant header file

#include "llvm/Support/PluginLoader.h"

This would allow the traditional LLVM plugin loader flags -load=/path/to/plugin.so to succeed, shown below for Enzyme as an example:

-C llvm-args="-load=`pwd`/../Enzyme/enzyme/buildrs/Enzyme/LLVMEnzyme-11.so" -C passes="enzyme"

Alternatively, we could make a custom unstable flag that explicitly loads plugins in a similar manner:

This requires duplicating a little bit of the dlopen functionality for loading plugins in LLVM, except now in Rust (wsmoses/rust@0149bc4).

The one thing of note is that LLVM plugins most likely will require access to LLVM functions that may not otherwise be available in Rust. Practically, building Rust with a dynamically linked LLVM solves this. There may be other options here as well.

Mentors or Reviewers

Unsure who would be relevant to review (new to rust community. I'd be happy to mentor and also happy to push this myself.

Process

The main points of the Major Change Process are as follows:

You can read more about Major Change Proposals on forge.

Comments

This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.