-static enum arch_type
-pe_arch (const char *arch)
-{
- if (strcmp (arch, "i386") == 0 || strcmp (arch, "ia32") == 0)
- return arch_type_i386;
+ if (size == 0)
+ return;
+
+ addr += extra->ImageBase;
+
+ /* Search for the section containing the DebugDirectory. */
+ for (section = abfd->sections; section != NULL; section = section->next)
+ {
+ if ((addr >= section->vma) && (addr < (section->vma + section->size)))
+ break;
+ }
+
+ if (section == NULL)
+ return;
+
+ if (!(section->flags & SEC_HAS_CONTENTS))
+ return;
+
+ dataoff = addr - section->vma;
+
+ /* PR 20605 and 22373: Make sure that the data is really there.
+ Note - since we are dealing with unsigned quantities we have
+ to be careful to check for potential overflows. */
+ if (dataoff >= section->size
+ || size > section->size - dataoff)
+ {
+ _bfd_error_handler
+ (_("%pB: error: debug data ends beyond end of debug directory"),
+ abfd);
+ return;
+ }
+
+ /* Read the whole section. */
+ if (!bfd_malloc_and_get_section (abfd, section, &data))
+ {
+ free (data);
+ return;
+ }
+
+ /* Search for a CodeView entry in the DebugDirectory */
+ for (i = 0; i < size / sizeof (struct external_IMAGE_DEBUG_DIRECTORY); i++)
+ {
+ struct external_IMAGE_DEBUG_DIRECTORY *ext
+ = &((struct external_IMAGE_DEBUG_DIRECTORY *)(data + dataoff))[i];
+ struct internal_IMAGE_DEBUG_DIRECTORY idd;