Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: John Baldwin <jhb@freebsd.org>
To: Nick Clifton <nickc@redhat.com>
Cc: gdb-patches@sourceware.org, binutils@sourceware.org
Subject: Re: [PATCH v2 1/3] Use the ELF class to determine the word size for FreeBSD core notes.
Date: Fri, 23 Dec 2016 20:35:00 -0000	[thread overview]
Message-ID: <1829689.DkhP3uyY6r@ralph.baldwin.cx> (raw)
In-Reply-To: <a2766669-a187-5623-28cd-7672ba1b27d2@redhat.com>

On Tuesday, December 13, 2016 11:04:40 AM Nick Clifton wrote:
> Hi John,
> 
> > FreeBSD MIPS64 core dumps contain an empty e_flags value so are assigned
> > to the default bfd_arch_mips which is 32-bits.
> 
> I am sorry, but I am worried about this patch breaking things for other,
> non-MIPS targets.  Wouldn't it be easier to update bfd/elfxx-mips.c:_bfd_elf_mips_mach()
> to test the EI_CLASS field if no flags are set.  Maybe by using the ABI_64_P macro ?

I agree and would rather choose a 64-bit MIPS default bfd_arch_mips in
this case if possible.  I wasn't sure how to go about that and if
doing so would break other things (whereas the function I changed
should only break things on FreeBSD if it is wrong since it controls
parsing of FreeBSD-specific notes).

Here is a patch that does that.  I have some other things to respin for
a v3 on the GDB side, but am including this inline to see what you think:

(In particular, with an empty flags value of 0, the arch field of the
flags is E_MIPS_ARCH_1 since E_MIPS_ARCH_1 is 0)

diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c
index d398810..1ba7042 100644
--- a/bfd/elf32-mips.c
+++ b/bfd/elf32-mips.c
@@ -2295,7 +2295,7 @@ mips_elf32_object_p (bfd *abfd)
   if (SGI_COMPAT (abfd))
     elf_bad_symtab (abfd) = TRUE;
 
-  mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
+  mach = _bfd_elf_mips_mach (abfd);
   bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
   return TRUE;
 }
diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c
index 8cd0a73..10ab5e9 100644
--- a/bfd/elf64-mips.c
+++ b/bfd/elf64-mips.c
@@ -4251,7 +4251,7 @@ mips_elf64_object_p (bfd *abfd)
   if (elf64_mips_irix_compat (abfd) != ict_none)
     elf_bad_symtab (abfd) = TRUE;
 
-  mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
+  mach = _bfd_elf_mips_mach (abfd);
   bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
   return TRUE;
 }
diff --git a/bfd/elfn32-mips.c b/bfd/elfn32-mips.c
index c7ca646..2864d09 100644
--- a/bfd/elfn32-mips.c
+++ b/bfd/elfn32-mips.c
@@ -3513,7 +3513,7 @@ mips_elf_n32_object_p (bfd *abfd)
   if (SGI_COMPAT (abfd))
     elf_bad_symtab (abfd) = TRUE;
 
-  mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags);
+  mach = _bfd_elf_mips_mach (abfd);
   bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach);
   return TRUE;
 }
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 96317aa..9b25303 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -6721,8 +6721,10 @@ mips_elf_create_dynamic_relocation (bfd *output_bfd,
 /* Return the MACH for a MIPS e_flags value.  */
 
 unsigned long
-_bfd_elf_mips_mach (flagword flags)
+_bfd_elf_mips_mach (bfd *abfd)
 {
+  flagword flags = elf_elfheader (abfd)->e_flags;
+
   switch (flags & EF_MIPS_MACH)
     {
     case E_MIPS_MACH_3900:
@@ -6784,7 +6786,10 @@ _bfd_elf_mips_mach (flagword flags)
        {
        default:
        case E_MIPS_ARCH_1:
-         return bfd_mach_mips3000;
+         if (ABI_64_P (abfd))
+           return bfd_mach_mips4000;
+         else
+           return bfd_mach_mips3000;
 
        case E_MIPS_ARCH_2:
          return bfd_mach_mips6000;
@@ -6817,8 +6822,6 @@ _bfd_elf_mips_mach (flagword flags)
          return bfd_mach_mipsisa64r6;
        }
     }
-
-  return 0;
 }
 
 /* Return printable name for ABI.  */
diff --git a/bfd/elfxx-mips.h b/bfd/elfxx-mips.h
index 8ea7b0f..be95a1b 100644
--- a/bfd/elfxx-mips.h
+++ b/bfd/elfxx-mips.h
@@ -138,7 +138,7 @@ extern bfd_reloc_status_type _bfd_mips_elf_lo16_reloc
 extern bfd_reloc_status_type _bfd_mips_elf_generic_reloc
   (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
 extern unsigned long _bfd_elf_mips_mach
-  (flagword);
+  (bfd *);
 extern bfd_boolean _bfd_mips_relax_section
   (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
 extern bfd_vma _bfd_mips_elf_sign_extend


-- 
John Baldwin


  reply	other threads:[~2016-12-23 20:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06 21:01 [PATCH v2 0/3] Add FreeBSD/mips targets to GDB John Baldwin
2016-12-06 21:01 ` [PATCH v2 1/3] Use the ELF class to determine the word size for FreeBSD core notes John Baldwin
2016-12-13 11:04   ` Nick Clifton
2016-12-23 20:35     ` John Baldwin [this message]
2016-12-06 21:01 ` [PATCH v2 2/3] Add FreeBSD/mips architecture John Baldwin
2016-12-08 18:47   ` Luis Machado
2016-12-08 20:08     ` John Baldwin
2016-12-08 20:13       ` Luis Machado
2016-12-09 19:02         ` John Baldwin
2016-12-16 12:22   ` GDB attribution policy (Re: [PATCH v2 2/3] Add FreeBSD/mips architecture.) Pedro Alves
2017-01-10 16:19     ` Pedro Alves
2016-12-06 21:01 ` [PATCH v2 3/3] Add native target for FreeBSD/mips John Baldwin
2016-12-08 18:53   ` Luis Machado
2016-12-08 20:09     ` John Baldwin
2016-12-08 20:15       ` Luis Machado
2016-12-16 12:50 ` [PATCH v2 0/3] Add FreeBSD/mips targets to GDB Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1829689.DkhP3uyY6r@ralph.baldwin.cx \
    --to=jhb@freebsd.org \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    --cc=nickc@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox