LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 6801 - sample clang plugin crashes
Summary: sample clang plugin crashes
Status: CONFIRMED
Alias: None
Product: clang
Classification: Unclassified
Component: -New Bugs (show other bugs)
Version: trunk
Hardware: All Linux
: P normal
Assignee: David Greene
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-04-06 19:02 PDT by Zhanyong Wan
Modified: 2017-09-15 10:00 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zhanyong Wan 2010-04-06 19:02:18 PDT
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
Comment 1 Zhanyong Wan 2010-04-07 18:27:57 PDT
This appears to be broken by r100249.
Comment 2 David Greene 2010-04-08 10:00:55 PDT
(In reply to comment #1)
> This appears to be broken by r100249.

Ok, I'll take a look at this.
Comment 3 David Greene 2010-04-08 13:22:36 PDT
How do I build the example if I've built clang with objdir != srcdir?
Comment 4 Zhanyong Wan 2010-04-08 19:45:05 PDT
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 ()
Comment 5 David Greene 2010-04-09 13:48:57 PDT
(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?
Comment 6 Troy D. Straszheim 2010-05-26 19:33:22 PDT
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
Comment 7 Troy D. Straszheim 2010-05-26 19:37:55 PDT
(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.
Comment 8 Douglas Gregor 2010-06-08 14:26:02 PDT
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.