Threading rust attributes to LLVM annotations

I’m doing exploratory work where I’d like to be able to add annotations to Rust function and data declarations that I’d like to be able to look for in the generated LLVM.

I am still new to rust, but one design would be to define new Rust attributes via the plugin API, and then have annotations on top-level attributes translate into appends to @llvm.global.annotations. Annotations on data could then translate into calls of @llvm.var.annotation. This would make the Rust LLVM pretty similar to what I currently see with clang when attaching annotations via __attribute__((annotate("...")).

I haven’t been able to find an existing project that does something like this, but I’m still getting up to speed with what’s out there. Are there any current projects that provide a way of passing Rust source annotations onto LLVM? All the analysis I’d like to do is at the LLVM representation, so I just want a minimally disruptive way of doing this.

Are you looking at this only as exploratory, or as a long-term plan?

If the former, there’s probably space for a new perma-instable thing like link_llvm_intrinsics to allow experimenting with things without needing new compiler builds every time.

For the latter, we generally don’t expose LLVM stuff unmodified as we’re not willing to promise stability for it, so it’d probably need to be new individual rust attributes for whatever specific goal you’re trying to accomplish with the LLVM attribute.

Thanks – this is just exploratory for now. I’ll try out the link_llvm_intrinsics feature.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.