Skip to content

Commit 0bb0fde

Browse files
committed
[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. rdar://160837587 (cherry picked from commit 903c72f)
1 parent 9d05187 commit 0bb0fde

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

lldb/include/lldb/Core/Section.h

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

265+
/// Returns true if this is a global offset table section.
266+
bool IsGOTSection() const;
267+
265268
protected:
266269
ObjectFile *m_obj_file; // The object file that data for this section should
267270
// be read from

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,12 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
740740
return false;
741741
}
742742

743+
/// Returns true if the section is a global offset table section.
744+
virtual bool IsGOTSection(const lldb_private::Section &section) const {
745+
assert(section.GetObjectFile() == this && "Wrong object file!");
746+
return false;
747+
}
748+
743749
/// Get a hash that can be used for caching object file releated information.
744750
///
745751
/// Data for object files can be cached between runs of debug sessions and

lldb/source/Core/Section.cpp

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

474+
bool Section::IsGOTSection() const {
475+
return GetObjectFile()->IsGOTSection(*this);
476+
}
474477

475478
#pragma mark SectionList
476479

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6305,6 +6305,20 @@ Section *ObjectFileMachO::GetMachHeaderSection() {
63056305
return nullptr;
63066306
}
63076307

6308+
bool ObjectFileMachO::IsGOTSection(const lldb_private::Section &section) const {
6309+
assert(section.GetObjectFile() == this && "Wrong object file!");
6310+
SectionSP segment = section.GetParent();
6311+
if (!segment)
6312+
return false;
6313+
6314+
bool is_data_const_got =
6315+
segment->GetName() == "__DATA_CONST" && section.GetName() == "__got";
6316+
bool is_auth_const_ptr =
6317+
segment->GetName() == "__AUTH_CONST" &&
6318+
(section.GetName() == "__auth_got" || section.GetName() == "__auth_ptr");
6319+
return is_data_const_got || is_auth_const_ptr;
6320+
}
6321+
63086322
bool ObjectFileMachO::SectionIsLoadable(const Section *section) {
63096323
if (!section)
63106324
return false;

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

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

160160
lldb_private::Section *GetMachHeaderSection();
161161

162+
bool IsGOTSection(const lldb_private::Section &section) const override;
163+
162164
// PluginInterface protocol
163165
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
164166

0 commit comments

Comments
 (0)