public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: YunQiang Su <yunqiang.su@cipunited.com>
To: binutils@sourceware.org
Cc: syq@debian.org, macro@orcam.me.uk, xry111@xry111.site,
	richard.sandiford@arm.com, jiaxun.yang@flygoat.com,
	YunQiang Su <yunqiang.su@cipunited.com>
Subject: [PATCH] MIPS: make mipsisa32 and mipsisa64 link more systematic
Date: Tue, 21 Feb 2023 12:06:50 +0800	[thread overview]
Message-ID: <20230221040650.2337395-1-yunqiang.su@cipunited.com> (raw)
In-Reply-To: <20230207024424.4000862-1-yunqiang.su@cipunited.com>

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 | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index e9fb61ff9e7..e9480ea3954 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -14505,6 +14505,16 @@ struct mips_mach_extension
   unsigned long extension, base;
 };
 
+/* An array describing how BFD machines relate to one another. The entries
+   are ordered topologically. */
+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.  */
@@ -14584,27 +14594,35 @@ static const struct mips_mach_extension mips_mach_extensions[] =
 
 /* Return true if bfd machine EXTENSION is an extension of machine 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;
+  unsigned long extension1 = extension;
 
-  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


  parent reply	other threads:[~2023-02-21  4:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-07  2:44 [PATCH] MIPS: allow link o32 objects with mach mips64r6 and mips32r6 YunQiang Su
2023-02-13 15:47 ` Richard Sandiford
2023-02-21  4:06 ` YunQiang Su [this message]
2023-02-27 14:56   ` [PATCH] MIPS: make mipsisa32 and mipsisa64 link more systematic Richard Sandiford
2023-03-02  1:52   ` [PATCH v2] " YunQiang Su
2023-03-05 13:38     ` YunQiang Su
2023-03-20  1:32       ` YunQiang Su
2023-04-03  3:59         ` YunQiang Su
2023-04-03 14:03     ` Richard Sandiford
2023-04-10  6:48       ` YunQiang Su
2023-04-10  6:51       ` [PATCH v3] " YunQiang Su
2023-04-12 12:26         ` Richard Sandiford

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=20230221040650.2337395-1-yunqiang.su@cipunited.com \
    --to=yunqiang.su@cipunited.com \
    --cc=binutils@sourceware.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=macro@orcam.me.uk \
    --cc=richard.sandiford@arm.com \
    --cc=syq@debian.org \
    --cc=xry111@xry111.site \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).