<div dir="ltr"><div><div><div>Hi all,<br><br></div>I'm trying to compile a clang plugin against a local ToT build of clang on OSX 10.10.  The link command fails like this:<br><br>$ /Users/ehsan/src/llvm-objdir/bin/clang++ -Qunused-arguments  -I/Users/ehsan/src/llvm/include -I/Users/ehsan/src/llvm-objdir/include  -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -std=c++11 -fcolor-diagnostics -O2 -g -DNDEBUG  -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -fno-rtti -fno-exceptions -fno-omit-frame-pointer  -fPIC -shared -o libclang-plugin.dylib  clang-plugin.o   -L/Users/ehsan/src/llvm-objdir/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lcurses -lpthread -lz -lm -L/Users/ehsan/src/llvm-objdir/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names -lLLVMOption -lLLVMBitReader -lLLVMMCParser -lLLVMAsmParser -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMCore -lLLVMSupport -lclangFrontend -lclangDriver -lclangSerialization -lclangParse -lclangSema -lclangAnalysis -lclangEdit -lclangAST -lclangLex -lclangBasic -lclangASTMatchers  -Wl,-executable_path,/Users/ehsan/moz/src/obj-ff-clang-plugin.noindex/dist/bin    -dynamiclib -install_name @executable_path/libclang-plugin.dylib -compatibility_version 1 -current_version 1 -single_module<br>Undefined symbols for architecture x86_64:<br>  "llvm::MemoryBuffer::getOpenFile(int, llvm::Twine const&, unsigned long long, bool, bool)", referenced from:<br>      (anonymous namespace)::RealFile::getBuffer(llvm::Twine const&, long long, bool, bool) in libclangBasic.a(VirtualFileSystem.cpp.o)<br>  "llvm::MemoryBuffer::getMemBufferCopy(llvm::StringRef, llvm::Twine const&)", referenced from:<br>      clang::Preprocessor::EnterMainSourceFile() in libclangLex.a(Preprocessor.cpp.o)<br>      clang::createChainedIncludesSource(clang::CompilerInstance&, llvm::IntrusiveRefCntPtr<clang::ExternalSemaSource>&) in libclangFrontend.a(ChainedIncludesSource.cpp.o)<br>      clang::ASTUnit::getMainBufferWithPrecompiledPreamble(clang::CompilerInvocation const&, bool, unsigned int) in libclangFrontend.a(ASTUnit.cpp.o)<br>      clang::GenerateModuleAction::BeginSourceFileAction(clang::CompilerInstance&, llvm::StringRef) in libclangFrontend.a(FrontendActions.cpp.o)<br>  "llvm::MemoryBuffer::getNewUninitMemBuffer(unsigned long, llvm::Twine const&)", referenced from:<br>      clang::Preprocessor::SetCodeCompletionPoint(clang::FileEntry const*, unsigned int, unsigned int) in libclangLex.a(Preprocessor.cpp.o)<br>  "llvm::MemoryBuffer::getFile(llvm::Twine const&, long long, bool, bool)", referenced from:<br>      clang::CompilerInvocation::getModuleHash() const in libclangFrontend.a(CompilerInvocation.cpp.o)<br>      clang::createVFSFromCompilerInvocation(clang::CompilerInvocation const&, clang::DiagnosticsEngine&) in libclangFrontend.a(CompilerInvocation.cpp.o)<br>      clang::GlobalModuleIndex::readIndex(llvm::StringRef) in libclangSerialization.a(GlobalModuleIndex.cpp.o)<br>      clang::PTHManager::Create(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, clang::DiagnosticsEngine&) in libclangLex.a(PTHLexer.cpp.o)<br>      clang::driver::toolchains::Linux::Linux(clang::driver::Driver const&, llvm::Triple const&, llvm::opt::ArgList const&) in libclangDriver.a(ToolChains.cpp.o)<br>  "llvm::sys::findProgramByName(llvm::StringRef, llvm::ArrayRef<llvm::StringRef>)", referenced from:<br>      clang::driver::Driver::GetProgramPath(char const*, clang::driver::ToolChain const&) const in libclangDriver.a(Driver.cpp.o)<br>  "llvm::scalbn(llvm::APFloat, int)", referenced from:<br>      (anonymous namespace)::ComplexExprEvaluator::VisitBinaryOperator(clang::BinaryOperator const*) in libclangAST.a(ExprConstant.cpp.o)<br>  "llvm::APInt::sshl_ov(llvm::APInt const&, bool&) const", referenced from:<br>      EvaluateDirectiveSubExpr((anonymous namespace)::PPValue&, unsigned int, clang::Token&, bool, clang::Preprocessor&) in libclangLex.a(PPExpressions.cpp.o)<br>  "llvm::APInt::ushl_ov(llvm::APInt const&, bool&) const", referenced from:<br>      EvaluateDirectiveSubExpr((anonymous namespace)::PPValue&, unsigned int, clang::Token&, bool, clang::Preprocessor&) in libclangLex.a(PPExpressions.cpp.o)<br>ld: symbol(s) not found for architecture x86_64<br>clang-3.5: error: linker command failed with exit code 1 (use -v to see invocation)<br><br></div>The missing symbols are all in libLLVMSupport.a, but libLLVMSupport.dylib (which is the library that ld tries to link against) misses all of these symbols because they are not referenced by anything and were eliminated during linking.<br><br>tools/driver/CMakeLists.txt in the clang repository sets LLVM_NO_DEAD_STRIP to 1 if CLANG_PLUGIN_SUPPORT is turned on, which it is in my build, but it seems like that setting does not affect libLLVMSupport, so we end up passing -dead_strip to the linker.  I'm not sure if this is the intended behavior, or a bug.<br><br></div>Do I understand the setup as intended correctly?  Can someone please suggest a way to bypass this issue?<br clear="all"><div><div><div><div><br></div><div>Thanks!<br></div><div>-- <br><div class="gmail_signature"><div dir="ltr">Ehsan<br></div></div>
</div></div></div></div></div>