Hi,

I use LLVM (3.2) in my project (Qt 5.0.0) and it works as expected on Windows and OS X, but on Ubuntu it just crashes. If I start my application, don't use any of the LLVM-specific stuff in my application, and try to quit my application, then I get the following debug traces:

Qt Code:
  1. 0 __memmove_ssse3 memcpy-ssse3.S 1682 0x1348f8c
  2. 1 llvm::PassRegistry::removeRegistrationListener(llvm::PassRegistrationListener*) /usr/lib/i386-linux-gnu/libLLVM-3.0.so.1 0xb0278ddb
  3. 2 llvm::PassRegistrationListener::~PassRegistrationListener() /usr/lib/i386-linux-gnu/libLLVM-3.0.so.1 0xb026aa06
  4. 3 llvm::PassNameParser::~PassNameParser() /usr/lib/i386-linux-gnu/libLLVM-3.0.so.1 0xb026aca2
  5. 4 llvm::cl::list<llvm::PassInfo const*, bool, llvm::PassNameParser>::~list() /home/me/myApp/build/plugins/myApp/libLLVM.so 0xb31eb8a4
  6. 5 __run_exit_handlers exit.c 78 0x1242f51
  7. 6 __GI_exit exit.c 100 0x1242fdd
  8. 7 __libc_start_main libc-start.c 258 0x12294db
  9. 8 _start 0x8068ca1
To copy to clipboard, switch view to plain text mode 
If you look at line 4, my application uses my version of LLVM (which I build as a Qt plugin), but then at lines 1, 2 and 3, we can see that my application somehow decided to use the system version of LLVM. Why is that? I have no idea!

All I know is that it used to work perfectly fine using Qt 4.8.x. I thought for a moment that it might be related to OpenGL/3D (Qt 5.0.0 uses OpenGL no matter what now, right?), especially since my Ubuntu box is in fact a virtual machine with no 3D acceleration (i.e. Mesa would take over and use llvmpipe?), but I then tried using the Ubuntu live CD (with 3D acceleration), and I got the same result, so I am puzzled...

Otherwise, if I manually rename the system version of LLVM (so that my application cannot 'see' it), then everything works as expected (i.e. no crash) but I obviously don't want and, in fact, can't really do that!

FWIW, here is another trace I get when starting my application and then trying to do some LLVM-specific stuff in my application:

Qt Code:
  1. 0 llvm::FoldingSetNodeID::AddPointer(void const*) /usr/lib/i386-linux-gnu/libLLVM-3.0.so.1 0xb074f37a
  2. 1 clang::FunctionProtoType::Profile(llvm::FoldingSetNodeID&, clang::QualType, clang::QualType const*, unsigned int, clang::FunctionProtoType::ExtProtoInfo const&, clang::ASTContext const&) /home/me/myApp/build/libLLVM.so 0x43a6b2e
  3. 2 clang::FunctionProtoType::Profile(llvm::FoldingSetNodeID&, clang::ASTContext const&) /home/me/myApp/build/libLLVM.so 0x43a6dd4
  4. 3 llvm::ContextualFoldingSet<clang::FunctionProtoType, clang::ASTContext&>::NodeEquals(llvm::FoldingSetImpl::Node*, llvm::FoldingSetNodeID const&, unsigned int, llvm::FoldingSetNodeID&) const /home/me/myApp/build/libLLVM.so 0x427d59f
  5. 4 llvm::FoldingSetImpl::FindNodeOrInsertPos(llvm::FoldingSetNodeID const&, void*&) /usr/lib/i386-linux-gnu/libLLVM-3.0.so.1 0xb074fb67
  6. 5 clang::ASTContext::getFunctionType(clang::QualType, clang::QualType const*, unsigned int, clang::FunctionProtoType::ExtProtoInfo const&) const /home/me/myApp/build/libLLVM.so 0x426ecbb
  7. 6 clang::ASTContext::GetBuiltinType(unsigned int, clang::ASTContext::GetBuiltinTypeError&, unsigned int*) const /home/me/myApp/build/libLLVM.so 0x4274243
  8. 7 clang::Sema::LazilyCreateBuiltin(clang::IdentifierInfo*, unsigned int, clang::Scope*, bool, clang::SourceLocation) /home/me/myApp/build/libLLVM.so 0x48baa24
  9. 8 ?? /home/me/myApp/build/libLLVM.so 0x49fde04
  10. 9 clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool) /home/me/myApp/build/libLLVM.so 0x4a03d13
  11. 10 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) /home/me/myApp/build/libLLVM.so 0x48cb270
  12. 11 clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) /home/me/myApp/build/libLLVM.so 0x48cb8f3
  13. 12 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&) /home/me/myApp/build/libLLVM.so 0x47196e1
  14. 13 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, bool, clang::SourceLocation*, clang::Parser::ForRangeInit*) /home/me/myApp/build/libLLVM.so 0x4725883
  15. 14 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /home/me/myApp/build/libLLVM.so 0x477563f
  16. 15 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /home/me/myApp/build/libLLVM.so 0x4775d79
  17. 16 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) /home/me/myApp/build/libLLVM.so 0x4779c77
  18. 17 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) /home/me/myApp/build/libLLVM.so 0x4779f48
  19. 18 clang::ParseAST(clang::Sema&, bool, bool) /home/me/myApp/build/libLLVM.so 0x470e49c
  20. 19 clang::ASTFrontendAction::ExecuteAction() /home/me/myApp/build/libLLVM.so 0x4671a57
  21. 20 clang::CodeGenAction::ExecuteAction() /home/me/myApp/build/libLLVM.so 0x456db42
  22. ... <More>
To copy to clipboard, switch view to plain text mode 
Again, you can see that sometimes my application uses its version of LLVM while, at other times, it uses the system version of LLVM...!?

Now, I wouldn't expect many people to use LLVM in their project, but... how would you go about handling the case where your application uses its version of a library which is also used by your Linux system?...

Cheers, Alan.