This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] rl78: check for overlong branches


I hesitate to check for overflow on the non-pcrel options, because
I've seen gcc take advantage of silent overflow when comparing
pointers to constant ranges.  Committed.

	* config/tc-rl78.c (md_apply_fix): Add overflow warnings for
	pc-relative branches.

diff --git a/gas/config/tc-rl78.c b/gas/config/tc-rl78.c
index ae8f5af..bbbf47b 100644
--- a/gas/config/tc-rl78.c
+++ b/gas/config/tc-rl78.c
@@ -1310,13 +1310,23 @@ md_apply_fix (struct fix * f ATTRIBUTE_UNUSED,
       f->fx_done = 1;
       break;
 
-    case BFD_RELOC_8:
     case BFD_RELOC_8_PCREL:
+      if ((long)val < -128 || (long)val > 127)
+	as_bad_where (f->fx_file, f->fx_line,
+		      _("value of %ld too large for 8-bit branch"),
+		      val);
+      /* Fall through.  */
+    case BFD_RELOC_8:
       op[0] = val;
       break;
 
-    case BFD_RELOC_16:
     case BFD_RELOC_16_PCREL:
+      if ((long)val < -32768 || (long)val > 32767)
+	as_bad_where (f->fx_file, f->fx_line,
+		      _("value of %ld too large for 16-bit branch"),
+		      val);
+      /* Fall through.  */
+    case BFD_RELOC_16:
     case BFD_RELOC_RL78_CODE:
       op[0] = val;
       op[1] = val >> 8;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]