Build the PrintFunctionNames sample plugin in tools/clang/examples/PrintFunctionNames/, then run: $ clang -cc1 -load path/to/PrintFunctionNames.so -plugin print-fns t.cc where t.cc has content: int f() { return 1; } and clang will crash: Two passes with the same argument (-preverify) attempted to be registered! UNREACHABLE executed at include/llvm/Support/PassNameParser.h:74! 0 clang 0x00000000012975ce 1 clang 0x00000000012974b5 2 libpthread.so.0 0x00007f9a507e3580 3 libc.so.6 0x00007f9a4ff98da5 gsignal + 53 4 libc.so.6 0x00007f9a4ff9a750 abort + 272 5 clang 0x00000000012bd928 llvm::FoldingSetNodeID::AddPointer(void const*) + 0 6 clang 0x0000000001213bb1 llvm::PassNameParser::passRegistered(llvm::PassInfo const*) + 229 7 clang 0x0000000001211c36 llvm::PassInfo::registerPass() + 140 8 clang 0x0000000000aecde3 llvm::PassInfo::PassInfo(char const*, char const*, long, llvm::Pass* (*)(), bool, bool) + 145 9 PrintFunctionNames.so 0x00007f9a4ef3b965 10 PrintFunctionNames.so 0x00007f9a4ef3c99a 11 PrintFunctionNames.so 0x00007f9a4ef3cb19 12 PrintFunctionNames.so 0x00007f9a4ef9ae36 Stack dump: 0. Program arguments: clang -cc1 -load path/to/PrintFunctionNames.so -plugin print-fns t.cc Aborted
This appears to be broken by r100249.
(In reply to comment #1) > This appears to be broken by r100249. Ok, I'll take a look at this.
How do I build the example if I've built clang with objdir != srcdir?
You can turn on the CLANG_BUILD_EXAMPLES cmake option to build the clang examples: from tools/clang/CMakeLists.txt: option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF) if(CLANG_BUILD_EXAMPLES) add_subdirectory(examples) endif ()
(In reply to comment #4) > You can turn on the CLANG_BUILD_EXAMPLES cmake option to build the clang > examples: > > from tools/clang/CMakeLists.txt: > > option(CLANG_BUILD_EXAMPLES "Build CLANG example programs." OFF) > if(CLANG_BUILD_EXAMPLES) > add_subdirectory(examples) > endif () How do I do this with the non-cmake build?
The problem is that the static registrators are statically linked into both llvm itself and the plugin... when you load the plugin the options collide as they're registered for the second time. Just don't link to all those libs: Index: CMakeLists.txt =================================================================== --- CMakeLists.txt (revision 104780) +++ CMakeLists.txt (working copy) @@ -2,23 +2,6 @@ set(LLVM_NO_RTTI 1) -set(LLVM_USED_LIBS - clangIndex - clangFrontend - clangDriver - clangSema - clangAnalysis - clangAST - clangParse - clangLex - clangBasic) - -set( LLVM_LINK_COMPONENTS - bitreader - mc - core - ) - add_clang_library(PrintFunctionNames PrintFunctionNames.cpp) set_target_properties(PrintFunctionNames
(In reply to comment #6) > The problem is that the static registrators are statically linked into both > llvm itself and the plugin... when you load the plugin the options collide as > they're registered for the second time. Just don't link to all those libs: > Oh, also you want set_target_properties(PrintFunctionNames PROPERTIES LINKER_LANGUAGE CXX PREFIX "") (note the PREFIX bit) so that PrintFunctionNames.so, not libPrintFunctionNames.so gets built... this way it matches the docs.
I've committed Troy's fixes for the CMake build system here: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20100607/031065.html along with tweaks to make it work properly on Darwin. These changes still need to be replicated in the make-based build system.