-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[lldb] Add function to tell if a section is a GOT section #165936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
|
@llvm/pr-subscribers-lldb Author: Augusto Noronha (augusto2112) ChangesA 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. Full diff: https://github.com/llvm/llvm-project/pull/165936.diff 5 Files Affected:
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 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(); }
|
bulbazord
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable and straightforward. What does the swift plugin do with this information?
|
|
||
| bool is_data_const_got = | ||
| segment->GetName() == "__DATA_CONST" && section.GetName() == "__got"; | ||
| bool is_auth_const_ptr = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: const these two.
|
Does this same issue need to be handled on Linux / ObjectFileELF? |
jasonmolenda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, my only concerns are about whether we need to handle the same thing in ELF.
The shared cache can unique pointers in the GOT sections and null the original pointers, and when parsing Swift metadata, LLDB needs to know when translating a file address into a process address if it's potentially one of those moved addresses, and run some fallback logic if that's the case. |
For my purposes I only need this for Mach-O since this is specific to the shared cache, but the interface is open to being implemented for ELF if someone else ever needs it. |
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.