jamesmth / llvm-plugin-rs Goto Github PK
View Code? Open in Web Editor NEWOut-of-tree LLVM passes in Rust
License: Apache License 2.0
Out-of-tree LLVM passes in Rust
License: Apache License 2.0
Loading a test plugin (e.g. tests/plugins/plugin1
) in opt
fails with the following stack trace:
Assertion failed: AnalysisPasses.count(PassT::ID()) && "This analysis pass was not registered prior to being queried", file C:\LLVM\include\llvm/IR/PassManager.h, line 779
Stack dump:
0. Program arguments: C:\LLVM\bin\opt.exe --load-pass-plugin=tests\plugins\target\debug\plugin1.dll --passes=mpass,function(fpass) tests/test.ll -disable-output
#0 0x00007ff6e99ed505 HandleAbort (C:\LLVM\bin\opt.exe+0x15ed505)
#1 0x00007ffd5530bab4 (C:\Windows\System32\ucrtbase.dll+0x7bab4)
#2 0x00007ffd5530ca81 (C:\Windows\System32\ucrtbase.dll+0x7ca81)
#3 0x00007ffd5530e451 (C:\Windows\System32\ucrtbase.dll+0x7e451)
#4 0x00007ffd5530e[69](https://github.com/jamesmth/llvm-plugin-rs/runs/8168481470?check_suite_focus=true#step:12:70)1 (C:\Windows\System32\ucrtbase.dll+0x7e691)
#5 0x00007ffd2288b124 llvm::AnalysisManager<class llvm::Module>::getResult<class llvm::PassInstrumentationAnalysis>(class llvm::Module &) C:\LLVM\include\llvm\IR\PassManager.h:778:0
#6 0x00007ffd2289a503 llvm::AnalysisManager<class llvm::Module>::getResultImpl(struct llvm::AnalysisKey *, class llvm::Module &) C:\LLVM\include\llvm\IR\PassManager.h:956:0
#7 0x00007ffd2288b03d llvm::AnalysisManager<llvm::Module>::getResult<`anonymous namespace'::Analysis<ModuleIR> > C:\LLVM\include\llvm\IR\PassManager.h:780:0
#8 0x00007ffd2287f85f getModuleAnalysisResult D:\a\llvm-plugin-rs\llvm-plugin-rs\llvm-plugin\cpp\ffi.cc:17:0
#9 0x00007ffd228631b4 llvm_plugin::analysis::ModuleAnalysisManager::get_result::h2f98a[71](https://github.com/jamesmth/llvm-plugin-rs/runs/8168481470?check_suite_focus=true#step:12:72)676f61429 D:\a\llvm-plugin-rs\llvm-plugin-rs\llvm-plugin\src\analysis.rs:77:0
#10 0x00007ffd22862154 plugin1::plugin::impl$0::run_pass D:\a\llvm-plugin-rs\llvm-plugin-rs\tests\plugins\plugin1\src\lib.rs:24:0
#11 0x00007ffd228626b7 plugin1::plugin::mpass_entrypoint D:\a\llvm-plugin-rs\llvm-plugin-rs\tests\plugins\plugin1\src\lib.rs:1:0
#12 0x00007ffd2287fd37 `anonymous namespace'::Pass<ModuleIR>::run D:\a\llvm-plugin-rs\llvm-plugin-rs\llvm-plugin\cpp\pass.hh:22:0
#13 0x00007ffd22880c3f llvm::detail::PassModel<llvm::Module,`anonymous namespace'::Pass<ModuleIR>,llvm::PreservedAnalyses,llvm::AnalysisManager<llvm::Module> >::run C:\LLVM\include\llvm\IR\PassManagerInternal.h:79:0
#14 0x00007ff6e8471f3d llvm::detail::AnalysisPassModel<class llvm::Function, class llvm::AAManager, class llvm::PreservedAnalyses, class llvm::AnalysisManager<class llvm::Function>::Invalidator>::run(class llvm::Function &, class llvm::AnalysisManager<class llvm::Function> &) (C:\LLVM\bin\opt.exe+0x71f3d)
#15 0x00007ff6e8473288 llvm::detail::AnalysisPassModel<class llvm::Function, class llvm::AAManager, class llvm::PreservedAnalyses, class llvm::AnalysisManager<class llvm::Function>::Invalidator>::run(class llvm::Function &, class llvm::AnalysisManager<class llvm::Function> &) (C:\LLVM\bin\opt.exe+0x73288)
#16 0x00007ff6e847eb[72](https://github.com/jamesmth/llvm-plugin-rs/runs/8168481470?check_suite_focus=true#step:12:73) llvm::cl::alias::done(void) (C:\LLVM\bin\opt.exe+0x7eb72)
#17 0x00007ff6ea07a750 llvm::itanium_demangle::StdQualifiedName::printLeft(class llvm::itanium_demangle::OutputStream &) const (C:\LLVM\bin\opt.exe+0x1c7a750)
#18 0x00007ffd57524ed0 (C:\Windows\System32\KERNEL32.DLL+0x14ed0)
#19 0x00007ffd57b7e39b (C:\Windows\SYSTEM32\ntdll.dll+0x7e39b)
If one compiles a plugin by manually specifying the LLVM installation path through LLVM_PLUGIN_PREFIX
, LLVM_SYS_*_PREFIX
should be specified as well.
Failing to do so would compile just fine, however there would be a link-time failure on windows:
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeNativeTarget referenced in function _ZN19llvm_plugin_inkwell7targets6Target17initialize_native17h08b7c706c2d9d071E
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeNativeAsmPrinter referenced in function _ZN19llvm_plugin_inkwell7targets6Target17initialize_native17h08b7c706c2d9d071E
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeNativeAsmParser referenced in function _ZN19llvm_plugin_inkwell7targets6Target17initialize_native17h08b7c706c2d9d071E
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeNativeDisassembler referenced in function _ZN19llvm_plugin_inkwell7targets6Target17initialize_native17h08b7c706c2d9d071E
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeAllTargets referenced in function _ZN19llvm_plugin_inkwell7targets6Target14initialize_all17h82f657c9247b850fE
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeAllTargetInfos referenced in function _ZN19llvm_plugin_inkwell7targets6Target14initialize_all17h82f657c9247b850fE
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeAllAsmParsers referenced in function _ZN19llvm_plugin_inkwell7targets6Target14initialize_all17h82f657c9247b850fE
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeAllAsmPrinters referenced in function _ZN19llvm_plugin_inkwell7targets6Target14initialize_all17h82f657c9247b850fE
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeAllDisassemblers referenced in function _ZN19llvm_plugin_inkwell7targets6Target14initialize_all17h82f657c9247b850fE
libllvm_plugin_inkwell-b65169ff3f820c9e.rlib(llvm_plugin_inkwell-b65169ff3f820c9e.llvm_plugin_inkwell.8b77332f-cgu.4.rcgu.o) : error LNK2019: unresolved external symbol LLVM_InitializeAllTargetMCs referenced in function _ZN19llvm_plugin_inkwell7targets6Target14initialize_all17h82f657c9247b850fE
D:\a\llvm-plugin-rs\tests\plugins\target\debug\deps\plugin1.dll : fatal error LNK1120: 10 unresolved externals
This is due to llvm-sys
not building libwrapper
when it fails to find llvm-config
(which happens precisely when LLVM_SYS_*_PREFIX
isn't set and LLVM is not in the system PATH
).
There should be a compile time error when LLVM_PLUGIN_PREFIX
is used without LLVM_SYS_*_PREFIX
.
versions:
OS: Fedora Linux 39 x86_64
LLVM:
llvm16.x86_64 16.0.6-5.fc39 @fedora
llvm16-devel.x86_64 16.0.6-5.fc39 @fedora
llvm16-libs.x86_64 16.0.6-5.fc39 @fedora
llvm16-static.x86_64 16.0.6-5.fc39 @fedora
reproduction:
$ unzip repro.zip
$ cd repro
$ cargo b
$ opt-16 --load-pass-plugin=./target/debug/librepro.so --passes='my_pass' file.ll -S -o file_out.ll
expected behavior:
file_out.ll is created
actual behavior:
segmentation fault (core dumped)
https://github.com/TheDan64/inkwell just got support for llvm 17, so hopefully a release will be on crates.io soon. Then it'd be awesome to see support in this crate.
Hello,
A few months ago I ported this repo to LLVM 15 to use with the rust compiler, but whenever I tried loading the produced passes, I would get a SIGSEGV in rustc. At the time I thought this was entirely my fault, and gave up due to time constraints and the difficulty of debugging something inside WSL. However, now that this repo has properly been updated to LLVM 15, I gave it another shot, but I'm getting the same issue. When compiling the hello world pass example and loading it into a test program I get this error message:
To reproduce:
cargo init --bin
.cargo/config.toml
, under build.rustflags
, add an option -Zllvm-plugins=(PATH_TO_PASS)
and -Cpasses=hello-world
.Please let me know if you can reproduce it or if I'm doing something completely wrong. I'm gonna try to investigate a bit further, but I'm not experienced in working with rustc, so any help would be appreciated.
When running:
opt --load-pass-plugin=plugin5.dll --passes="mpass,function(fpass)" tests/test.ll -disable-output
Exception 0x80000003
is raised, and the program fails with status code C0000374
.
Call stack:
RtlIsZeroMemory (@RtlIsZeroMemory:62)
RtlpNtSetValueKey (@RtlpNtSetValueKey:355)
RtlpNtSetValueKey (@RtlpNtSetValueKey:567)
RtlpNtSetValueKey (@RtlpNtSetValueKey:7391)
RtlGetCurrentServiceSessionId (@RtlGetCurrentServiceSessionId:1274)
RtlFreeHeap (@RtlFreeHeap:24)
_free_base (@_free_base:10)
bool __cdecl llvm::runPassPipeline(class llvm::StringRef,class llvm::Module &,class llvm::TargetMachine *,class llvm::ToolOutputFile *,class llvm::ToolOutputFile *,class llvm::ToolOutputFile *,class llvm::StringRef,enum llvm::opt_tool::OutputKind,enum llvm::opt_tool::VerifierKind,bool,bool,bool,bool,bool) (d:\llvm-10.0.0.src\tools\opt\NewPMDriver.cpp:370)
main (d:\llvm-10.0.0.src\tools\opt\opt.cpp:707)
static int __scrt_common_main_seh() (@class llvm::ModulePass * llvm::createAMDGPUFixFunctionBitcastsPass(void):573419)
BaseThreadInitThunk (@BaseThreadInitThunk:9)
RtlUserThreadStart (@RtlUserThreadStart:12)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.