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]

Re: [PATCH] Fix sign-extended immediates for SH on 64-bit host


Matt Fleming <matt@console-pimps.org> wrote:
> it appears that the SH backend for gas has a bug in it that is exposed
> when using a cross-compiled toolchain that is built on a 64-bit host. As
> an example, the assembler does not interpret the immediate constant
> 0xfffffff0 as a negative value when run on a 64-bit machine, rather it
> is zero-extended. The constant is correctly recognised as a negative
> integer on a 32-bit machine.
> 
> The attached patches introduce two new macros, SEXT and TRUNC to
> sign-extend and truncate a long, respectively. Using these macros allows
> us to obtain the same result from using sign-extended immediates on both
> 32-bit and 64-bit hosts.

Thanks for pointing this out.  The intension of your change
is fine, though it's a bit overkill to introduce 2 macros for
this and it would be better to put the comment at md_apply_fix
itself.  Could the attached one liner work for 64-bit host?
Testing patch looks OK.

Regards,
	kaz
--
	* config/tc-sh.c (md_apply_fix): Extend sign of the offset value
	for 64-bit host.

--- ORIG/src/gas/config/tc-sh.c	2008-09-12 09:01:35.000000000 +0900
+++ src/gas/config/tc-sh.c	2009-08-29 09:30:53.000000000 +0900
@@ -4183,6 +4183,9 @@ md_apply_fix (fixS *fixP, valueT *valP, 
 	val = ((val >> shift)
 	       | ((long) -1 & ~ ((long) -1 >> shift)));
     }
+
+  /* Extend sign for 64-bit host.  */
+  val = ((val & 0xffffffff) ^ 0x80000000) - 0x80000000;
   if (max != 0 && (val < min || val > max))
     as_bad_where (fixP->fx_file, fixP->fx_line, _("offset out of range"));
   else if (max != 0)


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