Open llvmbot opened 7 years ago
linking with -undefined dynamic_lookup
fixes the problem, but I don't understand why.
A quick-and-easy repro kit is available here:
https://www.dropbox.com/s/3yi1a42otk0tl0w/deleteme.tar.gz?dl=0
This has also been reproduced by someone else on 10.12.6 using the clang 5 package downloaded from the llvm download page
I grabbed the official 5.0 binary build for mac from the llvm website to try it.
After adding a dummy no-op implementation of
extern "C"
int futimens(int fd, const struct timespec times[2]) {
return 0;
}
to my plugin (because the clang 5 binary for mac is for 10.12 - I'm on 10.11 and 10.11 doesn't have that available in the OS), I got the same crash.
The same code with the llvm download page's binary build for mac for clang 4.0 - the above steps work fine.
I've written what I believe to be the simplest no-op plugin:
#include "clang/Frontend/FrontendPluginRegistry.h"
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "clang/Tooling/Tooling.h"
#include "clang/Rewrite/Core/Rewriter.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/AST/Comment.h"
#include "llvm/Support/raw_ostream.h"
using namespace clang;
using namespace clang::driver;
using namespace clang::tooling;
using namespace clang::comments;
/**
* Defines what will be matched and sent to
*/
class MyASTConsumer : public clang::ASTConsumer {
private:
public:
MyASTConsumer(CompilerInstance & CI){}
void HandleTranslationUnit(ASTContext & Context) override {
}
};
// This is the class that is registered with LLVM. PluginASTAction is-a ASTFrontEndAction
class PrintFunctionNamesAction : public clang::PluginASTAction {
public:
// open up output files
PrintFunctionNamesAction() {
}
// This is called when all parsing is done
void EndSourceFileAction(){}
protected:
// The value returned here is used internally to run checks against
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance & CI,
llvm::StringRef) {
return llvm::make_unique<MyASTConsumer>(CI);
}
public:
~PrintFunctionNamesAction()=default;
bool ParseArgs(const CompilerInstance & CI,
const std::vector<std::string> & args) {
return true;
}
void PrintHelp(llvm::raw_ostream & ros) {
}
};
static FrontendPluginRegistry::Add <PrintFunctionNamesAction>
X("noop_plugin", "noop plugin");
which I compile with:
$ CLANG_HOME/bin/clang++ \
-fno-rtti -O0 -g \
-I/usr/local/include \
-I$CLANG_HOME/include \
-fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual \
-Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor \
-Wdelete-non-virtual-dtor -Werror=date-time -std=c++11 -O3 -DNDEBUG -fno-rtti \
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \
noop_plugin.cpp \
`$CLANG_HOME/bin/llvm-config --ldflags --libs --system-libs` \
-dynamiclib -shared -o class_parser.dylib\
-std=c++14 \
\
\
-l LLVMAArch64AsmParser \
-l clangFrontend \
-L$CLANG_HOME/lib -Wl,-headerpad_max_install_names \
-lclangFrontend \
-lLLVMLTO -lclangSerialization -lclangASTMatchers -lclangSema -lclangAnalysis -lclangRewriteFrontend -lclangEdit \
-lclangParse -lclangFrontend -lclangBasic -lclangDriver -lclangAST -lclangLex -lLLVMObjCARCOpts -lLLVMSymbolize \
-lLLVMDebugInfoPDB -lLLVMDebugInfoDWARF -lLLVMXCoreDisassembler -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreInfo \
-lLLVMXCoreAsmPrinter -lLLVMSystemZDisassembler -lLLVMSystemZCodeGen -lLLVMSystemZAsmParser -lLLVMSystemZDesc \
-lLLVMSystemZInfo -lLLVMSystemZAsmPrinter -lLLVMSparcDisassembler -lLLVMSparcCodeGen -lLLVMSparcAsmParser \
-lLLVMSparcDesc -lLLVMSparcInfo -lLLVMSparcAsmPrinter -lLLVMPowerPCDisassembler -lLLVMPowerPCCodeGen \
-lLLVMPowerPCAsmParser -lLLVMPowerPCDesc -lLLVMPowerPCInfo -lLLVMPowerPCAsmPrinter -lLLVMNVPTXCodeGen \
-lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMNVPTXAsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info \
-lLLVMMSP430AsmPrinter -lLLVMMipsDisassembler -lLLVMMipsCodeGen -lLLVMMipsAsmParser -lLLVMMipsDesc -lLLVMMipsInfo \
-lLLVMMipsAsmPrinter -lLLVMHexagonDisassembler -lLLVMHexagonCodeGen -lLLVMHexagonAsmParser -lLLVMHexagonDesc \
-lLLVMHexagonInfo -lLLVMBPFCodeGen -lLLVMBPFDesc -lLLVMBPFInfo -lLLVMBPFAsmPrinter -lLLVMARMDisassembler \
-lLLVMARMCodeGen -lLLVMARMAsmParser -lLLVMARMDesc -lLLVMARMInfo -lLLVMARMAsmPrinter -lLLVMAMDGPUCodeGen \
-lLLVMAMDGPUAsmParser -lLLVMAMDGPUDesc -lLLVMAMDGPUUtils -lLLVMAMDGPUInfo -lLLVMAMDGPUAsmPrinter \
-lLLVMAArch64Disassembler -lLLVMAArch64CodeGen -lLLVMAArch64AsmParser -lLLVMAArch64Desc -lLLVMAArch64Info \
-lLLVMAArch64AsmPrinter -lLLVMAArch64Utils -lLLVMMIRParser -lLLVMLibDriver -lLLVMOption -lLLVMTableGen \
-lLLVMLineEditor -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter \
-lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMMCJIT -lLLVMPasses \
-lLLVMipo -lLLVMVectorize -lLLVMLinker -lLLVMIRReader -lLLVMAsmParser -lLLVMDebugInfoCodeView -lLLVMInterpreter \
-lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMBitWriter \
-lLLVMOrcJIT -lLLVMTransformUtils -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld \
-lLLVMObject -lLLVMMCParser -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lclangParse -lclangAST -lclangBasic -lclangParse\
-lclangParse \
-L/usr/local/lib \
-lcurses -lpthread -lm -lfmt
and then the program:
int main() {
float result = 1.0 * 1;
}
which I then run the plugin on as such:
clang++ source.cpp -std=c++17 -Xclang -load -Xclang ./class_parser.dylib -Xclang -plugin -Xclang noop_plugin
0 clang-5.0 0x0000000109d5a1f8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 clang-5.0 0x0000000109d5a7a6 SignalHandler(int) + 342
2 libsystem_platform.dylib 0x00007fff9917152a _sigtramp + 26
3 libsystem_platform.dylib 000000000000000000 _sigtramp + 1726540528
4 class_parser.dylib 0x000000010e1752f8 handleFloatFloatBinOp((anonymous namespace)::EvalInfo&, clang::Expr const*, llvm::APFloat&, clang::BinaryOperatorKind, llvm::APFloat const&) + 280
5 class_parser.dylib 0x000000010e17424f (anonymous namespace)::FloatExprEvaluator::VisitBinaryOperator(clang::BinaryOperator const*) + 703
6 class_parser.dylib 0x000000010e14b65c Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) + 796
7 class_parser.dylib 0x000000010e14770c EvaluateAsRValue((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::APValue&) + 92
8 class_parser.dylib 0x000000010e1474d8 clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&, clang::ASTContext const&) const + 376
9 class_parser.dylib 0x000000010d8cb8df (anonymous namespace)::CheckImplicitConversion(clang::Sema&, clang::Expr*, clang::QualType, clang::SourceLocation, bool*) + 927
10 class_parser.dylib 0x000000010d8c3af6 (anonymous namespace)::AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation) + 998
11 class_parser.dylib 0x000000010d8c48cb clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) + 139
12 class_parser.dylib 0x000000010db3a3c1 clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) + 289
13 class_parser.dylib 0x000000010d9732f1 clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) + 3937
14 class_parser.dylib 0x000000010de32a11 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) + 3713
15 class_parser.dylib 0x000000010de30087 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 2743
16 class_parser.dylib 0x000000010de2be33 clang::Parser::ParseSimpleDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool, clang::Parser::ForRangeInit*) + 723
17 class_parser.dylib 0x000000010de2b8e8 clang::Parser::ParseDeclaration(unsigned int, clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&) + 504
18 class_parser.dylib 0x000000010de9a03c clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) + 828
19 class_parser.dylib 0x000000010de99be4 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*) + 180
20 class_parser.dylib 0x000000010dea09d9 clang::Parser::ParseCompoundStatementBody(bool) + 1561
21 class_parser.dylib 0x000000010dea12c2 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) + 162
22 class_parser.dylib 0x000000010deb6a78 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) + 2616
23 class_parser.dylib 0x000000010de2ff84 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 2484
24 class_parser.dylib 0x000000010deb5e43 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) + 835
25 class_parser.dylib 0x000000010deb58c3 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) + 563
26 class_parser.dylib 0x000000010deb4597 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) + 2519
27 class_parser.dylib 0x000000010deb3459 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 633
28 class_parser.dylib 0x000000010deb30f5 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 37
29 class_parser.dylib 0x000000010de1e18f clang::ParseAST(clang::Sema&, bool, bool) + 351
30 clang-5.0 0x000000010a2dd813 clang::FrontendAction::Execute() + 67
31 clang-5.0 0x000000010a2824b8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1208
32 clang-5.0 0x000000010a321205 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 4597
33 clang-5.0 0x0000000108906929 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 1401
34 clang-5.0 0x0000000108904ab2 main + 11282
35 libdyld.dylib 0x00007fff8f0ae5ad start + 1
36 libdyld.dylib 0x000000000000003b start + 1895111311
Stack dump:
0. Program arguments: /Users/xaxxon/Downloads/clang+llvm-5.0.0/bin/clang-5.0 -cc1 -triple x86_64-apple-macosx10.11.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name source.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -faligned-alloc-unavailable -target-cpu core2 -target-linker-version 264.3.101 -dwarf-column-info -debugger-tuning=lldb -resource-dir /Users/xaxxon/Downloads/clang+llvm-5.0.0/lib/clang/5.0.0 -stdlib=libc++ -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /Users/xaxxon/deleteme -ferror-limit 19 -fmessage-length 168 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.11.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -load ./class_parser.dylib -plugin noop_plugin -o /var/folders/94/z1tx2t2n0dg2bx5lb315pwl80000gn/T/source-cba5bb.o -x c++ source.cpp
clang-5.0: error: unable to execute command: Segmentation fault: 11
clang-5.0: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Users/xaxxon/Downloads/clang+llvm-5.0.0/bin
clang-5.0: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang-5.0: error: unable to execute command: Segmentation fault: 11
clang-5.0: note: diagnostic msg: Error generating preprocessed source(s).
I have no DYLD_LIBRARY_PATH
set:
Zacs-MacBook-Air:deleteme xaxxon$ echo DYLD_LIBRARY_PATH
DYLD_LIBRARY_PATH
Zacs-MacBook-Air:deleteme xaxxon$ echo $DYLD_LIBRARY_PATH
Zacs-MacBook-Air:deleteme xaxxon$
and my clang is coming from my custom built clang, as described above. (yes I put it in a dir called Downloads even though I didn't download it)
Zacs-MacBook-Air:deleteme xaxxon$ which clang++
/Users/xaxxon/Downloads/clang+llvm-5.0.0/bin/clang++
it takes me 6 hours to compile clang, so building bleeding edge is quite painful for me, so I haven't tried to see if it's fixed past the final version of 5.0.0
This is on a 2011 macbook air running OS X 10.11.6 and a version of clang 5 I compiled from
./utils/release/test-release.sh -release 5.0.0 -final -triple x86_64-apple-darwin15.6.0
Extended Description
When I try to run my clang plugin on my real codebase, it crashes. I can compile the code without the plugin and I can run the plugin on some (much) simpler code.
I started trimming my "real" code back to try to find the problem and eventually got found a line that when present crashed the program, but when changed, did not (code slightly simplified from original):
If you remove the "* 1" the code compiles and my plugin works fine.