llvm-capstone/libunwind
Ryan Prichard 8200dbbcae [libunwind][Android] Improve workaround for PIE zero-dlpi_addr bug
Summary:
The workaround added in https://reviews.llvm.org/rL299575 appears to be
working around a bug in Android JB 4.1.x and 4.2.x (API 16 and 17).

Starting in API 16, Android added support for PIE binaries, but the
dynamic linker failed to initialize dlpi_addr to the address that the
executable was loaded at. The bug was fixed in Android JB 4.3.x (API 18).

Improve the true load bias calculation:

 * The code was assuming that the first segment would be the PT_PHDR
   segment. I think it's better to be explicit and search for PT_PHDR. (It
   will be almost as fast in practice.)

 * It's more correct to use p_vaddr rather than p_offset. If a PIE
   executable is linked with a non-zero image base (e.g. lld's
   -Wl,--image-base=xxxx), then we must use p_vaddr here.

The "phdr->p_vaddr < image_base" condition seems unnecessary and maybe
slightly wrong. If the OS were to load a binary at an address smaller than
a vaddr in the binary, we would still want to do this workaround.

The workaround is safe when the linker bug isn't present, because it
should calculate an image_base equal to dlpi_addr. Note that with API 21
and up, this workaround should never activate for dynamically-linked
objects, because non-PIE executables aren't allowed.

Consolidate the fix into a single block of code that calculates the true
image base, and make it clear that the fix no longer applies after API 18.

See https://github.com/android/ndk/issues/505 for details.

Reviewers: mclow.lists, srhines, danalbert, compnerd

Reviewed By: compnerd

Subscribers: srhines, krytarowski, christof, libcxx-commits

Tags: #libc

Differential Revision: https://reviews.llvm.org/D68971

llvm-svn: 374969
2019-10-16 02:38:47 +00:00
..
cmake [libunwind] Refactor CMake flag checks to match libc++ and libc++abi 2019-10-11 22:22:29 +00:00
docs Bump the trunk version to 10.0.0svn 2019-07-18 11:51:05 +00:00
include [NFC] Correct outdated links to the Itanium C++ ABI documentation 2019-04-11 16:37:07 +00:00
src [libunwind][Android] Improve workaround for PIE zero-dlpi_addr bug 2019-10-16 02:38:47 +00:00
test [libunwind] Adjust libunwind_01.pass.cpp test for ARM EHABI 2019-10-03 17:01:04 +00:00
.arcconfig
.clang-format
CMakeLists.txt [libunwind] Fix issues introduced in r374606 2019-10-12 01:50:57 +00:00
LICENSE.TXT