+ if (! bfd_section_from_phdr (abfd, i_phdrp + phindex, (int) phindex))
+ goto fail;
+
+ /* Check for core truncation. */
+ {
+ bfd_size_type high = 0;
+ struct stat statbuf;
+ for (phindex = 0; phindex < i_ehdrp->e_phnum; ++phindex)
+ {
+ Elf_Internal_Phdr *p = i_phdrp + phindex;
+ if (p->p_filesz)
+ {
+ bfd_size_type current = p->p_offset + p->p_filesz;
+ if (high < current)
+ high = current;
+ }
+ }
+ if (bfd_stat (abfd, &statbuf) == 0)
+ {
+ if ((bfd_size_type) statbuf.st_size < high)
+ {
+ _bfd_error_handler
+ /* xgettext:c-format */
+ (_("warning: %pB is truncated: expected core file "
+ "size >= %" PRIu64 ", found: %" PRIu64),
+ abfd, (uint64_t) high, (uint64_t) statbuf.st_size);
+ }
+ }
+ }
+
+ /* Save the entry point from the ELF header. */
+ abfd->start_address = i_ehdrp->e_entry;
+ return _bfd_no_cleanup;
+
+ wrong:
+ bfd_set_error (bfd_error_wrong_format);
+ fail:
+ return NULL;
+}
+
+/* Attempt to find a build-id in a core file from the core file BFD.
+ OFFSET is the file offset to a PT_LOAD segment that may contain
+ the build-id note. Returns TRUE upon success, FALSE otherwise. */
+
+bfd_boolean
+NAME(_bfd_elf, core_find_build_id)
+ (bfd *abfd,
+ bfd_vma offset)
+{
+ Elf_External_Ehdr x_ehdr; /* Elf file header, external form. */
+ Elf_Internal_Ehdr i_ehdr; /* Elf file header, internal form. */
+ Elf_Internal_Phdr *i_phdr;
+ unsigned int i;
+ size_t amt;
+
+ /* Seek to the position of the segment at OFFSET. */
+ if (bfd_seek (abfd, offset, SEEK_SET) != 0)
+ goto fail;
+
+ /* Read in the ELF header in external format. */
+ if (bfd_bread (&x_ehdr, sizeof (x_ehdr), abfd) != sizeof (x_ehdr))