[lldb] Fix data race in ObjectFile::GetSectionList (#197812)
The early `m_sections_up == nullptr` check was performed outside the module mutex, so two threads sharing the same Module could both enter the branch and race on the write in CreateSections. Restructure so the check and populate both happen under the module mutex; this is a standard double-checked locking fix. Found by ThreadSanitizer as part of #197792.
This commit is contained in:
1 parent
cc3f8adc7e
commit
a0176fd9df
2 files changed
+13
-10
No files matched your search
@@ -771,7 +771,10 @@ protected:
|
||||
lldb::ProcessWP m_process_wp;
|
||||
/// Set if the object file only exists in memory.
|
||||
const lldb::addr_t m_memory_addr;
|
||||
|
||||
std::unique_ptr<lldb_private::SectionList> m_sections_up;
|
||||
std::recursive_mutex m_sections_mutex;
|
||||
|
||||
std::unique_ptr<lldb_private::Symtab> m_symtab_up;
|
||||
/// We need a llvm::once_flag that we can use to avoid locking the module
|
||||
/// lock and deadlocking LLDB. See comments in ObjectFile::GetSymtab() for
|
||||
|
||||
@@ -603,17 +603,17 @@ void ObjectFile::ClearSymtab() {
|
||||
}
|
||||
|
||||
SectionList *ObjectFile::GetSectionList(bool update_module_section_list) {
|
||||
if (m_sections_up == nullptr) {
|
||||
if (update_module_section_list) {
|
||||
ModuleSP module_sp(GetModule());
|
||||
if (module_sp) {
|
||||
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
|
||||
CreateSections(*module_sp->GetUnifiedSectionList());
|
||||
}
|
||||
} else {
|
||||
SectionList unified_section_list;
|
||||
CreateSections(unified_section_list);
|
||||
std::lock_guard<std::recursive_mutex> guard(m_sections_mutex);
|
||||
if (m_sections_up)
|
||||
return m_sections_up.get();
|
||||
if (update_module_section_list) {
|
||||
if (ModuleSP module_sp = GetModule()) {
|
||||
std::lock_guard<std::recursive_mutex> guard(module_sp->GetMutex());
|
||||
CreateSections(*module_sp->GetUnifiedSectionList());
|
||||
}
|
||||
} else {
|
||||
SectionList unified_section_list;
|
||||
CreateSections(unified_section_list);
|
||||
}
|
||||
return m_sections_up.get();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user