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][SH] Ensure that offset alignments are valid


Hi,

The attached patch adds an error message, to the SH assembler, rejecting all invalid BFD_RELOC_SH_PCRELIMM8BY4 relocations.

Specifically, the PC to destination offset must not be negative, and the destination must be 4-byte aligned.

At present, incorrect values are silently mis-assembled.

This patch has some fallout in the testsuite results (the arch tests use misaligned targets). I shall fix that up if this patch is OK.

Andrew Stubbs
2008-04-11  Andrew Stubbs  <andrew.stubbs@st.com>

	* config/tc-sh.c (md_apply_fix): Make sure BFD_RELOC_SH_PCRELIMM8BY4
	relocations are properly aligned, and not negative.


Index: src/gas/config/tc-sh.c
===================================================================
--- src.orig/gas/config/tc-sh.c	2007-10-17 17:45:55.000000000 +0100
+++ src/gas/config/tc-sh.c	2008-04-11 15:01:17.000000000 +0100
@@ -4018,6 +4018,17 @@ md_apply_fix (fixS *fixP, valueT *valP, 
       break;
 
     case BFD_RELOC_SH_PCRELIMM8BY4:
+      /* Don't silently move the destination due to misalignment.
+	 The absolute address is the fragment base plus the offset into
+	 the fragment plus the pc relative offset to the label.  */
+      if ((fixP->fx_frag->fr_address + fixP->fx_where + val) & 3)
+	as_bad_where (fixP->fx_file, fixP->fx_line, _("offset to unaligned destination"));
+
+      /* The displacement cannot be zero or backward even if aligned.
+	 Allow -2 because val has already been adjusted somewhere.  */
+      if (val < -2)
+	as_bad_where (fixP->fx_file, fixP->fx_line, _("negative offset"));
+
       /* The lower two bits of the PC are cleared before the
          displacement is added in.  We can assume that the destination
          is on a 4 byte boundary.  If this instruction is also on a 4

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