[PATCH] OpenBSD ELF core support

Mark Kettenis mark.kettenis@xs4all.nl
Sat Mar 14 19:18:00 GMT 2009


A couple of weeks ago, I changed the OpenBSD kernel to create ELF core
dumps (we were still using the old NetBSD-style a.out core dumps).
This adds support for those in libbfd.

ok?


Index: bfd/ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* elf.c (elfcore_grok_openbsd_procinfo) 
	(elfcore_grok_openbsd_note): New functions.
	(elf_parse_notes): Handle notes from OpenBSD ELF core files.

Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.477
diff -u -p -r1.477 elf.c
--- bfd/elf.c 25 Feb 2009 14:39:35 -0000 1.477
+++ bfd/elf.c 14 Mar 2009 19:06:05 -0000
@@ -8101,6 +8101,70 @@ elfcore_grok_netbsd_note (bfd *abfd, Elf
 }
 
 static bfd_boolean
+elfcore_grok_openbsd_procinfo (bfd *abfd, Elf_Internal_Note *note)
+{
+  /* Signal number at offset 0x08. */
+  elf_tdata (abfd)->core_signal
+    = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x08);
+
+  /* Process ID at offset 0x20. */
+  elf_tdata (abfd)->core_pid
+    = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x20);
+
+  /* Command name at 0x48 (max 32 bytes, including nul). */
+  elf_tdata (abfd)->core_command
+    = _bfd_elfcore_strndup (abfd, note->descdata + 0x48, 31);
+
+  return TRUE;
+}
+
+static bfd_boolean
+elfcore_grok_openbsd_note (bfd *abfd, Elf_Internal_Note *note)
+{
+  if (note->type == NT_OPENBSD_PROCINFO)
+    return elfcore_grok_openbsd_procinfo (abfd, note);
+
+  if (note->type == NT_OPENBSD_REGS)
+    return elfcore_make_note_pseudosection (abfd, ".reg", note);
+
+  if (note->type == NT_OPENBSD_FPREGS)
+    return elfcore_make_note_pseudosection (abfd, ".reg2", note);
+
+  if (note->type == NT_OPENBSD_XFPREGS)
+    return elfcore_make_note_pseudosection (abfd, ".reg-xfp", note);
+
+  if (note->type == NT_OPENBSD_AUXV)
+    {
+      asection *sect = bfd_make_section_anyway_with_flags (abfd, ".auxv",
+							   SEC_HAS_CONTENTS);
+
+      if (sect == NULL)
+	return FALSE;
+      sect->size = note->descsz;
+      sect->filepos = note->descpos;
+      sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32;
+
+      return TRUE;
+    }
+
+  if (note->type == NT_OPENBSD_WCOOKIE)
+    {
+      asection *sect = bfd_make_section_anyway_with_flags (abfd, ".wcookie",
+							   SEC_HAS_CONTENTS);
+
+      if (sect == NULL)
+	return FALSE;
+      sect->size = note->descsz;
+      sect->filepos = note->descpos;
+      sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32;
+
+      return TRUE;
+    }
+
+  return TRUE;
+}
+
+static bfd_boolean
 elfcore_grok_nto_status (bfd *abfd, Elf_Internal_Note *note, long *tid)
 {
   void *ddata = note->descdata;
@@ -8587,6 +8651,11 @@ elf_parse_notes (bfd *abfd, char *buf, s
 	      if (! elfcore_grok_netbsd_note (abfd, &in))
 		return FALSE;
 	    }
+	  else if (CONST_STRNEQ (in.namedata, "OpenBSD"))
+	    {
+	      if (! elfcore_grok_openbsd_note (abfd, &in))
+		return FALSE;
+	    }
 	  else if (CONST_STRNEQ (in.namedata, "QNX"))
 	    {
 	      if (! elfcore_grok_nto_note (abfd, &in))
Index: include/elf/ChangeLog
from  Mark Kettenis  <kettenis@gnu.org>

	* common.h (NT_OPENBSD_PROCINFO, NT_OPENBSD_AUXV) 
	(NT_OPENBSD_REGS, NT_OPENBSD_FPREGS, NT_OPENBSD_XFPREGS) 
	(NT_OPENBSD_WCOOKIE): New defines.

Index: include/elf/common.h
===================================================================
RCS file: /cvs/src/src/include/elf/common.h,v
retrieving revision 1.104
diff -u -p -r1.104 common.h
--- include/elf/common.h 2 Mar 2009 10:33:07 -0000 1.104
+++ include/elf/common.h 14 Mar 2009 19:06:07 -0000
@@ -465,6 +465,18 @@
 #define NT_NETBSDCORE_PROCINFO	1	/* Has a struct procinfo */
 #define NT_NETBSDCORE_FIRSTMACH	32	/* start of machdep note types */
 
+
+/* Note segments for core files on OpenBSD systems.  Note name is
+   "OpenBSD".  */
+
+#define NT_OPENBSD_PROCINFO	10
+#define NT_OPENBSD_AUXV		11
+#define NT_OPENBSD_REGS		20
+#define NT_OPENBSD_FPREGS	21
+#define NT_OPENBSD_XFPREGS	22
+#define NT_OPENBSD_WCOOKIE	23
+
+
 /* Note segments for core files on SPU systems.  Note name
    must start with "SPU/".  */
 



More information about the Binutils mailing list