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
This commit is contained in:
Sterling Augustine
2020-03-05 11:50:51 -08:00
parent f0f4d41631
commit eb755df5c2

View File

@@ -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)