From patchwork Wed Nov 23 20:59:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 17747 Received: (qmail 33113 invoked by alias); 23 Nov 2016 20:59:42 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 33086 invoked by uid 89); 23 Nov 2016 20:59:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=no version=3.3.2 spammy=baldwin, Baldwin, bits_per_word, jhbfreebsdorg X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail.baldwin.cx Received: from bigwig.baldwin.cx (HELO mail.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Nov 2016 20:59:40 +0000 Received: from ralph.com (c-73-231-226-104.hsd1.ca.comcast.net [73.231.226.104]) by mail.baldwin.cx (Postfix) with ESMTPSA id 707A710AA59; Wed, 23 Nov 2016 15:59:38 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org, binutils@sourceware.org Subject: [PATCH 1/3] Use the ELF class to determine the word size for FreeBSD core notes. Date: Wed, 23 Nov 2016 12:59:00 -0800 Message-Id: <20161123205902.90995-2-jhb@FreeBSD.org> In-Reply-To: <20161123205902.90995-1-jhb@FreeBSD.org> References: <20161123205902.90995-1-jhb@FreeBSD.org> X-IsSubscribed: yes FreeBSD MIPS64 core dumps contain an empty e_flags value so are assigned to the default bfd_arch_mips which is 32-bits. bfd/ChangeLog: * elf.c (elfcore_grok_freebsd_psinfo): Use ELF header class to determine structure sizes. (elfcore_grok_freebsd_prstatus): Likewise. --- bfd/ChangeLog | 6 ++++++ bfd/elf.c | 23 +++++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 346ff29..05dd4f5 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2016-11-23 John Baldwin + + * elf.c (elfcore_grok_freebsd_psinfo): Use ELF header class to + determine structure sizes. + (elfcore_grok_freebsd_prstatus): Likewise. + 2016-11-23 Nick Clifton PR ld/20815 diff --git a/bfd/elf.c b/bfd/elf.c index 936255e..01e02f6 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -9749,14 +9749,14 @@ elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note) { size_t offset; - switch (abfd->arch_info->bits_per_word) + switch (elf_elfheader (abfd)->e_ident[EI_CLASS]) { - case 32: + case ELFCLASS32: if (note->descsz < 108) return FALSE; break; - case 64: + case ELFCLASS64: if (note->descsz < 120) return FALSE; break; @@ -9771,7 +9771,7 @@ elfcore_grok_freebsd_psinfo (bfd *abfd, Elf_Internal_Note *note) offset = 4; /* Skip over pr_psinfosz. */ - if (abfd->arch_info->bits_per_word == 32) + if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS32) offset += 4; else { @@ -9814,13 +9814,13 @@ elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note) offset = 4; /* Skip over pr_statussz. */ - switch (abfd->arch_info->bits_per_word) + switch (elf_elfheader (abfd)->e_ident[EI_CLASS]) { - case 32: + case ELFCLASS32: offset += 4; break; - case 64: + case ELFCLASS64: offset += 4; /* Padding before pr_statussz. */ offset += 8; break; @@ -9830,13 +9830,16 @@ elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note) } /* Extract size of pr_reg from pr_gregsetsz. */ - if (abfd->arch_info->bits_per_word == 32) + if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS32) size = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + offset); else size = bfd_h_get_64 (abfd, (bfd_byte *) note->descdata + offset); /* Skip over pr_gregsetsz and pr_fpregsetsz. */ - offset += (abfd->arch_info->bits_per_word / 8) * 2; + if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS32) + offset += 4 * 2; + else + offset += 8 * 2; /* Skip over pr_osreldate. */ offset += 4; @@ -9853,7 +9856,7 @@ elfcore_grok_freebsd_prstatus (bfd *abfd, Elf_Internal_Note *note) offset += 4; /* Padding before pr_reg. */ - if (abfd->arch_info->bits_per_word == 64) + if (elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) offset += 4; /* Make a ".reg/999" section and a ".reg" section. */