public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Zack Weinberg <zack@codesourcery.com>
To: Richard Earnshaw <rearnsha@gcc.gnu.org>
Cc: Nick Clifton <nickc@redhat.com>,  binutils@sourceware.org
Subject: Re: Fix some of the ARM GAS failures
Date: Fri, 27 May 2005 11:42:00 -0000	[thread overview]
Message-ID: <87fyw9kvr3.fsf@codesourcery.com> (raw)
In-Reply-To: <1117010314.7618.15.camel@pc960.cambridge.arm.com> (Richard Earnshaw's message of "Wed, 25 May 2005 09:38:34 +0100")

Richard Earnshaw <rearnsha@gcc.gnu.org> writes:

> On Tue, 2005-05-24 at 21:17, Zack Weinberg wrote:
>> This patch should improve the ARM-GAS situation somewhat.  md_apply_fix3
>> needs to truncate the relocation to 32 signed bits manually; if the host
>> is 64-bit, fx_addnumber and fx_offset are 64-bit, and may generate
>> spurious overflows.  Also, we need a double cast on both sides of the
>> hack to pass an integer around in tc_fix_data.
>> 
>
> AFAICT tc_fix_data is a private type to the ARM-specific parts of the
> assembler.  Since storing the thumbness is the only use, and the type of
> tc_fix_data is defined in tc-arm.h (TC_FIX_TYPE), it would make much
> more sense to just change TC_FIX_TYPE to 'int' and get rid of all those
> nasty casts.
>
> Otherwise OK.

Gosh, I had no idea the target could define the type of tc_fix_data.
Thanks!

Here's the patch I'll check in.

zw
        * config/tc-arm.h (TC_FIX_TYPE): Change to int.
        (TC_INIT_FIX_DATA): Initialize to 0, not NULL.
        * config/tc-arm.c (fix_new_arm): Remove now-unnecessary cast.
        (md_apply_fix3): Delete fix_is_thumb variable; refer to
        fixP->tc_fix_data directly in the sole place it was used.
        Explicitly truncate value, *valP, fixP->fx_addnumber, and
        fixP->fx_offset to 32 bits, for consistent behavior between 32-
        and 64-bit hosts.

===================================================================
Index: config/tc-arm.h
--- config/tc-arm.h	18 May 2005 05:40:08 -0000	1.28
+++ config/tc-arm.h	27 May 2005 06:43:18 -0000
@@ -96,8 +96,8 @@ struct fix;
    deliberately not been updated to mark assembler created stabs
    symbols as Thumb.  */
 
-#define TC_FIX_TYPE PTR
-#define TC_INIT_FIX_DATA(FIX) ((FIX)->tc_fix_data = NULL)
+#define TC_FIX_TYPE int
+#define TC_INIT_FIX_DATA(FIX) ((FIX)->tc_fix_data = 0)
 
 /* We need to keep some local information on symbols.  */
 
===================================================================
Index: config/tc-arm.c
--- config/tc-arm.c	18 May 2005 05:40:07 -0000	1.204
+++ config/tc-arm.c	27 May 2005 06:46:10 -0000
@@ -7297,7 +7297,7 @@ fix_new_arm (fragS *	   frag,
 
   /* Mark whether the fix is to a THUMB instruction, or an ARM
      instruction.  */
-  new_fix->tc_fix_data = (PTR) thumb_mode;
+  new_fix->tc_fix_data = thumb_mode;
 }
 
 static void
@@ -10077,9 +10077,6 @@ md_apply_fix3 (fixS *	fixP,
   unsigned long	 temp;
   int		 sign;
   char *	 buf = fixP->fx_where + fixP->fx_frag->fr_literal;
-  /* The double cast here prevents warnings about converting a pointer
-     to an integer of different size.  We know the value is 0, 1, or 2.	 */
-  int		 fix_is_thumb = (int) (size_t) fixP->tc_fix_data;
 
   assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
 
@@ -10098,9 +10095,21 @@ md_apply_fix3 (fixS *	fixP,
 	value += md_pcrel_from (fixP);
     }
 
-  /* Remember value for emit_reloc.  */
+  /* On a 64-bit host, silently truncate 'value' to 32 bits for
+     consistency with the behavior on 32-bit hosts.  Remember value
+     for emit_reloc.  */
+  value &= 0xffffffff;
+  value ^= 0x80000000;
+  value -= 0x80000000; 
+
+  *valP = value;
   fixP->fx_addnumber = value;
 
+  /* Same treatment for fixP->fx_offset.  */
+  fixP->fx_offset &= 0xffffffff;
+  fixP->fx_offset ^= 0x80000000;
+  fixP->fx_offset -= 0x80000000;
+
   switch (fixP->fx_r_type)
     {
     case BFD_RELOC_NONE:
@@ -10436,7 +10445,7 @@ md_apply_fix3 (fixS *	fixP,
       break;
 
     case BFD_RELOC_ARM_SWI:
-      if (fix_is_thumb)
+      if (fixP->tc_fix_data != 0)
 	{
 	  if (((unsigned long) value) > 0xff)
 	    as_bad_where (fixP->fx_file, fixP->fx_line,

      reply	other threads:[~2005-05-27  6:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-24 21:24 Zack Weinberg
2005-05-25 13:42 ` Richard Earnshaw
2005-05-27 11:42   ` Zack Weinberg [this message]

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=87fyw9kvr3.fsf@codesourcery.com \
    --to=zack@codesourcery.com \
    --cc=binutils@sourceware.org \
    --cc=nickc@redhat.com \
    --cc=rearnsha@gcc.gnu.org \
    /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).