------- Additional Comments From nickc at redhat dot com  2005-05-18 08:42 
-------
Hi Hotti,

  This problem is due to the fact that the assembler does not distinguish
between decimal constants and hexadecimal constants.   The assembler considers
that the following instruction is correct and does not overflow:

  add     %o1, 0x1fff, %o1

ie, the programmer is specifying an exact bit pattern to be used in the
immediate field of the add instruction.  But 0x1fff == 8191, so the assembler
also accepts 8191 in this field.

The assembler could be modified to record whether a constant value was entered
as a decimal value or a hexadecimal value, and this information could be checked
at the time that the range of the value was checked, but this would mean large
changes to the assembler.  I do not believe that such changes are worthwile.  We
are talking assembly language here.  If programmers do not understand the
instruction set that they are using then they should not be programming in
assembler - it is far too low level for beginners.

Feel free to disagree with me however.  There is a simple patch which will fix
the range checking and force it to be 13-bits even for hexadecimal constants:

Index: gas/config/tc-sparc.c
===================================================================
RCS file: /cvs/src/src/gas/config/tc-sparc.c,v
retrieving revision 1.56
diff -c -3 -p -r1.56 tc-sparc.c
*** gas/config/tc-sparc.c       5 May 2005 09:13:03 -0000       1.56
--- gas/config/tc-sparc.c       18 May 2005 08:41:26 -0000
*************** md_apply_fix3 (fixP, valP, segment)
*** 3321,3327 ****
          /* Fall through.  */
  
        case BFD_RELOC_SPARC13:
!         if (! in_signed_range (val, 0x1fff))
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("relocation overflow"));
          insn |= val & 0x1fff;
--- 3321,3327 ----
          /* Fall through.  */
  
        case BFD_RELOC_SPARC13:
!         if (! in_signed_range (val, 0x0fff))
            as_bad_where (fixP->fx_file, fixP->fx_line,
                          _("relocation overflow"));
          insn |= val & 0x1fff;

Cheers
  Nick


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |WAITING


http://sources.redhat.com/bugzilla/show_bug.cgi?id=949

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


_______________________________________________
bug-binutils mailing list
bug-binutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-binutils

Reply via email to