diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -409,24 +409,6 @@ // 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(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 @@ 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 @@ } } #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(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 @@ } 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(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 @@ } } return found_obj && found_hdr; - #endif } +#endif // defined(LIBUNWIND_SUPPORT_DWARF_UNWIND) #endif // defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND)