llvm-project
17e4140e - [lldb] Make TypeSystem::m_sym_file atomic to fix data race (#198923)

Commit
7 days ago
[lldb] Make TypeSystem::m_sym_file atomic to fix data race (#198923) SymbolFileCommon::GetTypeSystemForLanguage unconditionally writes this pointer with `ts->SetSymbolFile(this)` on every lookup, which races with concurrent reads from other threads. The race is benign in practice: there is exactly one SymbolFile per Module, so every writer stores the same pointer, but it is still undefined behavior under the C++ memory model. Make the field std::atomic<SymbolFile *> and turn SetSymbolFile into a compare-exchange that asserts a TypeSystem is never rebound to a different SymbolFile, documenting the invariant that lets us get away with this. The alternative is to have the SymbolFile pointer passed in through the constructor, but that would require updating a bunch of call sites, including various plugin interfaces. Found by ThreadSanitizer as part of #197792.
Author
Parents
Loading