+static bfd_boolean
+elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note)
+{
+ size_t offset;
+
+ switch (elf_elfheader (abfd)->e_ident[EI_CLASS])
+ {
+ case ELFCLASS32:
+ if (note->descsz < 108)
+ return FALSE;
+ break;
+
+ case ELFCLASS64:
+ if (note->descsz < 120)
+ return FALSE;
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ /* Check for version 1 in pr_version. */
+ if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1)
+ return FALSE;
+
+ offset = 4;
+
+ /* Skip over pr_psinfosz. */
+ if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS32)
+ offset += 4;
+ else
+ {
+ offset += 4; /* Padding before pr_psinfosz. */
+ offset += 8;
+ }
+
+ /* pr_fname is PRFNAMESZ (16) + 1 bytes in size. */
+ elf_tdata (abfd)->core->program
+ = _bfd_elfcore_strndup (abfd, note->descdata + offset, 17);
+ offset += 17;
+
+ /* pr_psargs is PRARGSZ (80) + 1 bytes in size. */
+ elf_tdata (abfd)->core->command
+ = _bfd_elfcore_strndup (abfd, note->descdata + offset, 81);
+ offset += 81;
+
+ /* Padding before pr_pid. */
+ offset += 2;
+
+ /* The pr_pid field was added in version "1a". */
+ if (note->descsz < offset + 4)
+ return TRUE;
+
+ elf_tdata (abfd)->core->pid
+ = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+
+ return TRUE;
+}
+
+static bfd_boolean
+elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note)
+{
+ size_t offset;
+ size_t size;
+ size_t min_size;
+
+ /* Compute offset of pr_getregsz, skipping over pr_statussz.
+ Also compute minimum size of this note. */
+ switch (elf_elfheader (abfd)->e_ident[EI_CLASS])
+ {
+ case ELFCLASS32:
+ offset = 4 + 4;
+ min_size = offset + (4 * 2) + 4 + 4 + 4;
+ break;
+
+ case ELFCLASS64:
+ offset = 4 + 4 + 8; /* Includes padding before pr_statussz. */
+ min_size = offset + (8 * 2) + 4 + 4 + 4 + 4;
+ break;
+
+ default:
+ return FALSE;
+ }
+
+ if (note->descsz < min_size)
+ return FALSE;
+
+ /* Check for version 1 in pr_version. */
+ if (bfd_h_get_32 (abfd, (bfd_byte *) note->descdata) != 1)
+ return FALSE;
+
+ /* Extract size of pr_reg from pr_gregsetsz. */
+ /* Skip over pr_gregsetsz and pr_fpregsetsz. */
+ if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS32)
+ {
+ size = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+ offset += 4 * 2;
+ }
+ else
+ {
+ size = bfd_h_get_64 (abfd, (bfd_byte *) note->descdata + offset);
+ offset += 8 * 2;
+ }
+
+ /* Skip over pr_osreldate. */
+ offset += 4;
+
+ /* Read signal from pr_cursig. */
+ if (elf_tdata (abfd)->core->signal == 0)
+ elf_tdata (abfd)->core->signal
+ = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+ offset += 4;
+
+ /* Read TID from pr_pid. */
+ elf_tdata (abfd)->core->lwpid
+ = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset);
+ offset += 4;
+
+ /* Padding before pr_reg. */
+ if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64)
+ offset += 4;
+
+ /* Make sure that there is enough data remaining in the note. */
+ if ((note->descsz - offset) < size)
+ return FALSE;
+
+ /* Make a ".reg/999" section and a ".reg" section. */
+ return _bfd_elfcore_make_pseudosection (abfd, ".reg",
+ size, note->descpos + offset);
+}
+
+static bfd_boolean
+elfcore_grok_freebsd_note (bfd *abfd, Elf_Internal_Note *note)
+{
+ const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+
+ switch (note->type)
+ {
+ case NT_PRSTATUS:
+ if (bed->elf_backend_grok_freebsd_prstatus)
+ if ((*bed->elf_backend_grok_freebsd_prstatus) (abfd, note))
+ return TRUE;
+ return elfcore_grok_freebsd_prstatus (abfd, note);
+
+ case NT_FPREGSET:
+ return elfcore_grok_prfpreg (abfd, note);
+
+ case NT_PRPSINFO:
+ return elfcore_grok_freebsd_psinfo (abfd, note);
+
+ case NT_FREEBSD_THRMISC:
+ if (note->namesz == 8)
+ return elfcore_make_note_pseudosection (abfd, ".thrmisc", note);
+ else
+ return TRUE;
+
+ case NT_FREEBSD_PROCSTAT_PROC:
+ return elfcore_make_note_pseudosection (abfd, ".note.freebsdcore.proc",
+ note);
+
+ case NT_FREEBSD_PROCSTAT_FILES:
+ return elfcore_make_note_pseudosection (abfd, ".note.freebsdcore.files",
+ note);
+
+ case NT_FREEBSD_PROCSTAT_VMMAP:
+ return elfcore_make_note_pseudosection (abfd, ".note.freebsdcore.vmmap",
+ note);
+
+ case NT_FREEBSD_PROCSTAT_AUXV:
+ {
+ asection *sect = bfd_make_section_anyway_with_flags (abfd, ".auxv",
+ SEC_HAS_CONTENTS);
+
+ if (sect == NULL)
+ return FALSE;
+ sect->size = note->descsz - 4;
+ sect->filepos = note->descpos + 4;
+ sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32;
+
+ return TRUE;
+ }
+
+ case NT_X86_XSTATE:
+ if (note->namesz == 8)
+ return elfcore_grok_xstatereg (abfd, note);
+ else
+ return TRUE;
+
+ case NT_FREEBSD_PTLWPINFO:
+ return elfcore_make_note_pseudosection (abfd, ".note.freebsdcore.lwpinfo",
+ note);
+
+ case NT_ARM_VFP:
+ return elfcore_grok_arm_vfp (abfd, note);
+
+ default:
+ return TRUE;
+ }
+}
+