Skip to content

Commit 903c72f

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
1 parent 483dcf2 commit 903c72f

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
@@ -278,6 +278,9 @@ class Section : public std::enable_shared_from_this<Section>,
278278
/// return true.
279279
bool ContainsOnlyDebugInfo() const;
280280

281+
/// Returns true if this is a global offset table section.
282+
bool IsGOTSection() const;
283+
281284
protected:
282285
ObjectFile *m_obj_file; // The object file that data for this section should
283286
// be read from

lldb/include/lldb/Symbol/ObjectFile.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,12 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,
761761
return false;
762762
}
763763

764+
/// Returns true if the section is a global offset table section.
765+
virtual bool IsGOTSection(const lldb_private::Section &section) const {
766+
assert(section.GetObjectFile() == this && "Wrong object file!");
767+
return false;
768+
}
769+
764770
/// Get a hash that can be used for caching object file releated information.
765771
///
766772
/// 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
@@ -473,6 +473,10 @@ bool Section::ContainsOnlyDebugInfo() const {
473473
return false;
474474
}
475475

476+
bool Section::IsGOTSection() const {
477+
return GetObjectFile()->IsGOTSection(*this);
478+
}
479+
476480
#pragma mark SectionList
477481

478482
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
@@ -6069,6 +6069,20 @@ Section *ObjectFileMachO::GetMachHeaderSection() {
60696069
return nullptr;
60706070
}
60716071

6072+
bool ObjectFileMachO::IsGOTSection(const lldb_private::Section &section) const {
6073+
assert(section.GetObjectFile() == this && "Wrong object file!");
6074+
SectionSP segment = section.GetParent();
6075+
if (!segment)
6076+
return false;
6077+
6078+
bool is_data_const_got =
6079+
segment->GetName() == "__DATA_CONST" && section.GetName() == "__got";
6080+
bool is_auth_const_ptr =
6081+
segment->GetName() == "__AUTH_CONST" &&
6082+
(section.GetName() == "__auth_got" || section.GetName() == "__auth_ptr");
6083+
return is_data_const_got || is_auth_const_ptr;
6084+
}
6085+
60726086
bool ObjectFileMachO::SectionIsLoadable(const Section *section) {
60736087
if (!section)
60746088
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)