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