From 7ef1d3a265b35e58e941dbb5f5be24a7bfeb65c6 Mon Sep 17 00:00:00 2001 From: christos Date: Wed, 29 Mar 2017 15:28:42 +0000 Subject: [PATCH] Teach me about the NetBSD-CORE ELF AuxV note. --- external/gpl3/binutils/dist/bfd/elf.c | 69 ++++++++----------- .../gpl3/binutils/dist/binutils/readelf.c | 7 +- .../gpl3/binutils/dist/include/elf/common.h | 1 + 3 files changed, 37 insertions(+), 40 deletions(-) diff --git a/external/gpl3/binutils/dist/bfd/elf.c b/external/gpl3/binutils/dist/bfd/elf.c index ccf2d36e19bb..d7db904cc426 100644 --- a/external/gpl3/binutils/dist/bfd/elf.c +++ b/external/gpl3/binutils/dist/bfd/elf.c @@ -8741,6 +8741,22 @@ _bfd_elfcore_make_pseudosection (bfd *abfd, return elfcore_maybe_make_sect (abfd, name, sect); } +static bfd_boolean +elfcore_make_auxv_note_section (bfd *abfd, Elf_Internal_Note *note, + size_t offs) +{ + asection *sect = bfd_make_section_anyway_with_flags (abfd, ".auxv", + SEC_HAS_CONTENTS); + + if (sect == NULL) + return FALSE; + sect->size = note->descsz - offs; + sect->filepos = note->descpos + offs; + sect->alignment_power = 1 + bfd_get_arch_size (abfd) / 32; + + return TRUE; +} + /* prstatus_t exists on: solaris 2.5+ linux 2.[01] + glibc @@ -9461,18 +9477,7 @@ elfcore_grok_note (bfd *abfd, Elf_Internal_Note *note) #endif case NT_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; - } + return elfcore_make_auxv_note_section (abfd, note, 0); case NT_FILE: return elfcore_make_note_pseudosection (abfd, ".note.linuxcore.file", @@ -9664,18 +9669,7 @@ elfcore_grok_freebsd_note (bfd *abfd, Elf_Internal_Note *note) return TRUE; 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; - } + return elfcore_make_auxv_note_section (abfd, note, 4); case NT_X86_XSTATE: if (note->namesz == 8) @@ -9721,6 +9715,7 @@ elfcore_grok_netbsd_procinfo (bfd *abfd, Elf_Internal_Note *note) note); } + static bfd_boolean elfcore_grok_netbsd_note (bfd *abfd, Elf_Internal_Note *note) { @@ -9729,17 +9724,24 @@ elfcore_grok_netbsd_note (bfd *abfd, Elf_Internal_Note *note) if (elfcore_netbsd_get_lwpid (note, &lwp)) elf_tdata (abfd)->core->lwpid = lwp; - if (note->type == NT_NETBSDCORE_PROCINFO) + switch (note->type) { + case NT_NETBSDCORE_PROCINFO: /* NetBSD-specific core "procinfo". Note that we expect to find this note before any of the others, which is fine, since the kernel writes this note out first when it creates a core file. */ - return elfcore_grok_netbsd_procinfo (abfd, note); + + case NT_NETBSDCORE_AUXV: + /* NetBSD-specific Elf Auxiliary Vector data. */ + return elfcore_make_auxv_note_section (abfd, note, 4); + + default: + break; } - /* As of Jan 2002 there are no other machine-independent notes + /* As of March 2017 there are no other machine-independent notes defined for NetBSD core files. If the note type is less than the start of the machine-dependent note types, we don't understand it. */ @@ -9837,18 +9839,7 @@ elfcore_grok_openbsd_note (bfd *abfd, Elf_Internal_Note *note) 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; - } + return elfcore_make_auxv_note_section (abfd, note, 0); if (note->type == NT_OPENBSD_WCOOKIE) { diff --git a/external/gpl3/binutils/dist/binutils/readelf.c b/external/gpl3/binutils/dist/binutils/readelf.c index 88a880db7548..b5ff758aacc9 100644 --- a/external/gpl3/binutils/dist/binutils/readelf.c +++ b/external/gpl3/binutils/dist/binutils/readelf.c @@ -15666,10 +15666,15 @@ get_netbsd_elfcore_note_type (unsigned e_type) { static char buff[64]; - if (e_type == NT_NETBSDCORE_PROCINFO) + switch (e_type) { + case NT_NETBSDCORE_PROCINFO: /* NetBSD core "procinfo" structure. */ return _("NetBSD procinfo structure"); + case NT_NETBSDCORE_AUXV: + return _("NetBSD ELF auxiliary vector data"); + default: + break; } /* As of Jan 2002 there are no other machine-independent notes diff --git a/external/gpl3/binutils/dist/include/elf/common.h b/external/gpl3/binutils/dist/include/elf/common.h index 61d4c47c8441..279777387b60 100644 --- a/external/gpl3/binutils/dist/include/elf/common.h +++ b/external/gpl3/binutils/dist/include/elf/common.h @@ -614,6 +614,7 @@ must start with "NetBSD-CORE". */ #define NT_NETBSDCORE_PROCINFO 1 /* Has a struct procinfo */ +#define NT_NETBSDCORE_AUXV 2 /* Has ELF Auxiliary vector */ #define NT_NETBSDCORE_FIRSTMACH 32 /* start of machdep note types */