Esther Goh
Esther Goh

Reputation: 322

LLVM Adding a pass - linking error

I have written my pass in llvm/lib/Transforms, and its called createABCDPass. I have added the following code in my pass:

namespace llvm { FunctionPass *createABCDPass(); }
FunctionPass *llvm::createABCDPass() { return new AbcRemoval(); }

where AbcRemoval is the class of the pass.

After that, I have done a forward declaration in lib/CodeGen/LLVMTargetMachine.cpp in order to recognize my pass:

namespace llvm { FunctionPass *createABCDPass(); }
PM.add(createABCDPass());

However, when I run make on llvm, i get the following error:

llvm[2]: Linking Release executable llc (without symbols)
Undefined symbols:
  "llvm::createABCDPass()", referenced from:
      llvm::LLVMTargetMachine::addCommonCodeGenPasses(llvm::PassManagerBase&, llvm::CodeGenOpt::Level, bool, llvm::MCContext*&)in libLLVMCodeGen.a(LLVMTargetMachine.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [/Users/.../llvm/Release/bin/llc] Error 1
make[1]: *** [llc/.makeall] Error 2
make: *** [all] Error 1

Does anybody know why am I getting this error? Thanks!

Upvotes: 2

Views: 853

Answers (2)

Esther Goh
Esther Goh

Reputation: 322

Ah, I fixed it in the end by renaming the pass module to -libLLVM_xxx. Apparently you got to name it libLLVM_"something" in order for it to run with all the other passes in LLVM dynamically. Not sure why, but it works!

Upvotes: 3

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

You have to link your pass to llc. By default llc pulls almost nothing from lib/Transforms, so your pass won't be linked in to llc.

Upvotes: 2

Related Questions