[Lldb-commits] [lldb] [lldb] guard Module::GetSectionList with a mutex (PR #189007)
Charles Zablit via lldb-commits
lldb-commits at lists.llvm.org
Fri Mar 27 07:25:34 PDT 2026
https://github.com/charles-zablit created https://github.com/llvm/llvm-project/pull/189007
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.
>From 0fddde9a4152c6b16396cfc3fe5ff0fceaf9edb9 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Fri, 27 Mar 2026 14:13:54 +0000
Subject: [PATCH] [lldb] guard Module::GetSectionList with a mutex
---
lldb/source/Core/Module.cpp | 1 +
1 file changed, 1 insertion(+)
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)
More information about the lldb-commits
mailing list