diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:52:37 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-10-23 17:52:37 +0000 |
commit | 067b0ac8a70ff539e3dbbe2be60c3ac441c8305b (patch) | |
tree | 261de59dded1643a4a128978fefa90ea5a193a50 | |
parent | cd5ff43da54e357cd6a79fea21f2ae1afb8d3660 (diff) |
Vendor import of stripped LLVM libunwind trunk r375505, the last commitvendor/llvm-libunwind/libunwind-trunk-r375505vendor/llvm-libunwind
before the upstream Subversion repository was made read-only, and the
LLVM project migrated to GitHub:
https://llvm.org/svn/llvm-project/libunwind/trunk@375505
Notes
Notes:
svn path=/vendor/llvm-libunwind/dist/; revision=353948
svn path=/vendor/llvm-libunwind/libunwind-r375505/; revision=353949; tag=vendor/llvm-libunwind/libunwind-trunk-r375505
-rw-r--r-- | src/AddressSpace.hpp | 62 | ||||
-rw-r--r-- | src/RWMutex.hpp | 2 | ||||
-rw-r--r-- | src/Unwind-EHABI.cpp | 9 | ||||
-rw-r--r-- | src/UnwindCursor.hpp | 10 | ||||
-rw-r--r-- | src/libunwind.cpp | 6 |
5 files changed, 51 insertions, 38 deletions
diff --git a/src/AddressSpace.hpp b/src/AddressSpace.hpp index fb07c807db9e..908c898d7403 100644 --- a/src/AddressSpace.hpp +++ b/src/AddressSpace.hpp @@ -27,11 +27,18 @@ #if _LIBUNWIND_USE_DLADDR #include <dlfcn.h> -#if defined(__unix__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA) +#if defined(__unix__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA) #pragma comment(lib, "dl") #endif #endif +#if defined(_LIBUNWIND_ARM_EHABI) +struct EHABIIndexEntry { + uint32_t functionOffset; + uint32_t data; +}; +#endif + #ifdef __APPLE__ #include <mach-o/getsect.h> namespace libunwind { @@ -462,12 +469,13 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, (void)targetAddr; (void)info; return true; -#elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__) && \ - (__ANDROID_API__ < 21) +#elif defined(_LIBUNWIND_ARM_EHABI) && defined(__BIONIC__) + // For ARM EHABI, Bionic didn't implement dl_iterate_phdr until API 21. After + // API 21, dl_iterate_phdr exists, but dl_unwind_find_exidx is much faster. int length = 0; info.arm_section = (uintptr_t)dl_unwind_find_exidx((_Unwind_Ptr)targetAddr, &length); - info.arm_section_length = (uintptr_t)length; + info.arm_section_length = (uintptr_t)length * sizeof(EHABIIndexEntry); if (info.arm_section && info.arm_section_length) return true; #elif defined(_LIBUNWIND_ARM_EHABI) || defined(_LIBUNWIND_SUPPORT_DWARF_UNWIND) @@ -497,32 +505,40 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, #if !defined(Elf_Phdr) typedef ElfW(Phdr) Elf_Phdr; #endif -#if !defined(Elf_Addr) && defined(__ANDROID__) +#if !defined(Elf_Addr) typedef ElfW(Addr) Elf_Addr; #endif + 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 + // versions of Android prior to API 18, the dynamic linker reported a + // dlpi_addr of 0 for PIE executables. Compute the true image base + // using the PT_PHDR segment. + // See https://github.com/android/ndk/issues/505. + for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) { + const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i]; + if (phdr->p_type == PT_PHDR) { + image_base = reinterpret_cast<Elf_Addr>(pinfo->dlpi_phdr) - + phdr->p_vaddr; + break; + } + } + } +#endif + #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." #endif size_t object_length; -#if defined(__ANDROID__) - Elf_Addr image_base = - pinfo->dlpi_phnum - ? reinterpret_cast<Elf_Addr>(pinfo->dlpi_phdr) - - reinterpret_cast<const Elf_Phdr *>(pinfo->dlpi_phdr) - ->p_offset - : 0; -#endif for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) { const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i]; if (phdr->p_type == PT_LOAD) { - uintptr_t begin = pinfo->dlpi_addr + phdr->p_vaddr; -#if defined(__ANDROID__) - if (pinfo->dlpi_addr == 0 && phdr->p_vaddr < image_base) - begin = begin + image_base; -#endif + uintptr_t begin = image_base + phdr->p_vaddr; uintptr_t end = begin + phdr->p_memsz; if (cbdata->targetAddr >= begin && cbdata->targetAddr < end) { cbdata->sects->dso_base = begin; @@ -531,11 +547,7 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, } } else if (phdr->p_type == PT_GNU_EH_FRAME) { EHHeaderParser<LocalAddressSpace>::EHHeaderInfo hdrInfo; - uintptr_t eh_frame_hdr_start = pinfo->dlpi_addr + phdr->p_vaddr; -#if defined(__ANDROID__) - if (pinfo->dlpi_addr == 0 && phdr->p_vaddr < image_base) - eh_frame_hdr_start = eh_frame_hdr_start + image_base; -#endif + uintptr_t eh_frame_hdr_start = image_base + phdr->p_vaddr; cbdata->sects->dwarf_index_section = eh_frame_hdr_start; cbdata->sects->dwarf_index_section_length = phdr->p_memsz; found_hdr = EHHeaderParser<LocalAddressSpace>::decodeEHHdr( @@ -556,12 +568,12 @@ inline bool LocalAddressSpace::findUnwindSections(pint_t targetAddr, for (Elf_Half i = 0; i < pinfo->dlpi_phnum; i++) { const Elf_Phdr *phdr = &pinfo->dlpi_phdr[i]; if (phdr->p_type == PT_LOAD) { - uintptr_t begin = pinfo->dlpi_addr + phdr->p_vaddr; + uintptr_t begin = image_base + phdr->p_vaddr; uintptr_t end = begin + phdr->p_memsz; if (cbdata->targetAddr >= begin && cbdata->targetAddr < end) found_obj = true; } else if (phdr->p_type == PT_ARM_EXIDX) { - uintptr_t exidx_start = pinfo->dlpi_addr + phdr->p_vaddr; + uintptr_t exidx_start = image_base + phdr->p_vaddr; cbdata->sects->arm_section = exidx_start; cbdata->sects->arm_section_length = phdr->p_memsz; found_hdr = true; diff --git a/src/RWMutex.hpp b/src/RWMutex.hpp index a37ac77144f3..954e94c322d4 100644 --- a/src/RWMutex.hpp +++ b/src/RWMutex.hpp @@ -17,7 +17,7 @@ #include <windows.h> #elif !defined(_LIBUNWIND_HAS_NO_THREADS) #include <pthread.h> -#if defined(__unix__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA) +#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBUNWIND_HAS_COMMENT_LIB_PRAGMA) #pragma comment(lib, "pthread") #endif #endif diff --git a/src/Unwind-EHABI.cpp b/src/Unwind-EHABI.cpp index 4ff5e318b5f1..a23ba2cc7e0e 100644 --- a/src/Unwind-EHABI.cpp +++ b/src/Unwind-EHABI.cpp @@ -941,8 +941,13 @@ _Unwind_VRS_Pop(_Unwind_Context *context, _Unwind_VRS_RegClass regclass, // format 1", which is equivalent to FSTMD + a padding word. for (uint32_t i = first; i < end; ++i) { // SP is only 32-bit aligned so don't copy 64-bit at a time. - uint64_t value = *sp++; - value |= ((uint64_t)(*sp++)) << 32; + uint64_t w0 = *sp++; + uint64_t w1 = *sp++; +#ifdef __LITTLE_ENDIAN__ + uint64_t value = (w1 << 32) | w0; +#else + uint64_t value = (w0 << 32) | w1; +#endif if (_Unwind_VRS_Set(context, regclass, i, representation, &value) != _UVRSR_OK) return _UVRSR_FAILED; diff --git a/src/UnwindCursor.hpp b/src/UnwindCursor.hpp index a96c9f39958d..b4d44e111a65 100644 --- a/src/UnwindCursor.hpp +++ b/src/UnwindCursor.hpp @@ -1222,11 +1222,6 @@ template <typename A, typename R> bool UnwindCursor<A, R>::isSignalFrame() { #endif // defined(_LIBUNWIND_SUPPORT_SEH_UNWIND) #if defined(_LIBUNWIND_ARM_EHABI) -struct EHABIIndexEntry { - uint32_t functionOffset; - uint32_t data; -}; - template<typename A> struct EHABISectionIterator { typedef EHABISectionIterator _Self; @@ -1991,7 +1986,10 @@ int UnwindCursor<A, R>::step() { template <typename A, typename R> void UnwindCursor<A, R>::getInfo(unw_proc_info_t *info) { - *info = _info; + if (_unwindInfoMissing) + memset(info, 0, sizeof(*info)); + else + *info = _info; } template <typename A, typename R> diff --git a/src/libunwind.cpp b/src/libunwind.cpp index c90032bd66c9..31f30f5cd709 100644 --- a/src/libunwind.cpp +++ b/src/libunwind.cpp @@ -171,8 +171,7 @@ _LIBUNWIND_HIDDEN int __unw_get_proc_info(unw_cursor_t *cursor, co->getInfo(info); if (info->end_ip == 0) return UNW_ENOINFO; - else - return UNW_ESUCCESS; + return UNW_ESUCCESS; } _LIBUNWIND_WEAK_ALIAS(__unw_get_proc_info, unw_get_proc_info) @@ -194,8 +193,7 @@ _LIBUNWIND_HIDDEN int __unw_get_proc_name(unw_cursor_t *cursor, char *buf, AbstractUnwindCursor *co = (AbstractUnwindCursor *)cursor; if (co->getFunctionName(buf, bufLen, offset)) return UNW_ESUCCESS; - else - return UNW_EUNSPEC; + return UNW_EUNSPEC; } _LIBUNWIND_WEAK_ALIAS(__unw_get_proc_name, unw_get_proc_name) |