Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample clang plugin crashes #7173

Closed
llvmbot opened this issue Apr 7, 2010 · 9 comments
Closed

sample clang plugin crashes #7173

llvmbot opened this issue Apr 7, 2010 · 9 comments
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category confirmed Verified by a second party

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Apr 7, 2010

Bugzilla Link 6801
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

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

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 8, 2010

This appears to be broken by r100249.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 8, 2010

This appears to be broken by r100249.

Ok, I'll take a look at this.

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 8, 2010

How do I build the example if I've built clang with objdir != srcdir?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 9, 2010

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 ()

@llvmbot
Copy link
Collaborator Author

llvmbot commented Apr 9, 2010

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?

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 27, 2010

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

@llvmbot
Copy link
Collaborator Author

llvmbot commented May 27, 2010

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.

@DougGregor
Copy link
Contributor

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.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
@llvmbot llvmbot added the confirmed Verified by a second party label Jan 26, 2022
@arsenm
Copy link
Contributor

arsenm commented Aug 16, 2023

Last comment indicates this was fixed, except for the since removed make build

@arsenm arsenm closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category confirmed Verified by a second party
Projects
None yet
Development

No branches or pull requests

3 participants