Arnamoy Bhattacharyya
2012-Jul-05 06:34 UTC
[LLVMdev] "symbol lookup error" while running a Simple Loop Pass
Hello; I wrote this simple loop pass to collect the number of instructions in each loop of the program. The code is as follows- #define DEBUG_TYPE "loopinst" #include "llvm/Pass.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Support/raw_ostream.h" #include "llvm/ADT/Statistic.h" #include "llvm/Instructions.h" #include "llvm/Analysis/LoopInfo.h" using namespace llvm; STATISTIC(LoopInstNum, "Counts number of instructions in a loop"); namespace { struct LoopInst : public LoopPass { static char ID; // Pass identification, replacement for typeid LoopInst() : LoopPass(ID) {} virtual bool runOnLoop(Loop *L, LPPassManager &LPM) { LoopInfo *LI = &getAnalysis<LoopInfo>(); for (Loop::block_iterator b = L->block_begin(), be = L->block_end();b !be; ++b) { for (BasicBlock::iterator i = (*b)->begin(), ie = (*b)->end(); i != ie; ++i) { ++LoopInstNum; errs() << "Hello: "; } } return false; } // We don't modify the program, so we preserve all analyses virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<LoopInfo>(); AU.addPreserved<LoopInfo>(); } }; } char LoopInst::ID = 0; static RegisterPass<LoopInst> X("loop-inst", "loop instruction Pass"); I put it under llvm-src/lib/Transforms directory and ran a "make" from there to create the .so file. But when I run opt with the library, I get the following error - opt -load=/home/arnie/llvm-development/llvm/Debug+Asserts/lib/LoopInst.so -loops -loop-inst a.s opt: symbol lookup error: /home/arnie/llvm-development/llvm/Debug+Asserts/lib/LoopInst.so: undefined symbol: _ZNK4llvm8LoopBaseINS_10BasicBlockENS_4LoopEE11block_beginEv Can anyone tell me what I am doing wrong? Also what's the difference between declaring a pass as a struct vs declaring it as a class. In the "writing a pass" tutorial the "Hello" pass has been declared as a struct but most (if not all) the LLVM passes are written as classes. Thanks a lot; -- Arnamoy Bhattacharyya Athabasca Hall 143 Department of Computing Science - University of Alberta Edmonton, Alberta, Canada, T6G 2E8 587-710-7073 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120705/ff65500b/attachment.html>
Carlos Sánchez de La Lama
2012-Jul-05 06:44 UTC
[LLVMdev] "symbol lookup error" while running a Simple Loop Pass
Hi, this is probably related to the reported bug: http://llvm.org/bugs/show_bug.cgi?id=13144 You have two possible solutions: 1) add KEEP_SYMBOLS := 1 to opt Makefile and recompile OR 2) used a shared build of LLVM BR Carlos PD: If you are uing OSX, the problem might be slightly more complex. Look at my mail which is linked at the end of the bug report. 2012/7/5 Arnamoy Bhattacharyya <arnamoy at ualberta.ca>:> Hello; > > I wrote this simple loop pass to collect the number of instructions in each > loop of the program. The code is as follows- > > #define DEBUG_TYPE "loopinst" > #include "llvm/Pass.h" > #include "llvm/Analysis/LoopPass.h" > #include "llvm/Support/raw_ostream.h" > #include "llvm/ADT/Statistic.h" > #include "llvm/Instructions.h" > #include "llvm/Analysis/LoopInfo.h" > > using namespace llvm; > > STATISTIC(LoopInstNum, "Counts number of instructions in a loop"); > > namespace { > struct LoopInst : public LoopPass { > static char ID; // Pass identification, replacement for typeid > LoopInst() : LoopPass(ID) {} > > virtual bool runOnLoop(Loop *L, LPPassManager &LPM) { > LoopInfo *LI = &getAnalysis<LoopInfo>(); > for (Loop::block_iterator b = L->block_begin(), be = L->block_end();b != be; > ++b) > { > for (BasicBlock::iterator i = (*b)->begin(), ie = (*b)->end(); i != ie; ++i) > { > ++LoopInstNum; > errs() << "Hello: "; > } > } > > return false; > } > > // We don't modify the program, so we preserve all analyses > virtual void getAnalysisUsage(AnalysisUsage &AU) const { > AU.addRequired<LoopInfo>(); > AU.addPreserved<LoopInfo>(); > } > }; > } > > char LoopInst::ID = 0; > static RegisterPass<LoopInst> X("loop-inst", "loop instruction Pass"); > > > I put it under llvm-src/lib/Transforms directory and ran a "make" from there > to create the .so file. But when I run opt with the library, I get the > following error - > > opt -load=/home/arnie/llvm-development/llvm/Debug+Asserts/lib/LoopInst.so > -loops -loop-inst a.s > > opt: symbol lookup error: > /home/arnie/llvm-development/llvm/Debug+Asserts/lib/LoopInst.so: undefined > symbol: _ZNK4llvm8LoopBaseINS_10BasicBlockENS_4LoopEE11block_beginEv > > Can anyone tell me what I am doing wrong? > > Also what's the difference between declaring a pass as a struct vs declaring > it as a class. In the "writing a pass" tutorial the "Hello" pass has been > declared as a struct but most (if not all) the LLVM passes are written as > classes. > > Thanks a lot; > -- > Arnamoy Bhattacharyya > Athabasca Hall 143 > Department of Computing Science - University of Alberta > Edmonton, Alberta, Canada, T6G 2E8 > 587-710-7073 > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Arnamoy Bhattacharyya
2012-Jul-05 18:47 UTC
[LLVMdev] "symbol lookup error" while running a Simple Loop Pass
Problem solved. I was building llvm in a separate llvm-build directory. I built it within the llvm-src directory (which kept all the llvm .so and my pass' .so in the llvm-src/Release+Asserts/lib directory) to solve the problem. Can anyone tell me what's the difference between writing a pass as a "struct" (as in the tutorial) and as a "class" (as most developers do)? Thanks again; ---------- Forwarded message ---------- From: Arnamoy Bhattacharyya <arnamoy at ualberta.ca> Date: Thu, Jul 5, 2012 at 12:34 AM Subject: "symbol lookup error" while running a Simple Loop Pass To: llvmdev at cs.uiuc.edu Hello; I wrote this simple loop pass to collect the number of instructions in each loop of the program. The code is as follows- #define DEBUG_TYPE "loopinst" #include "llvm/Pass.h" #include "llvm/Analysis/LoopPass.h" #include "llvm/Support/raw_ostream.h" #include "llvm/ADT/Statistic.h" #include "llvm/Instructions.h" #include "llvm/Analysis/LoopInfo.h" using namespace llvm; STATISTIC(LoopInstNum, "Counts number of instructions in a loop"); namespace { struct LoopInst : public LoopPass { static char ID; // Pass identification, replacement for typeid LoopInst() : LoopPass(ID) {} virtual bool runOnLoop(Loop *L, LPPassManager &LPM) { LoopInfo *LI = &getAnalysis<LoopInfo>(); for (Loop::block_iterator b = L->block_begin(), be = L->block_end();b !be; ++b) { for (BasicBlock::iterator i = (*b)->begin(), ie = (*b)->end(); i != ie; ++i) { ++LoopInstNum; errs() << "Hello: "; } } return false; } // We don't modify the program, so we preserve all analyses virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired<LoopInfo>(); AU.addPreserved<LoopInfo>(); } }; } char LoopInst::ID = 0; static RegisterPass<LoopInst> X("loop-inst", "loop instruction Pass"); I put it under llvm-src/lib/Transforms directory and ran a "make" from there to create the .so file. But when I run opt with the library, I get the following error - opt -load=/home/arnie/llvm-development/llvm/Debug+Asserts/lib/LoopInst.so -loops -loop-inst a.s opt: symbol lookup error: /home/arnie/llvm-development/llvm/Debug+Asserts/lib/LoopInst.so: undefined symbol: _ZNK4llvm8LoopBaseINS_10BasicBlockENS_4LoopEE11block_beginEv Can anyone tell me what I am doing wrong? Also what's the difference between declaring a pass as a struct vs declaring it as a class. In the "writing a pass" tutorial the "Hello" pass has been declared as a struct but most (if not all) the LLVM passes are written as classes. Thanks a lot; -- Arnamoy Bhattacharyya Athabasca Hall 143 Department of Computing Science - University of Alberta Edmonton, Alberta, Canada, T6G 2E8 587-710-7073 -- Arnamoy Bhattacharyya Athabasca Hall 143 Department of Computing Science - University of Alberta Edmonton, Alberta, Canada, T6G 2E8 587-710-7073 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120705/29a288ef/attachment.html>
Carlos Sánchez de La Lama
2012-Jul-05 21:00 UTC
[LLVMdev] "symbol lookup error" while running a Simple Loop Pass
Hi,> Problem solved. I was building llvm in a separate llvm-build directory. I > built it within the llvm-src directory (which kept all the llvm .so and my > pass' .so in the llvm-src/Release+Asserts/lib directory) to solve the > problem.I do not fully understand what you mean, there should be no difference on building out of source AFAIK.> Can anyone tell me what's the difference between writing a pass as a > "struct" (as in the tutorial) and as a "class" (as most developers do)?In C++, "class" is just an struct where members have private visibility by default. So defining a pass (or any class) with "struct" is 100% equivalent to defining it with "class" and then placing all members with "public:" visibility. From LLVM point of view, functionality of your pass is not going to change at all by using "class" or "struct" to define it. BR Carlos> ---------- Forwarded message ---------- > From: Arnamoy Bhattacharyya <arnamoy at ualberta.ca> > Date: Thu, Jul 5, 2012 at 12:34 AM > Subject: "symbol lookup error" while running a Simple Loop Pass > To: llvmdev at cs.uiuc.edu > > > Hello; > > I wrote this simple loop pass to collect the number of instructions in each > loop of the program. The code is as follows- > > #define DEBUG_TYPE "loopinst" > #include "llvm/Pass.h" > #include "llvm/Analysis/LoopPass.h" > #include "llvm/Support/raw_ostream.h" > #include "llvm/ADT/Statistic.h" > #include "llvm/Instructions.h" > #include "llvm/Analysis/LoopInfo.h" > > using namespace llvm; > > STATISTIC(LoopInstNum, "Counts number of instructions in a loop"); > > namespace { > struct LoopInst : public LoopPass { > static char ID; // Pass identification, replacement for typeid > LoopInst() : LoopPass(ID) {} > > virtual bool runOnLoop(Loop *L, LPPassManager &LPM) { > LoopInfo *LI = &getAnalysis<LoopInfo>(); > for (Loop::block_iterator b = L->block_begin(), be = L->block_end();b != be; > ++b) > { > for (BasicBlock::iterator i = (*b)->begin(), ie = (*b)->end(); i != ie; ++i) > { > ++LoopInstNum; > errs() << "Hello: "; > } > } > > return false; > } > > // We don't modify the program, so we preserve all analyses > virtual void getAnalysisUsage(AnalysisUsage &AU) const { > AU.addRequired<LoopInfo>(); > AU.addPreserved<LoopInfo>(); > } > }; > } > > char LoopInst::ID = 0; > static RegisterPass<LoopInst> X("loop-inst", "loop instruction Pass"); > > > I put it under llvm-src/lib/Transforms directory and ran a "make" from there > to create the .so file. But when I run opt with the library, I get the > following error - > > opt -load=/home/arnie/llvm-development/llvm/Debug+Asserts/lib/LoopInst.so > -loops -loop-inst a.s > > opt: symbol lookup error: > /home/arnie/llvm-development/llvm/Debug+Asserts/lib/LoopInst.so: undefined > symbol: _ZNK4llvm8LoopBaseINS_10BasicBlockENS_4LoopEE11block_beginEv > > Can anyone tell me what I am doing wrong? > > Also what's the difference between declaring a pass as a struct vs declaring > it as a class. In the "writing a pass" tutorial the "Hello" pass has been > declared as a struct but most (if not all) the LLVM passes are written as > classes. > > Thanks a lot; > -- > Arnamoy Bhattacharyya > Athabasca Hall 143 > Department of Computing Science - University of Alberta > Edmonton, Alberta, Canada, T6G 2E8 > 587-710-7073 > > > > -- > Arnamoy Bhattacharyya > Athabasca Hall 143 > Department of Computing Science - University of Alberta > Edmonton, Alberta, Canada, T6G 2E8 > 587-710-7073 > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
Maybe Matching Threads
- [LLVMdev] "symbol lookup error" while running a Simple Loop Pass
- [LLVMdev] "symbol lookup error" while running a Simple Loop Pass
- [LLVMdev] Error While Inserting New Instruction to LLVM IR
- [LLVMdev] llvm::ConstantArray::get(llvm::LLVMContext&, llvm::StringRef, bool) deprecated?
- [LLVMdev] Get the filename on which a pass is running?