[v2] MIPS: make mipsisa32 and mipsisa64 link more systematic

Message ID 20230302015222.291088-1-yunqiang.su@cipunited.com
State Accepted
Headers
Series [v2] MIPS: make mipsisa32 and mipsisa64 link more systematic |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

YunQiang Su March 2, 2023, 1:52 a.m. UTC
  Introduce `static const struct mips_mach_extension mips_mach_32_64[]`
and `mips_mach_extends_32_64 (unsigned long base, unsigned long extension)`,
to make mipsisa32 and mipsisa64 interlink more systemtic.

Normally, the ISA mipsisa64rN has two subset: mipsisa64r(N-1) and
mipsisa32rN. `mips_mach_extensions` can hold only mipsisa64r(N-1),
so we need to introduce a new instruction `mips_mach_32_64`, which holds the pair 32vs64.

Note: R6 is not compatible with pre-R6.

bfd/ChangeLog:

	* elfxx-mips.c (mips_mach_extends_p): make mipsisa32 and
	  mipsisa64 interlink more systematic.
	  (mips_mach_32_64): new struct added.
	  (mips_mach_extends_32_64): new function added.
---
 bfd/elfxx-mips.c | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
  

Comments

YunQiang Su March 5, 2023, 1:38 p.m. UTC | #1
@Rickard can you help to submit this patch to git?
I have no permission to do so.

YunQiang Su <yunqiang.su@cipunited.com> 于2023年3月2日周四 09:52写道:
>
> Introduce `static const struct mips_mach_extension mips_mach_32_64[]`
> and `mips_mach_extends_32_64 (unsigned long base, unsigned long extension)`,
> to make mipsisa32 and mipsisa64 interlink more systemtic.
>
> Normally, the ISA mipsisa64rN has two subset: mipsisa64r(N-1) and
> mipsisa32rN. `mips_mach_extensions` can hold only mipsisa64r(N-1),
> so we need to introduce a new instruction `mips_mach_32_64`, which holds the pair 32vs64.
>
> Note: R6 is not compatible with pre-R6.
>
> bfd/ChangeLog:
>
>         * elfxx-mips.c (mips_mach_extends_p): make mipsisa32 and
>           mipsisa64 interlink more systematic.
>           (mips_mach_32_64): new struct added.
>           (mips_mach_extends_32_64): new function added.
> ---
>  bfd/elfxx-mips.c | 40 +++++++++++++++++++++++++++++-----------
>  1 file changed, 29 insertions(+), 11 deletions(-)
>
> diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
> index 35bbd86044b..21e6396609b 100644
> --- a/bfd/elfxx-mips.c
> +++ b/bfd/elfxx-mips.c
> @@ -14524,6 +14524,16 @@ struct mips_mach_extension
>    unsigned long extension, base;
>  };
>
> +/* An array that maps 64-bit architectures to the corresponding 32-bit
> +   architectures.  */
> +static const struct mips_mach_extension mips_mach_32_64[] =
> +{
> +  { bfd_mach_mipsisa64r6, bfd_mach_mipsisa32r6 },
> +  { bfd_mach_mipsisa64r5, bfd_mach_mipsisa32r5 },
> +  { bfd_mach_mipsisa64r3, bfd_mach_mipsisa32r3 },
> +  { bfd_mach_mipsisa64r2, bfd_mach_mipsisa32r2 },
> +  { bfd_mach_mipsisa64,   bfd_mach_mipsisa32 }
> +};
>
>  /* An array describing how BFD machines relate to one another.  The entries
>     are ordered topologically with MIPS I extensions listed last.  */
> @@ -14601,29 +14611,37 @@ static const struct mips_mach_extension mips_mach_extensions[] =
>    { bfd_mach_mips3900, bfd_mach_mips3000 }
>  };
>
> -/* Return true if bfd machine EXTENSION is an extension of machine BASE.  */
> +/* Return true if bfd machine EXTENSION is the same as BASE, or if
> +   EXTENSION is the 64-bit equivalent of a 32-bit BASE.  */
> +
> +static bool
> +mips_mach_extends_32_64 (unsigned long base, unsigned long extension)
> +{
> +  size_t i;
> +
> +  if (extension == base)
> +    return true;
> +
> +  for (i = 0; i < ARRAY_SIZE (mips_mach_64_32); i++)
> +    if (extension == mips_mach_32_64[i].extension)
> +      return base == mips_mach_32_64[i].base;
> +
> +  return false;
> +}
>
>  static bool
>  mips_mach_extends_p (unsigned long base, unsigned long extension)
>  {
>    size_t i;
>
> -  if (extension == base)
> -    return true;
> -
> -  if (base == bfd_mach_mipsisa32
> -      && mips_mach_extends_p (bfd_mach_mipsisa64, extension))
> -    return true;
> -
> -  if (base == bfd_mach_mipsisa32r2
> -      && mips_mach_extends_p (bfd_mach_mipsisa64r2, extension))
> +  if (mips_mach_extends_32_64 (base, extension))
>      return true;
>
>    for (i = 0; i < ARRAY_SIZE (mips_mach_extensions); i++)
>      if (extension == mips_mach_extensions[i].extension)
>        {
>         extension = mips_mach_extensions[i].base;
> -       if (extension == base)
> +       if (mips_mach_extends_32_64 (base, extension))
>           return true;
>        }
>
> --
> 2.30.2
>
  
YunQiang Su March 20, 2023, 1:32 a.m. UTC | #2
ping

YunQiang Su <syq@debian.org> 于2023年3月5日周日 21:38写道:
>
> @Rickard can you help to submit this patch to git?
> I have no permission to do so.
>
> YunQiang Su <yunqiang.su@cipunited.com> 于2023年3月2日周四 09:52写道:
> >
> > Introduce `static const struct mips_mach_extension mips_mach_32_64[]`
> > and `mips_mach_extends_32_64 (unsigned long base, unsigned long extension)`,
> > to make mipsisa32 and mipsisa64 interlink more systemtic.
> >
> > Normally, the ISA mipsisa64rN has two subset: mipsisa64r(N-1) and
> > mipsisa32rN. `mips_mach_extensions` can hold only mipsisa64r(N-1),
> > so we need to introduce a new instruction `mips_mach_32_64`, which holds the pair 32vs64.
> >
> > Note: R6 is not compatible with pre-R6.
> >
> > bfd/ChangeLog:
> >
> >         * elfxx-mips.c (mips_mach_extends_p): make mipsisa32 and
> >           mipsisa64 interlink more systematic.
> >           (mips_mach_32_64): new struct added.
> >           (mips_mach_extends_32_64): new function added.
> > ---
> >  bfd/elfxx-mips.c | 40 +++++++++++++++++++++++++++++-----------
> >  1 file changed, 29 insertions(+), 11 deletions(-)
> >
> > diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
> > index 35bbd86044b..21e6396609b 100644
> > --- a/bfd/elfxx-mips.c
> > +++ b/bfd/elfxx-mips.c
> > @@ -14524,6 +14524,16 @@ struct mips_mach_extension
> >    unsigned long extension, base;
> >  };
> >
> > +/* An array that maps 64-bit architectures to the corresponding 32-bit
> > +   architectures.  */
> > +static const struct mips_mach_extension mips_mach_32_64[] =
> > +{
> > +  { bfd_mach_mipsisa64r6, bfd_mach_mipsisa32r6 },
> > +  { bfd_mach_mipsisa64r5, bfd_mach_mipsisa32r5 },
> > +  { bfd_mach_mipsisa64r3, bfd_mach_mipsisa32r3 },
> > +  { bfd_mach_mipsisa64r2, bfd_mach_mipsisa32r2 },
> > +  { bfd_mach_mipsisa64,   bfd_mach_mipsisa32 }
> > +};
> >
> >  /* An array describing how BFD machines relate to one another.  The entries
> >     are ordered topologically with MIPS I extensions listed last.  */
> > @@ -14601,29 +14611,37 @@ static const struct mips_mach_extension mips_mach_extensions[] =
> >    { bfd_mach_mips3900, bfd_mach_mips3000 }
> >  };
> >
> > -/* Return true if bfd machine EXTENSION is an extension of machine BASE.  */
> > +/* Return true if bfd machine EXTENSION is the same as BASE, or if
> > +   EXTENSION is the 64-bit equivalent of a 32-bit BASE.  */
> > +
> > +static bool
> > +mips_mach_extends_32_64 (unsigned long base, unsigned long extension)
> > +{
> > +  size_t i;
> > +
> > +  if (extension == base)
> > +    return true;
> > +
> > +  for (i = 0; i < ARRAY_SIZE (mips_mach_64_32); i++)
> > +    if (extension == mips_mach_32_64[i].extension)
> > +      return base == mips_mach_32_64[i].base;
> > +
> > +  return false;
> > +}
> >
> >  static bool
> >  mips_mach_extends_p (unsigned long base, unsigned long extension)
> >  {
> >    size_t i;
> >
> > -  if (extension == base)
> > -    return true;
> > -
> > -  if (base == bfd_mach_mipsisa32
> > -      && mips_mach_extends_p (bfd_mach_mipsisa64, extension))
> > -    return true;
> > -
> > -  if (base == bfd_mach_mipsisa32r2
> > -      && mips_mach_extends_p (bfd_mach_mipsisa64r2, extension))
> > +  if (mips_mach_extends_32_64 (base, extension))
> >      return true;
> >
> >    for (i = 0; i < ARRAY_SIZE (mips_mach_extensions); i++)
> >      if (extension == mips_mach_extensions[i].extension)
> >        {
> >         extension = mips_mach_extensions[i].base;
> > -       if (extension == base)
> > +       if (mips_mach_extends_32_64 (base, extension))
> >           return true;
> >        }
> >
> > --
> > 2.30.2
> >
  
YunQiang Su April 3, 2023, 3:59 a.m. UTC | #3
ping

YunQiang Su <syq@debian.org> 于2023年3月20日周一 09:32写道:
>
> ping
>
> YunQiang Su <syq@debian.org> 于2023年3月5日周日 21:38写道:
> >
> > @Rickard can you help to submit this patch to git?
> > I have no permission to do so.
> >
> > YunQiang Su <yunqiang.su@cipunited.com> 于2023年3月2日周四 09:52写道:
> > >
> > > Introduce `static const struct mips_mach_extension mips_mach_32_64[]`
> > > and `mips_mach_extends_32_64 (unsigned long base, unsigned long extension)`,
> > > to make mipsisa32 and mipsisa64 interlink more systemtic.
> > >
> > > Normally, the ISA mipsisa64rN has two subset: mipsisa64r(N-1) and
> > > mipsisa32rN. `mips_mach_extensions` can hold only mipsisa64r(N-1),
> > > so we need to introduce a new instruction `mips_mach_32_64`, which holds the pair 32vs64.
> > >
> > > Note: R6 is not compatible with pre-R6.
> > >
> > > bfd/ChangeLog:
> > >
> > >         * elfxx-mips.c (mips_mach_extends_p): make mipsisa32 and
> > >           mipsisa64 interlink more systematic.
> > >           (mips_mach_32_64): new struct added.
> > >           (mips_mach_extends_32_64): new function added.
> > > ---
> > >  bfd/elfxx-mips.c | 40 +++++++++++++++++++++++++++++-----------
> > >  1 file changed, 29 insertions(+), 11 deletions(-)
> > >
> > > diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
> > > index 35bbd86044b..21e6396609b 100644
> > > --- a/bfd/elfxx-mips.c
> > > +++ b/bfd/elfxx-mips.c
> > > @@ -14524,6 +14524,16 @@ struct mips_mach_extension
> > >    unsigned long extension, base;
> > >  };
> > >
> > > +/* An array that maps 64-bit architectures to the corresponding 32-bit
> > > +   architectures.  */
> > > +static const struct mips_mach_extension mips_mach_32_64[] =
> > > +{
> > > +  { bfd_mach_mipsisa64r6, bfd_mach_mipsisa32r6 },
> > > +  { bfd_mach_mipsisa64r5, bfd_mach_mipsisa32r5 },
> > > +  { bfd_mach_mipsisa64r3, bfd_mach_mipsisa32r3 },
> > > +  { bfd_mach_mipsisa64r2, bfd_mach_mipsisa32r2 },
> > > +  { bfd_mach_mipsisa64,   bfd_mach_mipsisa32 }
> > > +};
> > >
> > >  /* An array describing how BFD machines relate to one another.  The entries
> > >     are ordered topologically with MIPS I extensions listed last.  */
> > > @@ -14601,29 +14611,37 @@ static const struct mips_mach_extension mips_mach_extensions[] =
> > >    { bfd_mach_mips3900, bfd_mach_mips3000 }
> > >  };
> > >
> > > -/* Return true if bfd machine EXTENSION is an extension of machine BASE.  */
> > > +/* Return true if bfd machine EXTENSION is the same as BASE, or if
> > > +   EXTENSION is the 64-bit equivalent of a 32-bit BASE.  */
> > > +
> > > +static bool
> > > +mips_mach_extends_32_64 (unsigned long base, unsigned long extension)
> > > +{
> > > +  size_t i;
> > > +
> > > +  if (extension == base)
> > > +    return true;
> > > +
> > > +  for (i = 0; i < ARRAY_SIZE (mips_mach_64_32); i++)
> > > +    if (extension == mips_mach_32_64[i].extension)
> > > +      return base == mips_mach_32_64[i].base;
> > > +
> > > +  return false;
> > > +}
> > >
> > >  static bool
> > >  mips_mach_extends_p (unsigned long base, unsigned long extension)
> > >  {
> > >    size_t i;
> > >
> > > -  if (extension == base)
> > > -    return true;
> > > -
> > > -  if (base == bfd_mach_mipsisa32
> > > -      && mips_mach_extends_p (bfd_mach_mipsisa64, extension))
> > > -    return true;
> > > -
> > > -  if (base == bfd_mach_mipsisa32r2
> > > -      && mips_mach_extends_p (bfd_mach_mipsisa64r2, extension))
> > > +  if (mips_mach_extends_32_64 (base, extension))
> > >      return true;
> > >
> > >    for (i = 0; i < ARRAY_SIZE (mips_mach_extensions); i++)
> > >      if (extension == mips_mach_extensions[i].extension)
> > >        {
> > >         extension = mips_mach_extensions[i].base;
> > > -       if (extension == base)
> > > +       if (mips_mach_extends_32_64 (base, extension))
> > >           return true;
> > >        }
> > >
> > > --
> > > 2.30.2
> > >
  
Richard Sandiford April 3, 2023, 2:03 p.m. UTC | #4
YunQiang Su <yunqiang.su@cipunited.com> writes:
> Introduce `static const struct mips_mach_extension mips_mach_32_64[]`
> and `mips_mach_extends_32_64 (unsigned long base, unsigned long extension)`,
> to make mipsisa32 and mipsisa64 interlink more systemtic.
>
> Normally, the ISA mipsisa64rN has two subset: mipsisa64r(N-1) and
> mipsisa32rN. `mips_mach_extensions` can hold only mipsisa64r(N-1),
> so we need to introduce a new instruction `mips_mach_32_64`, which holds the pair 32vs64.
>
> Note: R6 is not compatible with pre-R6.
>
> bfd/ChangeLog:
>
> 	* elfxx-mips.c (mips_mach_extends_p): make mipsisa32 and
> 	  mipsisa64 interlink more systematic.
> 	  (mips_mach_32_64): new struct added.
> 	  (mips_mach_extends_32_64): new function added.

Sorry for the delay in pushing this.  Could you check whether it's
the right version though?  When I build locally I get:

> ---
>  bfd/elfxx-mips.c | 40 +++++++++++++++++++++++++++++-----------
>  1 file changed, 29 insertions(+), 11 deletions(-)
>
> diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
> index 35bbd86044b..21e6396609b 100644
> --- a/bfd/elfxx-mips.c
> +++ b/bfd/elfxx-mips.c
> @@ -14524,6 +14524,16 @@ struct mips_mach_extension
>    unsigned long extension, base;
>  };
>  
> +/* An array that maps 64-bit architectures to the corresponding 32-bit
> +   architectures.  */
> +static const struct mips_mach_extension mips_mach_32_64[] =
> +{
> +  { bfd_mach_mipsisa64r6, bfd_mach_mipsisa32r6 },
> +  { bfd_mach_mipsisa64r5, bfd_mach_mipsisa32r5 },
> +  { bfd_mach_mipsisa64r3, bfd_mach_mipsisa32r3 },
> +  { bfd_mach_mipsisa64r2, bfd_mach_mipsisa32r2 },
> +  { bfd_mach_mipsisa64,   bfd_mach_mipsisa32 }
> +};
>  
>  /* An array describing how BFD machines relate to one another.  The entries
>     are ordered topologically with MIPS I extensions listed last.  */
> @@ -14601,29 +14611,37 @@ static const struct mips_mach_extension mips_mach_extensions[] =
>    { bfd_mach_mips3900, bfd_mach_mips3000 }
>  };
>  
> -/* Return true if bfd machine EXTENSION is an extension of machine BASE.  */
> +/* Return true if bfd machine EXTENSION is the same as BASE, or if
> +   EXTENSION is the 64-bit equivalent of a 32-bit BASE.  */
> +
> +static bool
> +mips_mach_extends_32_64 (unsigned long base, unsigned long extension)
> +{
> +  size_t i;
> +
> +  if (extension == base)
> +    return true;
> +
> +  for (i = 0; i < ARRAY_SIZE (mips_mach_64_32); i++)

error: ‘mips_mach_64_32’ undeclared (first use in this function); did you mean ‘mips_mach_32_64’?

It looks like the previous patch had the same thing (sorry for not
noticing).  Obviously it's a simple fix, but it would be good to have
some reassurance that the patch has been tested beyond my crude sanity
checks.

Thanks,
Richard

> +    if (extension == mips_mach_32_64[i].extension)
> +      return base == mips_mach_32_64[i].base;
> +
> +  return false;
> +}
>  
>  static bool
>  mips_mach_extends_p (unsigned long base, unsigned long extension)
>  {
>    size_t i;
>  
> -  if (extension == base)
> -    return true;
> -
> -  if (base == bfd_mach_mipsisa32
> -      && mips_mach_extends_p (bfd_mach_mipsisa64, extension))
> -    return true;
> -
> -  if (base == bfd_mach_mipsisa32r2
> -      && mips_mach_extends_p (bfd_mach_mipsisa64r2, extension))
> +  if (mips_mach_extends_32_64 (base, extension))
>      return true;
>  
>    for (i = 0; i < ARRAY_SIZE (mips_mach_extensions); i++)
>      if (extension == mips_mach_extensions[i].extension)
>        {
>  	extension = mips_mach_extensions[i].base;



> -	if (extension == base)
> +	if (mips_mach_extends_32_64 (base, extension))
>  	  return true;
>        }
  
YunQiang Su April 10, 2023, 6:48 a.m. UTC | #5
Richard Sandiford <richard.sandiford@arm.com> 于2023年4月3日周一 22:03写道:
>
> YunQiang Su <yunqiang.su@cipunited.com> writes:
> > Introduce `static const struct mips_mach_extension mips_mach_32_64[]`
> > and `mips_mach_extends_32_64 (unsigned long base, unsigned long extension)`,
> > to make mipsisa32 and mipsisa64 interlink more systemtic.
> >
> > Normally, the ISA mipsisa64rN has two subset: mipsisa64r(N-1) and
> > mipsisa32rN. `mips_mach_extensions` can hold only mipsisa64r(N-1),
> > so we need to introduce a new instruction `mips_mach_32_64`, which holds the pair 32vs64.
> >
> > Note: R6 is not compatible with pre-R6.
> >
> > bfd/ChangeLog:
> >
> >       * elfxx-mips.c (mips_mach_extends_p): make mipsisa32 and
> >         mipsisa64 interlink more systematic.
> >         (mips_mach_32_64): new struct added.
> >         (mips_mach_extends_32_64): new function added.
>
> Sorry for the delay in pushing this.  Could you check whether it's
> the right version though?  When I build locally I get:
>
> > ---
> >  bfd/elfxx-mips.c | 40 +++++++++++++++++++++++++++++-----------
> >  1 file changed, 29 insertions(+), 11 deletions(-)
> >
> > diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
> > index 35bbd86044b..21e6396609b 100644
> > --- a/bfd/elfxx-mips.c
> > +++ b/bfd/elfxx-mips.c
> > @@ -14524,6 +14524,16 @@ struct mips_mach_extension
> >    unsigned long extension, base;
> >  };
> >
> > +/* An array that maps 64-bit architectures to the corresponding 32-bit
> > +   architectures.  */
> > +static const struct mips_mach_extension mips_mach_32_64[] =
> > +{
> > +  { bfd_mach_mipsisa64r6, bfd_mach_mipsisa32r6 },
> > +  { bfd_mach_mipsisa64r5, bfd_mach_mipsisa32r5 },
> > +  { bfd_mach_mipsisa64r3, bfd_mach_mipsisa32r3 },
> > +  { bfd_mach_mipsisa64r2, bfd_mach_mipsisa32r2 },
> > +  { bfd_mach_mipsisa64,   bfd_mach_mipsisa32 }
> > +};
> >
> >  /* An array describing how BFD machines relate to one another.  The entries
> >     are ordered topologically with MIPS I extensions listed last.  */
> > @@ -14601,29 +14611,37 @@ static const struct mips_mach_extension mips_mach_extensions[] =
> >    { bfd_mach_mips3900, bfd_mach_mips3000 }
> >  };
> >
> > -/* Return true if bfd machine EXTENSION is an extension of machine BASE.  */
> > +/* Return true if bfd machine EXTENSION is the same as BASE, or if
> > +   EXTENSION is the 64-bit equivalent of a 32-bit BASE.  */
> > +
> > +static bool
> > +mips_mach_extends_32_64 (unsigned long base, unsigned long extension)
> > +{
> > +  size_t i;
> > +
> > +  if (extension == base)
> > +    return true;
> > +
> > +  for (i = 0; i < ARRAY_SIZE (mips_mach_64_32); i++)
>
> error: ‘mips_mach_64_32’ undeclared (first use in this function); did you mean ‘mips_mach_32_64’?
>
> It looks like the previous patch had the same thing (sorry for not
> noticing).  Obviously it's a simple fix, but it would be good to have
> some reassurance that the patch has been tested beyond my crude sanity
> checks.
>
Yes, it is a typo.
Sorry for it. I won't happen anymore...

> Thanks,
> Richard
>
> > +    if (extension == mips_mach_32_64[i].extension)
> > +      return base == mips_mach_32_64[i].base;
> > +
> > +  return false;
> > +}
> >
> >  static bool
> >  mips_mach_extends_p (unsigned long base, unsigned long extension)
> >  {
> >    size_t i;
> >
> > -  if (extension == base)
> > -    return true;
> > -
> > -  if (base == bfd_mach_mipsisa32
> > -      && mips_mach_extends_p (bfd_mach_mipsisa64, extension))
> > -    return true;
> > -
> > -  if (base == bfd_mach_mipsisa32r2
> > -      && mips_mach_extends_p (bfd_mach_mipsisa64r2, extension))
> > +  if (mips_mach_extends_32_64 (base, extension))
> >      return true;
> >
> >    for (i = 0; i < ARRAY_SIZE (mips_mach_extensions); i++)
> >      if (extension == mips_mach_extensions[i].extension)
> >        {
> >       extension = mips_mach_extensions[i].base;
>
>
>
> > -     if (extension == base)
> > +     if (mips_mach_extends_32_64 (base, extension))
> >         return true;
> >        }
  

Patch

diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 35bbd86044b..21e6396609b 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -14524,6 +14524,16 @@  struct mips_mach_extension
   unsigned long extension, base;
 };
 
+/* An array that maps 64-bit architectures to the corresponding 32-bit
+   architectures.  */
+static const struct mips_mach_extension mips_mach_32_64[] =
+{
+  { bfd_mach_mipsisa64r6, bfd_mach_mipsisa32r6 },
+  { bfd_mach_mipsisa64r5, bfd_mach_mipsisa32r5 },
+  { bfd_mach_mipsisa64r3, bfd_mach_mipsisa32r3 },
+  { bfd_mach_mipsisa64r2, bfd_mach_mipsisa32r2 },
+  { bfd_mach_mipsisa64,   bfd_mach_mipsisa32 }
+};
 
 /* An array describing how BFD machines relate to one another.  The entries
    are ordered topologically with MIPS I extensions listed last.  */
@@ -14601,29 +14611,37 @@  static const struct mips_mach_extension mips_mach_extensions[] =
   { bfd_mach_mips3900, bfd_mach_mips3000 }
 };
 
-/* Return true if bfd machine EXTENSION is an extension of machine BASE.  */
+/* Return true if bfd machine EXTENSION is the same as BASE, or if
+   EXTENSION is the 64-bit equivalent of a 32-bit BASE.  */
+
+static bool
+mips_mach_extends_32_64 (unsigned long base, unsigned long extension)
+{
+  size_t i;
+
+  if (extension == base)
+    return true;
+
+  for (i = 0; i < ARRAY_SIZE (mips_mach_64_32); i++)
+    if (extension == mips_mach_32_64[i].extension)
+      return base == mips_mach_32_64[i].base;
+
+  return false;
+}
 
 static bool
 mips_mach_extends_p (unsigned long base, unsigned long extension)
 {
   size_t i;
 
-  if (extension == base)
-    return true;
-
-  if (base == bfd_mach_mipsisa32
-      && mips_mach_extends_p (bfd_mach_mipsisa64, extension))
-    return true;
-
-  if (base == bfd_mach_mipsisa32r2
-      && mips_mach_extends_p (bfd_mach_mipsisa64r2, extension))
+  if (mips_mach_extends_32_64 (base, extension))
     return true;
 
   for (i = 0; i < ARRAY_SIZE (mips_mach_extensions); i++)
     if (extension == mips_mach_extensions[i].extension)
       {
 	extension = mips_mach_extensions[i].base;
-	if (extension == base)
+	if (mips_mach_extends_32_64 (base, extension))
 	  return true;
       }