From d11242a7d050f5ad5187a088768a269ccebcbd2e Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Fri, 24 Oct 2025 14:12:48 -0700 Subject: [PATCH 1/2] [lldb] Add function to tell if a section is a GOT section 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. --- lldb/include/lldb/Core/Section.h | 3 +++ lldb/include/lldb/Symbol/ObjectFile.h | 6 ++++++ lldb/source/Core/Section.cpp | 4 ++++ .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 14 ++++++++++++++ .../Plugins/ObjectFile/Mach-O/ObjectFileMachO.h | 2 ++ 5 files changed, 29 insertions(+) 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
, /// 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, 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 9cdb8467bfc60..05ed6038b8df6 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5922,6 +5922,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; + + bool is_data_const_got = + segment->GetName() == "__DATA_CONST" && section.GetName() == "__got"; + 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(); } From fa1ea6f010b2a52bccafa15902df4e2f0dc0b199 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Wed, 5 Nov 2025 12:57:03 -0800 Subject: [PATCH 2/2] Make bools const --- lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp index 05ed6038b8df6..1f62d79909d1e 100644 --- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp +++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp @@ -5928,9 +5928,9 @@ bool ObjectFileMachO::IsGOTSection(const lldb_private::Section §ion) const { if (!segment) return false; - bool is_data_const_got = + const bool is_data_const_got = segment->GetName() == "__DATA_CONST" && section.GetName() == "__got"; - bool is_auth_const_ptr = + 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;