[Lldb-commits] [lldb] aa1b1dc - [lldb] Add function to tell if a section is a GOT section (#165936)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 6 12:52:08 PST 2025
Author: Augusto Noronha
Date: 2025-11-06T12:52:04-08:00
New Revision: aa1b1dc3914df84581e92fa75e6b8ff7007e0295
URL: https://github.com/llvm/llvm-project/commit/aa1b1dc3914df84581e92fa75e6b8ff7007e0295
DIFF: https://github.com/llvm/llvm-project/commit/aa1b1dc3914df84581e92fa75e6b8ff7007e0295.diff
LOG: [lldb] Add function to tell if a section is a GOT section (#165936)
A global offset table is a section that holds the address of functions
that are dynamically linked. The Swift plugin needs to know if sections
are a global offset table or not.
Added:
Modified:
lldb/include/lldb/Core/Section.h
lldb/include/lldb/Symbol/ObjectFile.h
lldb/source/Core/Section.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
Removed:
################################################################################
diff --git a/lldb/include/lldb/Core/Section.h b/lldb/include/lldb/Core/Section.h
index f0f5a0b3499c0..d0f10cc342780 100644
--- a/lldb/include/lldb/Core/Section.h
+++ b/lldb/include/lldb/Core/Section.h
@@ -273,6 +273,9 @@ class Section : public std::enable_shared_from_this<Section>,
/// return true.
bool ContainsOnlyDebugInfo() const;
+ /// Returns true if this is a global offset table section.
+ bool IsGOTSection() const;
+
protected:
ObjectFile *m_obj_file; // The object file that data for this section should
// be read from
diff --git a/lldb/include/lldb/Symbol/ObjectFile.h b/lldb/include/lldb/Symbol/ObjectFile.h
index 1b9ae1fb31a69..1de08a8576507 100644
--- a/lldb/include/lldb/Symbol/ObjectFile.h
+++ b/lldb/include/lldb/Symbol/ObjectFile.h
@@ -758,6 +758,12 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
return false;
}
+ /// Returns true if the section is a global offset table section.
+ virtual bool IsGOTSection(const lldb_private::Section §ion) const {
+ assert(section.GetObjectFile() == this && "Wrong object file!");
+ return false;
+ }
+
/// Get a hash that can be used for caching object file releated information.
///
/// Data for object files can be cached between runs of debug sessions and
diff --git a/lldb/source/Core/Section.cpp b/lldb/source/Core/Section.cpp
index 02d9d86fe5374..d3f753e53b7fa 100644
--- a/lldb/source/Core/Section.cpp
+++ b/lldb/source/Core/Section.cpp
@@ -471,6 +471,10 @@ bool Section::ContainsOnlyDebugInfo() const {
return false;
}
+bool Section::IsGOTSection() const {
+ return GetObjectFile()->IsGOTSection(*this);
+}
+
#pragma mark SectionList
SectionList &SectionList::operator=(const SectionList &rhs) {
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index c8e520d687f67..2218c23db5a95 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -5936,6 +5936,20 @@ Section *ObjectFileMachO::GetMachHeaderSection() {
return nullptr;
}
+bool ObjectFileMachO::IsGOTSection(const lldb_private::Section §ion) const {
+ assert(section.GetObjectFile() == this && "Wrong object file!");
+ SectionSP segment = section.GetParent();
+ if (!segment)
+ return false;
+
+ const bool is_data_const_got =
+ segment->GetName() == "__DATA_CONST" && section.GetName() == "__got";
+ const bool is_auth_const_ptr =
+ segment->GetName() == "__AUTH_CONST" &&
+ (section.GetName() == "__auth_got" || section.GetName() == "__auth_ptr");
+ return is_data_const_got || is_auth_const_ptr;
+}
+
bool ObjectFileMachO::SectionIsLoadable(const Section *section) {
if (!section)
return false;
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
index 25643aacb3d2d..5456f0315c942 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h
@@ -162,6 +162,8 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
lldb_private::Section *GetMachHeaderSection();
+ bool IsGOTSection(const lldb_private::Section §ion) const override;
+
// PluginInterface protocol
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
More information about the lldb-commits
mailing list