[libunwind] eb755df - Split findUnwindSectionsByPhdr into target-specific functions.
Sterling Augustine via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 6 13:28:36 PST 2020
Author: Sterling Augustine
Date: 2020-03-06T13:28:09-08:00
New Revision: eb755df5c27f5687a4f43a62e7eb0713c3f8f030
URL: https://github.com/llvm/llvm-project/commit/eb755df5c27f5687a4f43a62e7eb0713c3f8f030
DIFF: https://github.com/llvm/llvm-project/commit/eb755df5c27f5687a4f43a62e7eb0713c3f8f030.diff
LOG: Split findUnwindSectionsByPhdr into target-specific functions.
Summary:
This further cleans up the control flow and makes it easier to
optimize and replace portions in a subsequent patch.
This should be NFC, but given the amount of #ifdeffing here,
it may not be. So will watch the buildbots closely.
Also, as this is purely moving existing code around, I plan to
ignore the lint errors.
Reviewers: compnerd, miyuki, mstorsjo
Subscribers: libcxx-commits
Tags: #libc
Differential Revision: https://reviews.llvm.org/D75705
Added:
Modified:
libunwind/src/AddressSpace.hpp
Removed:
################################################################################
diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp
index 2f68d6525a0f..d4d66ad74ff6 100644
--- a/libunwind/src/AddressSpace.hpp
+++ b/libunwind/src/AddressSpace.hpp
@@ -409,24 +409,6 @@ LocalAddressSpace::getEncodedP(pint_t &addr, pint_t end, uint8_t encoding,
// that don't help at all.
#elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
-struct _LIBUNWIND_HIDDEN dl_iterate_cb_data {
- LocalAddressSpace *addressSpace;
- UnwindInfoSections *sects;
- uintptr_t targetAddr;
-};
-
-int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
- auto cbdata = static_cast<dl_iterate_cb_data *>(data);
- bool found_obj = false;
- bool found_hdr = false;
-
- assert(cbdata);
- assert(cbdata->sects);
-
- if (cbdata->targetAddr < pinfo->dlpi_addr) {
- return false;
- }
-
#if !defined(Elf_Half)
typedef ElfW(Half) Elf_Half;
#endif
@@ -437,8 +419,8 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
typedef ElfW(Addr) Elf_Addr;
#endif
+static Elf_Addr calculateImageBase(struct dl_phdr_info *pinfo) {
Elf_Addr image_base = pinfo->dlpi_addr;
-
#if defined(__ANDROID__) && __ANDROID_API__ < 18
if (image_base == 0) {
// Normally, an image base of 0 indicates a non-PIE executable. On
@@ -456,11 +438,32 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
}
}
#endif
+ return image_base;
+}
- #if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
+struct _LIBUNWIND_HIDDEN dl_iterate_cb_data {
+ LocalAddressSpace *addressSpace;
+ UnwindInfoSections *sects;
+ uintptr_t targetAddr;
+};
+
+#if defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
#if !defined(_LIBUNWIND_SUPPORT_DWARF_INDEX)
- #error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform."
+ #error "_LIBUNWIND_SUPPORT_DWARF_UNWIND requires _LIBUNWIND_SUPPORT_DWARF_INDEX on this platform."
#endif
+
+int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
+ auto *cbdata = static_cast<dl_iterate_cb_data *>(data);
+ bool found_obj = false;
+ bool found_hdr = false;
+
+ assert(cbdata);
+ assert(cbdata->sects);
+
+ if (cbdata->targetAddr < pinfo->dlpi_addr)
+ return 0;
+
+ Elf_Addr image_base = calculateImageBase(pinfo);
size_t object_length;
for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) {
@@ -492,7 +495,25 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
} else {
return false;
}
- #else // defined(_LIBUNWIND_ARM_EHABI)
+}
+
+#else // defined(LIBUNWIND_SUPPORT_DWARF_UNWIND)
+// Given all the #ifdef's above, the code here is for
+// defined(LIBUNWIND_ARM_EHABI)
+
+int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
+ auto *cbdata = static_cast<dl_iterate_cb_data *>(data);
+ bool found_obj = false;
+ bool found_hdr = false;
+
+ assert(cbdata);
+ assert(cbdata->sects);
+
+ if (cbdata->targetAddr < pinfo->dlpi_addr)
+ return 0;
+
+ Elf_Addr image_base = calculateImageBase(pinfo);
+
for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) {
const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i];
if (phdr->p_type == PT_LOAD) {
@@ -508,8 +529,8 @@ int findUnwindSectionsByPhdr(struct dl_phdr_info *pinfo, size_t, void *data) {
}
}
return found_obj && found_hdr;
- #endif
}
+#endif // defined(LIBUNWIND_SUPPORT_DWARF_UNWIND)
#endif // defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)
More information about the cfe-commits
mailing list