public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: mengqinggang <mengqinggang@loongson.cn>
To: binutils@sourceware.org
Cc: liuzhensong@loongson.cn, xry111@xry111.site, i.swmail@xen0n.name,
	maskray@google.com, mengqinggang <mengqinggang@loongson.cn>
Subject: [PATCH] LoongArch: fix gas BFD_RELOC_8/16/24 bug
Date: Wed, 24 Aug 2022 15:41:56 +0800	[thread overview]
Message-ID: <20220824074156.3330005-1-mengqinggang@loongson.cn> (raw)

If fixP->fx_subsy is NULL, BFD_RELOC_8/16/24 can't convert to
BFD_RELOC_LARCH_xxx.

gas/config/tc-loongarch.c
---
 gas/config/tc-loongarch.c | 59 +++++++++++++++++++++++++++------------
 1 file changed, 41 insertions(+), 18 deletions(-)

diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index fbbaca55085..6baefa45f90 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -1157,10 +1157,6 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 
     case BFD_RELOC_64:
     case BFD_RELOC_32:
-    case BFD_RELOC_24:
-    case BFD_RELOC_16:
-    case BFD_RELOC_8:
-
       if (fixP->fx_r_type == BFD_RELOC_32
 	  && fixP->fx_addsy && fixP->fx_subsy
 	  && (sub_segment = S_GET_SEGMENT (fixP->fx_subsy))
@@ -1191,25 +1187,52 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
 	      fixP->fx_r_type = BFD_RELOC_LARCH_ADD32;
 	      fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB32;
 	      break;
-	    case BFD_RELOC_24:
-	      fixP->fx_r_type = BFD_RELOC_LARCH_ADD24;
-	      fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB24;
-	      break;
-	    case BFD_RELOC_16:
-	      fixP->fx_r_type = BFD_RELOC_LARCH_ADD16;
-	      fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB16;
-	      break;
-	    case BFD_RELOC_8:
-	      fixP->fx_r_type = BFD_RELOC_LARCH_ADD8;
-	      fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB8;
-	      break;
 	    default:
 	      break;
 	    }
+
 	  md_number_to_chars (buf, 0, fixP->fx_size);
-	  if (fixP->fx_next->fx_addsy == NULL)
-	    fixP->fx_next->fx_done = 1;
 	}
+
+      if (fixP->fx_addsy == NULL)
+	{
+	  fixP->fx_done = 1;
+	  md_number_to_chars (buf, *valP, fixP->fx_size);
+	}
+      break;
+
+    case BFD_RELOC_24:
+    case BFD_RELOC_16:
+    case BFD_RELOC_8:
+      fixP->fx_next = xmemdup (fixP, sizeof (*fixP), sizeof (*fixP));
+      fixP->fx_next->fx_addsy = fixP->fx_subsy;
+      fixP->fx_next->fx_subsy = NULL;
+      fixP->fx_next->fx_offset = 0;
+      fixP->fx_subsy = NULL;
+
+      switch (fixP->fx_r_type)
+	{
+	case BFD_RELOC_24:
+	  fixP->fx_r_type = BFD_RELOC_LARCH_ADD24;
+	  fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB24;
+	  break;
+	case BFD_RELOC_16:
+	  fixP->fx_r_type = BFD_RELOC_LARCH_ADD16;
+	  fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB16;
+	  break;
+	case BFD_RELOC_8:
+	  fixP->fx_r_type = BFD_RELOC_LARCH_ADD8;
+	  fixP->fx_next->fx_r_type = BFD_RELOC_LARCH_SUB8;
+	  break;
+	default:
+	  break;
+	}
+
+      md_number_to_chars (buf, 0, fixP->fx_size);
+
+      if (fixP->fx_next->fx_addsy == NULL)
+	fixP->fx_next->fx_done = 1;
+
       if (fixP->fx_addsy == NULL)
 	{
 	  fixP->fx_done = 1;
-- 
2.36.0


             reply	other threads:[~2022-08-24  7:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-24  7:41 mengqinggang [this message]
2022-08-30  8:27 mengqinggang

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=20220824074156.3330005-1-mengqinggang@loongson.cn \
    --to=mengqinggang@loongson.cn \
    --cc=binutils@sourceware.org \
    --cc=i.swmail@xen0n.name \
    --cc=liuzhensong@loongson.cn \
    --cc=maskray@google.com \
    --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).