<div dir="ltr">--<br><div class="gmail_extra"><div><div class="gmail_signature">Cristianno Martins<br>PhD Student of Computer Science<br>University of Campinas<br><a href="mailto:cmartins@ic.unicamp.br" target="_blank">cmartins@ic.unicamp.br</a><br><a href="mailto:cristiannomartins@hotmail.com" target="_blank"></a></div></div>
<br><div class="gmail_quote">On Wed, Feb 18, 2015 at 7:17 AM, Andrew Selvia <span dir="ltr"><<a href="mailto:andrew.selvia@icloud.com" target="_blank">andrew.selvia@icloud.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I want to create LLVM passes on OS X Yosemite. First, I built LLVM as such (based on <a href="http://llvm.org/docs/GettingStarted.html" target="_blank">http://llvm.org/docs/GettingStarted.html</a> and trial & error):<div><br></div><div>...<br><div><div>$ mkdir build && cd build</div><div>$ CC=clang CXX="clang++ -stdlib=libc++" ../llvm/configure --enable-libcpp --enable-shared</div><div>$ make</div><div>$ make install</div></div></div><div><br></div><div>Then, I tested it with the following command. It worked!</div><div><br></div><div>$ opt -load /usr/local/lib/LLVMHello.dylib -hello <test.bc>/dev/null</div><div><br></div><div>However, when attempting to build my own pass in OS X Yosemite, I ran into confusing linking problems:</div><div><br></div><div>$ c++ $(CXXFLAGS) SourceLineAnnotator.cpp -c -o SourceLineAnnotator.o</div><div>$ c++ SourceLineAnnotator.o -shared -o annotate.so</div><div><br></div><div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">Undefined symbols for architecture x86_64:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::ModulePass::assignPassManager(llvm::PMStack&, llvm::PassManagerType)", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::ModulePass::~ModulePass()", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      cs380c::SourceLineAnnotator::~SourceLineAnnotator() in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::raw_ostream::write(char const*, unsigned long)", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      llvm::raw_ostream::operator<<(llvm::StringRef) in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::raw_ostream::operator<<(unsigned long)", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      llvm::raw_ostream::operator<<(unsigned int) in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::PassRegistry::registerPass(llvm::PassInfo const&, bool)", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      llvm::RegisterPass<cs380c::SourceLineAnnotator>::RegisterPass(char const*, char const*, bool, bool) in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::PassRegistry::getPassRegistry()", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      llvm::RegisterPass<cs380c::SourceLineAnnotator>::RegisterPass(char const*, char const*, bool, bool) in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::AssemblyAnnotationWriter::~AssemblyAnnotationWriter()", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      SourceLineAssemblyAnnotationWriter::~SourceLineAssemblyAnnotationWriter() in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Pass::releaseMemory()", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Pass::dumpPassStructure(unsigned int)", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Pass::getAsImmutablePass()", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Pass::getAsPMDataManager()", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Pass::preparePassManager(llvm::PMStack&)", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Pass::getAdjustedAnalysisPointer(void const*)", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::outs()", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      cs380c::SourceLineAnnotator::runOnModule(llvm::Module&) in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::ModulePass::createPrinterPass(llvm::raw_ostream&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::ModulePass::getPotentialPassManagerType() const", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Instruction::getMetadataImpl(llvm::StringRef) const", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      llvm::Instruction::getMetadata(llvm::StringRef) const in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Pass::getPassName() const", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Pass::verifyAnalysis() const", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Pass::print(llvm::raw_ostream&, llvm::Module const*) const", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      vtable for cs380c::SourceLineAnnotator in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "llvm::Module::print(llvm::raw_ostream&, llvm::AssemblyAnnotationWriter*) const", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      cs380c::SourceLineAnnotator::runOnModule(llvm::Module&) in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "vtable for llvm::ModulePass", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      llvm::ModulePass::ModulePass(char&) in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "vtable for llvm::AssemblyAnnotationWriter", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      llvm::AssemblyAnnotationWriter::AssemblyAnnotationWriter() in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  "vtable for llvm::Pass", referenced from:</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">      llvm::Pass::Pass(llvm::PassKind, char&) in SourceLineAnnotator.o</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">ld: symbol(s) not found for architecture x86_64</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">clang: error: linker command failed with exit code 1 (use -v to see invocation)</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">make: *** [annotate.so] Error 1</div></div><div><br></div><div>Eventually, I discovered the .so file could be successfully compiled as follows:</div><div><br></div><div>$ c++ SourceLineAnnotator.o -shared `/usr/local/bin/llvm-config --ldflags --libs --system-libs` -o annotate.so</div><div><br></div><div>By adding the flags specified, I can now compile the pass to a .so file. However, when I attempt to load it with opt, I get another type of error (also related to linking from what I can tell):</div><div><br></div><div>$ opt -load annotate.so -annotate <test.bc>/dev/null</div><div><br></div><div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">opt: CommandLine Error: Option 'print-before-all' registered more than once!</div><div style="margin:0px;font-size:10px;font-family:Monaco;color:rgb(245,245,245);background-color:rgb(0,0,0)">LLVM ERROR: inconsistency in registered CommandLine options</div></div><div><br></div><div>I’m quite stuck. I have fought with linker errors for weeks now and I’m not sure what to try. Any help would be greatly appreciated.</div></div></blockquote><div><br></div><div>I've had a similar issue some time ago, and mine was related to the placement of the CommandLine option on my files. I assume "print-before-all" is a command line option you're trying to add to LLVM through your pass, right? It is probable that you declared that command inside a header file (this kind of error appears when you do that). Try moving the definition of print-before-all to a cpp file and compiling your pass again. That should fix it =)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><span class="HOEnZb"><font color="#888888"><div><br></div><div>Andrew Selvia</div></font></span></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>