[LLVMdev] How to use the llvm::Linker?

Duncan Sands baldrick at free.fr
Fri Mar 29 03:03:43 PDT 2013


Hi,

On 29/03/13 09:22, xiaoyaollvm wrote:
> Hi,All
> this one pass that will use the Linker
> namespace {
>    // Hello2 - The second implementation with getAnalysisUsage implemented.
>    llvm::StringRef programNametest("");
>    struct Hello2 : public ModulePass {
>      static char ID; // Pass identification, replacement for typeid
>      Hello2() : ModulePass(ID) {}
>
>      virtual bool runOnModule(llvm::Module &M){
>        llvm::Linker *linkertest = new llvm::Linker(programNametest,&M);
>        llvm::errs() << linkertest->getModule();
>        ++HelloCounter;
>        errs() << "Hello: ";
>        return false;
>      }
>
>      // We don't modify the program, so we preserve all analyses
>      virtual void getAnalysisUsage(AnalysisUsage &AU) const {
>        AU.setPreservesAll();
>      }
>    };
> }
>
> char Hello2::ID = 0;
> static RegisterPass<Hello2>
> Y1("hello2", "Hello World Pass (with getAnalysisUsage implemented)");
>
> But ,when i run the  pass with opt, there will be a Error:
> ./bin/opt: symbol lookup error: ./lib/Hello.so: undefined symbol:
> _ZN4llvm6Linker11LinkModulesEPNS_6ModuleES2_jPSs
> by the c++filt, the function name is :
> llvm::Linker::LinkModules(llvm::Module*, llvm::Module*, unsigned int,
> std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)
> So I think, may I should  Modify the cmake, I want to know how to modify the
> files of  cmake, so that i can complier the pass with Linker.

since "opt" itself doesn't do any linking, it isn't linked with the linker
library (-lLLVMLinker), which is where the LinkModules code lives.  So you will
have to link your plugin with libLLVMLinker in order to get the LinkModules
code.

Ciao, Duncan.



More information about the llvm-dev mailing list