We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
opt
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I've written the following empty MachineFunctionPass:
#include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/Passes/PassBuilder.h" #include "llvm/Passes/PassPlugin.h" #include "llvm/CodeGen/MachinePassManager.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/Support/raw_ostream.h" using namespace llvm; struct MyMachineFunctionPass : PassInfoMixin<MyMachineFunctionPass> { static StringRef name() { return "MyMachineFunctionPass"; } // Doing transformations here... PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &AM) { errs() << "Running MyMachineFunctionPass\n"; return PreservedAnalyses::none(); } /// (2) Optional initialization before any MachineFunction runs static Error doInitialization(Module &M, MachineFunctionAnalysisManager &AM) { errs() << "Initializing MyMachineFunctionPass on module: " << M.getName() << "\n"; return Error::success(); } /// (3) Optional finalization after all MachineFunctions have run static Error doFinalization(Module &M, MachineFunctionAnalysisManager &AM) { errs() << "Finalizing MyMachineFunctionPass on module: " << M.getName() << "\n"; return Error::success(); } /// (4) Fallback: runs on module if invoked incorrectly as an IR pass (shouldn't happen in proper use) static Error run(Module &M, MachineFunctionAnalysisManager &AM) { errs() << "WARNING: MyMachineFunctionPass called on Module — skipping\n"; return Error::success(); } }; extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo llvmGetPassPluginInfo() { errs() << "[+] Running llvmGetPassPluginInfo()\n"; return { LLVM_PLUGIN_API_VERSION, "MyMachineFunctionPass", LLVM_VERSION_STRING, [](PassBuilder &PB) { PB.registerPipelineParsingCallback( [](StringRef Name, MachineFunctionPassManager &MFPM, ArrayRef<PassBuilder::PipelineElement>) { errs() << "[+] Running registerPipelineParsingCallback()\n"; if (Name == "MyMachineFunctionPass") { errs() << " - Name is MyMachineFunctionPass\n"; MFPM.addPass(MyMachineFunctionPass()); return true; } return false; } ); } }; }
However, opt segfaults on compilation using this plugin:
root@5c9cdbf4bf7a:/tmp/workdir# clang -O0 -emit-llvm -c beacon/test.c -o builds/test.bc root@5c9cdbf4bf7a:/tmp/workdir# llc -O0 -stop-after=finalize-isel -march=x86-64 -o builds/test.mir builds/test.bc root@5c9cdbf4bf7a:/tmp/workdir# opt -load-pass-plugin=./transpiler/build/libMyMachineFunctionPass.so -passes=MyMachineFunctionPass -S ./builds/test.bc -o ./builds/test.ll [+] Running llvmGetPassPluginInfo() [+] Running registerPipelineParsingCallback() - Name is MyMachineFunctionPass [+] Running registerPipelineParsingCallback() - Name is MyMachineFunctionPass PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace. Stack dump: 0. Program arguments: opt -load-pass-plugin=./transpiler/build/libMyMachineFunctionPass.so -passes=MyMachineFunctionPass -S ./builds/test.bc -o ./builds/test.ll 1. Running pass "function(machine-function(MyMachineFunctionPass))" on module "./builds/test.bc" 2. Running pass "machine-function(MyMachineFunctionPass)" on function "main" #0 0x00007f2b019c7d46 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x1025d46) #1 0x00007f2b019c59d0 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x10239d0) #2 0x00007f2b019c83fb (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x10263fb) #3 0x00007f2b004dd050 (/lib/x86_64-linux-gnu/libc.so.6+0x3c050) #4 0x00007f2b01b57ffe llvm::AnalysisManager<llvm::Function>::getResultImpl(llvm::AnalysisKey*, llvm::Function&) (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x11b5ffe) #5 0x00007f2b01e0613e llvm::FunctionToMachineFunctionPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x146413e) #6 0x00007f2b03d7b80d (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x33d980d) #7 0x00007f2b01b55349 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x11b3349) #8 0x00007f2b03d6da1d (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x33cba1d) #9 0x00007f2b01b59306 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x11b7306) #10 0x00007f2b03d7765d (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x33d565d) #11 0x00007f2b01b54057 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/usr/lib/llvm-20/bin/../lib/libLLVM.so.20.1+0x11b2057) #12 0x000055d5e57d6b61 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/usr/lib/llvm-20/bin/opt+0x29b61) #13 0x000055d5e57cbc2e optMain (/usr/lib/llvm-20/bin/opt+0x1ec2e) #14 0x00007f2b004c824a (/lib/x86_64-linux-gnu/libc.so.6+0x2724a) #15 0x00007f2b004c8305 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x27305) #16 0x000055d5e57c60b1 _start (/usr/lib/llvm-20/bin/opt+0x190b1) Segmentation fault (core dumped)
I wonder if anyone could guide me in the right direction.
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I've written the following empty MachineFunctionPass:
However,
opt
segfaults on compilation using this plugin:I wonder if anyone could guide me in the right direction.
The text was updated successfully, but these errors were encountered: