Skip to content

Commit c4fa274

Browse files
augusto2112github-actions[bot]
authored andcommitted
Automerge: [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.
2 parents 32067e2 + aa1b1dc commit c4fa274

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

lldb/include/lldb/Core/Section.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ class Section : public std::enable_shared_from_this<Section>,
273273
/// return true.
274274
bool ContainsOnlyDebugInfo() const;
275275

276+
/// Returns true if this is a global offset table section.
277+
bool IsGOTSection() const;
278+
276279
protected:
277280
ObjectFile *m_obj_file; // The object file that data for this section should
278281
// be read from

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,12 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
758758
return false;
759759
}
760760

761+
/// Returns true if the section is a global offset table section.
762+
virtual bool IsGOTSection(const lldb_private::Section &section) const {
763+
assert(section.GetObjectFile() == this && "Wrong object file!");
764+
return false;
765+
}
766+
761767
/// Get a hash that can be used for caching object file releated information.
762768
///
763769
/// Data for object files can be cached between runs of debug sessions and

lldb/source/Core/Section.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,10 @@ bool Section::ContainsOnlyDebugInfo() const {
471471
return false;
472472
}
473473

474+
bool Section::IsGOTSection() const {
475+
return GetObjectFile()->IsGOTSection(*this);
476+
}
477+
474478
#pragma mark SectionList
475479

476480
SectionList &SectionList::operator=(const SectionList &rhs) {

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5936,6 +5936,20 @@ Section *ObjectFileMachO::GetMachHeaderSection() {
59365936
return nullptr;
59375937
}
59385938

5939+
bool ObjectFileMachO::IsGOTSection(const lldb_private::Section &section) const {
5940+
assert(section.GetObjectFile() == this && "Wrong object file!");
5941+
SectionSP segment = section.GetParent();
5942+
if (!segment)
5943+
return false;
5944+
5945+
const bool is_data_const_got =
5946+
segment->GetName() == "__DATA_CONST" && section.GetName() == "__got";
5947+
const bool is_auth_const_ptr =
5948+
segment->GetName() == "__AUTH_CONST" &&
5949+
(section.GetName() == "__auth_got" || section.GetName() == "__auth_ptr");
5950+
return is_data_const_got || is_auth_const_ptr;
5951+
}
5952+
59395953
bool ObjectFileMachO::SectionIsLoadable(const Section *section) {
59405954
if (!section)
59415955
return false;

lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class ObjectFileMachO : public lldb_private::ObjectFile {
162162

163163
lldb_private::Section *GetMachHeaderSection();
164164

165+
bool IsGOTSection(const lldb_private::Section &section) const override;
166+
165167
// PluginInterface protocol
166168
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
167169

0 commit comments

Comments
 (0)