1c194f
diff --git a/coregrind/m_debuginfo/readelf.c b/coregrind/m_debuginfo/readelf.c
1c194f
index 70c28e629..8bd3e049c 100644
1c194f
--- a/coregrind/m_debuginfo/readelf.c
1c194f
+++ b/coregrind/m_debuginfo/readelf.c
1c194f
@@ -1137,7 +1137,11 @@ HChar* find_buildid(DiImage* img, Bool rel_ok, Bool search_shdrs)
1c194f
 
1c194f
       ElfXX_Ehdr ehdr;
1c194f
       ML_(img_get)(&ehdr, img, 0, sizeof(ehdr));
1c194f
-      for (i = 0; i < ehdr.e_phnum; i++) {
1c194f
+      /* Skip the phdrs when we have to search the shdrs. In separate
1c194f
+         .debug files the phdrs might not be valid (they are a copy of
1c194f
+         the main ELF file) and might trigger assertions when getting
1c194f
+	 image notes based on them. */
1c194f
+      for (i = 0; !search_shdrs && i < ehdr.e_phnum; i++) {
1c194f
          ElfXX_Phdr phdr;
1c194f
          ML_(img_get)(&phdr, img,
1c194f
                       ehdr.e_phoff + i * ehdr.e_phentsize, sizeof(phdr));