[libunwind] Optimize dl_iterate_phdr's findUnwindSectionsByPhdr
authorRyan Prichard <rprichard@google.com>
Wed, 23 Sep 2020 21:25:23 +0000 (14:25 -0700)
committerRyan Prichard <rprichard@google.com>
Wed, 23 Sep 2020 22:40:39 +0000 (15:40 -0700)
commit881aba7071c6e4cc2417e875ca5027ec7c0a92a3
treed17548b28efffbfa4434977ebbb29d87abf5ba30
parentb16d6653c01cee37f51a98dd4092c4ef302c47a5
[libunwind] Optimize dl_iterate_phdr's findUnwindSectionsByPhdr

Currently, findUnwindSectionsByPhdr is slightly micro-optimized for the
case where the first callback has the target address, and is otherwise
very inefficient -- it decodes .eh_frame_hdr even when no PT_LOAD
matches the PC. (If the FrameHeaderCache is enabled, then the
micro-optimization only helps the first time unwind info is looked up.)

Instead, it makes more sense to optimize for the case where the
callback *doesn't* find the target address, so search for a PT_LOAD
segment first, and only look for the unwind info section if a matching
PT_LOAD is found.

This change helps on an Android benchmark with 100 shared objects,
where the DSO at the end of the dl_iterate_phdr list throws 10000
exceptions. Assuming the frame cache is disabled, this change cuts
about 30-40% off the benchmark's runtime.

Reviewed By: compnerd, saugustine, #libunwind

Differential Revision: https://reviews.llvm.org/D87881
libunwind/src/AddressSpace.hpp