[Lldb-commits] [lldb] [lldb] guard Module::GetSectionList with a mutex (PR #189007)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 27 07:26:14 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Charles Zablit (charles-zablit)
<details>
<summary>Changes</summary>
Without the lock, 2 threads could both build their own `SectionList`, and each call `m_sections_up = std::move(sections_up)`.
As a result, the thread that ran `ObjectFile::SetSectionLoadAddress` first registered its `SectionSP` objects. But the last thread to write `m_sections_up` wins, so `GetSectionList()->GetSectionAtIndex(0)` could return a `SectionSP` whose raw pointer was never registered in `SectionLoadList`. The lookup then returns `INVALID_ADDRESS`.
The mutex ensures that only one thread ever builds and assigns the `SectionList`. The thread that wins the lock also owns the `SectionSP` objects, so the pointers in `m_sections_up` and in `SectionLoadList` are always the same set.
---
Full diff: https://github.com/llvm/llvm-project/pull/189007.diff
1 Files Affected:
- (modified) lldb/source/Core/Module.cpp (+1)
``````````diff
diff --git a/lldb/source/Core/Module.cpp b/lldb/source/Core/Module.cpp
index aad23c0486805..6e690076fe0de 100644
--- a/lldb/source/Core/Module.cpp
+++ b/lldb/source/Core/Module.cpp
@@ -1225,6 +1225,7 @@ ObjectFile *Module::GetObjectFile() {
SectionList *Module::GetSectionList() {
// Populate m_sections_up with sections from objfile.
+ std::lock_guard<std::recursive_mutex> guard(m_mutex);
if (!m_sections_up) {
ObjectFile *obj_file = GetObjectFile();
if (obj_file != nullptr)
``````````
</details>
https://github.com/llvm/llvm-project/pull/189007
More information about the lldb-commits
mailing list