Remove the last improper use of getGlobalContext() from LLVM.

This caused a race condition where a thread calls ~LLVMContextImpl which calls
Module::dropAllReferences which calls begin() on an empty ilist that would
create the sentinel, which racily accesses the global context.

This can not be fixed by locking inside createSentinel because the lock would
need to be shared with all users of the global context, including those that
reside outside LLVM's own code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@137546 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nick Lewycky 2011-08-13 01:04:44 +00:00
parent 266246c0ed
commit 53b2b73643
2 changed files with 23 additions and 22 deletions

View File

@ -50,17 +50,35 @@ template<> struct ilist_traits<Function>
private: private:
mutable ilist_node<Function> Sentinel; mutable ilist_node<Function> Sentinel;
}; };
template<> struct ilist_traits<GlobalVariable> template<> struct ilist_traits<GlobalVariable>
: public SymbolTableListTraits<GlobalVariable, Module> { : public SymbolTableListTraits<GlobalVariable, Module> {
// createSentinel is used to create a node that marks the end of the list. // createSentinel is used to create a node that marks the end of the list.
static GlobalVariable *createSentinel(); GlobalVariable *createSentinel() const {
static void destroySentinel(GlobalVariable *GV) { delete GV; } return static_cast<GlobalVariable*>(&Sentinel);
}
static void destroySentinel(GlobalVariable*) {}
GlobalVariable *provideInitialHead() const { return createSentinel(); }
GlobalVariable *ensureHead(GlobalVariable*) const { return createSentinel(); }
static void noteHead(GlobalVariable*, GlobalVariable*) {}
private:
mutable ilist_node<GlobalVariable> Sentinel;
}; };
template<> struct ilist_traits<GlobalAlias> template<> struct ilist_traits<GlobalAlias>
: public SymbolTableListTraits<GlobalAlias, Module> { : public SymbolTableListTraits<GlobalAlias, Module> {
// createSentinel is used to create a node that marks the end of the list. // createSentinel is used to create a node that marks the end of the list.
static GlobalAlias *createSentinel(); GlobalAlias *createSentinel() const {
static void destroySentinel(GlobalAlias *GA) { delete GA; } return static_cast<GlobalAlias*>(&Sentinel);
}
static void destroySentinel(GlobalAlias*) {}
GlobalAlias *provideInitialHead() const { return createSentinel(); }
GlobalAlias *ensureHead(GlobalAlias*) const { return createSentinel(); }
static void noteHead(GlobalAlias*, GlobalAlias*) {}
private:
mutable ilist_node<GlobalAlias> Sentinel;
}; };
template<> struct ilist_traits<NamedMDNode> template<> struct ilist_traits<NamedMDNode>

View File

@ -32,25 +32,10 @@ using namespace llvm;
// Methods to implement the globals and functions lists. // Methods to implement the globals and functions lists.
// //
GlobalVariable *ilist_traits<GlobalVariable>::createSentinel() {
GlobalVariable *Ret = new GlobalVariable(Type::getInt32Ty(getGlobalContext()),
false, GlobalValue::ExternalLinkage);
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret);
return Ret;
}
GlobalAlias *ilist_traits<GlobalAlias>::createSentinel() {
GlobalAlias *Ret = new GlobalAlias(Type::getInt32Ty(getGlobalContext()),
GlobalValue::ExternalLinkage);
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret);
return Ret;
}
// Explicit instantiations of SymbolTableListTraits since some of the methods // Explicit instantiations of SymbolTableListTraits since some of the methods
// are not in the public header file. // are not in the public header file.
template class llvm::SymbolTableListTraits<GlobalVariable, Module>;
template class llvm::SymbolTableListTraits<Function, Module>; template class llvm::SymbolTableListTraits<Function, Module>;
template class llvm::SymbolTableListTraits<GlobalVariable, Module>;
template class llvm::SymbolTableListTraits<GlobalAlias, Module>; template class llvm::SymbolTableListTraits<GlobalAlias, Module>;
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@ -552,5 +537,3 @@ namespace {
void Module::findUsedStructTypes(std::vector<StructType*> &StructTypes) const { void Module::findUsedStructTypes(std::vector<StructType*> &StructTypes) const {
TypeFinder(StructTypes).run(*this); TypeFinder(StructTypes).run(*this);
} }