Hi, I'm writing my first hello world Pass with the class name First, but when I tried to load it using opt, I got the following error: /var/soft/llvm-2.2-build/lib/Transforms/Hello$ opt -load ../../../Debug/lib/First.so --help opt: /var/soft/llvm-2.2/lib/VMCore/Pass.cpp:157: void<unnamed>::PassRegistrar::RegisterPass(llvm::PassInfo&): Assertion `Inserted && "Pass registered multiple times!"' failed. Aborted The code is as follows. #include "llvm/Pass.h" #include "llvm/Function.h" using namespace llvm; namespace { struct First : public FunctionPass { static char ID; First(): FunctionPass((intptr_t)&ID) {} virtual bool runOnFunction(Function &F) { llvm::cerr << "First: " << F.getName() << "\n"; return false; } }; char First::ID = 0; RegisterPass<First> X("first", "First world pass"); } and the Makefile: LEVEL = ../../.. LIBRARYNAME = First LOADABLE_MODULE = 1 LLVMLIBS = LLVMCore.a LLVMSupport.a LLVMSystem.a include $(LEVEL)/Makefile.common Thanks in advance. Lu
Lu Zhao wrote:> It turned out to be the problem of this line in Makefile > > LLVMLIBS = LLVMCore.a LLVMSupport.a LLVMSystem.a > > The error is gone when I remove the above line. > > However, the pass output only contains one line of the main function. > > First: main > > It does not have puts and __main as shown in this page: > http://llvm.org/docs/WritingAnLLVMPass.html#running > > So I guess the drived FunctionPass only works on the application > functions, not on the library functions of LLVM. Is that right? >LLVM does not distinguish between application and library functions, unless you mean that it distinguishes between defined functions and functions defined in another module. It's possible that runOnFunction() is not called for functions with no function body (aka external declarations or external functions). If you disassemble your input bytecode file and look at the LLVM disassembly, I'd bet that either __main() and puts are external functions with no function body or are not present in the file at all. -- John T.> Thanks. > Lu > > On Mon, 31 Mar 2008 00:47:26 -0600 > Lu Zhao <luzhao at cs.utah.edu> wrote: > >
It turned out to be the problem of this line in Makefile LLVMLIBS = LLVMCore.a LLVMSupport.a LLVMSystem.a The error is gone when I remove the above line. However, the pass output only contains one line of the main function. First: main It does not have puts and __main as shown in this page: http://llvm.org/docs/WritingAnLLVMPass.html#running So I guess the drived FunctionPass only works on the application functions, not on the library functions of LLVM. Is that right? Thanks. Lu On Mon, 31 Mar 2008 00:47:26 -0600 Lu Zhao <luzhao at cs.utah.edu> wrote:> Hi, > > I'm writing my first hello world Pass with the class name First, but > when I tried to load it using opt, I got the following error: > > /var/soft/llvm-2.2-build/lib/Transforms/Hello$ opt > -load ../../../Debug/lib/First.so --help > opt: /var/soft/llvm-2.2/lib/VMCore/Pass.cpp:157: > void<unnamed>::PassRegistrar::RegisterPass(llvm::PassInfo&): Assertion > `Inserted && "Pass registered multiple times!"' failed. > Aborted > > The code is as follows. > > #include "llvm/Pass.h" > #include "llvm/Function.h" > > using namespace llvm; > > namespace { > struct First : public FunctionPass { > static char ID; > First(): FunctionPass((intptr_t)&ID) {} > > virtual bool runOnFunction(Function &F) > { > llvm::cerr << "First: " << F.getName() << "\n"; > return false; > } > }; > > > char First::ID = 0; > RegisterPass<First> X("first", "First world pass"); > } > > and the Makefile: > > LEVEL = ../../.. > LIBRARYNAME = First > LOADABLE_MODULE = 1 > LLVMLIBS = LLVMCore.a LLVMSupport.a LLVMSystem.a > include $(LEVEL)/Makefile.common > > Thanks in advance. > Lu > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev