Mark Wielaard c728a3
--- valgrind/coregrind/m_debuginfo/readelf.c	(revision 12871)
Mark Wielaard c728a3
+++ valgrind/coregrind/m_debuginfo/readelf.c	(working copy)
Mark Wielaard 56078f
@@ -888,7 +888,7 @@
Mark Wielaard 56078f
  * http://fedoraproject.org/wiki/RolandMcGrath/BuildID
Mark Wielaard 56078f
  */
Mark Wielaard 56078f
 static
Mark Wielaard 56078f
-Char *find_buildid(Addr image, UWord n_image, Bool rel_ok)
Mark Wielaard 56078f
+Char *find_buildid(Addr image, UWord n_image, Bool rel_ok, Bool search_shdrs)
Mark Wielaard 56078f
 {
Mark Wielaard 56078f
    Char* buildid = NULL;
Mark Wielaard 56078f
    __attribute__((unused)) /* on Android, at least */
Mark Wielaard 56078f
@@ -930,7 +930,11 @@
Mark Wielaard 56078f
          }
Mark Wielaard 56078f
       }
Mark Wielaard 56078f
 
Mark Wielaard 56078f
-      if (buildid || !rel_ok)
Mark Wielaard 56078f
+      /* Normally we would only search shdrs for ET_REL files, but when
Mark Wielaard 56078f
+         we search for a separate .debug file phdrs might not be there
Mark Wielaard 56078f
+         (they are never loaded) or have been corrupted, so try again
Mark Wielaard 56078f
+         against shdrs. */
Mark Wielaard 56078f
+      if (buildid || (!rel_ok && !search_shdrs))
Mark Wielaard 56078f
          return buildid;
Mark Wielaard 56078f
 
Mark Wielaard 56078f
       for (i = 0; i < ehdr->e_shnum; i++) {
Mark Wielaard 56078f
@@ -1074,7 +1078,7 @@
Mark Wielaard 56078f
       return 0;
Mark Wielaard 56078f
 
Mark Wielaard 56078f
    if (buildid) {
Mark Wielaard 56078f
-      Char* debug_buildid = find_buildid(sr_Res(sres), *size, rel_ok);
Mark Wielaard 56078f
+      Char* debug_buildid = find_buildid(sr_Res(sres), *size, rel_ok, True);
Mark Wielaard 56078f
       if (debug_buildid == NULL || VG_(strcmp)(buildid, debug_buildid) != 0) {
Mark Wielaard 56078f
          SysRes res = VG_(am_munmap_valgrind)(sr_Res(sres), *size);
Mark Wielaard 56078f
          vg_assert(!sr_isError(res));
Mark Wielaard 56078f
@@ -2274,7 +2278,7 @@
Mark Wielaard 56078f
       vg_assert(dimage == 0 && n_dimage == 0);
Mark Wielaard 56078f
 
Mark Wielaard 56078f
       /* Look for a build-id */
Mark Wielaard 56078f
-      buildid = find_buildid(oimage, n_oimage, False);
Mark Wielaard 56078f
+      buildid = find_buildid(oimage, n_oimage, False, False);
Mark Wielaard 56078f
 
Mark Wielaard 56078f
       /* Look for a debug image */
Mark Wielaard 56078f
       if (buildid != NULL || debuglink_img != NULL) {