AddressSpace: fix DWARF based unwinding handling on Android

It is possible that there are no program headers in the module.  Do not
attempt to dereference nullptr as a program header.

llvm-svn: 299591
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 5c18b4406e11d89345e278457f7dbbe2f6af9cee
diff --git a/src/AddressSpace.hpp b/src/AddressSpace.hpp
index ab6e0d5..54b258e 100644
--- a/src/AddressSpace.hpp
+++ b/src/AddressSpace.hpp
@@ -394,8 +394,11 @@
         size_t object_length;
 #if defined(__ANDROID__)
         Elf_Addr image_base =
-            reinterpret_cast<Elf_Addr>(pinfo->dlpi_phdr) -
-            reinterpret_cast<const Elf_Phdr *>(pinfo->dlpi_phdr)->p_offset;
+            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++) {