R_MIPS16_GPREL patch

Mark Mitchell mark@codesourcery.com
Wed Jul 14 19:00:00 GMT 1999


>>>>> "Ian" == Ian Lance Taylor <ian@zembu.com> writes:

    Ian> Yes, when viewing the values as 32 bits, there is the same
    Ian> word swap issue here.  Sorry I missed it when looking at the
    Ian> code.

OK.  This change makes the two R_MIPS16_26 and R_MIPS16_GPREL cases
behave in the same way.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

1999-07-14  Mark Mitchell  <mark@codesourcery.com>

	* elf32-mips.c (mips_elf_obtain_contents): Swap 16-bit halves of
	things relocated by R_MIPS16_GPREL.
	(mips_elf_perform_relocation): Likewise.

Index: elf32-mips.c
===================================================================
RCS file: /cvs/binutils/binutils/bfd/elf32-mips.c,v
retrieving revision 1.25
diff -u -p -r1.25 elf32-mips.c
--- elf32-mips.c	1999/07/14 14:23:13	1.25
+++ elf32-mips.c	1999/07/15 01:57:03
@@ -6101,7 +6101,8 @@ mips_elf_obtain_contents (howto, relocat
   /* Obtain the bytes.  */
   x = bfd_get (8 * bfd_get_reloc_size (howto), input_bfd, location);
 
-  if (ELF32_R_TYPE (relocation->r_info) == R_MIPS16_26
+  if ((ELF32_R_TYPE (relocation->r_info) == R_MIPS16_26
+       || ELF32_R_TYPE (relocation->r_info) == R_MIPS16_GPREL)
       && bfd_little_endian (input_bfd))
     /* The two 16-bit words will be reversed on a little-endian
        system.  See mips_elf_perform_relocation for more details.  */
@@ -6208,18 +6209,6 @@ mips_elf_perform_relocation (info, howto
 		 | ((value & 0x3e00000) >> 5) 
 		 | (value & 0xffff));
       
-      /* Perform the relocation.  */
-      x |= (value & howto->dst_mask);
-
-      /* Swap the high- and low-order 16 bits on little-endian
-         systems.  */
-      if (bfd_little_endian (input_bfd))
-	x = (((x & 0xffff) << 16)
-	     | ((x & 0xffff0000) >> 16));
-
-      /* Store the value.  */
-      bfd_put_32 (input_bfd, x, location);
-      return;
     }
   else if (ELF32_R_TYPE (relocation->r_info) == R_MIPS16_GPREL)
     {
@@ -6239,7 +6228,9 @@ mips_elf_perform_relocation (info, howto
 	 addend is retrieved and stored as shown in this diagram; that
 	 is, the Imm fields above replace the V-rel16 field.  
 
-         All we need to do here is shuffle the bits appropriately.  */
+         All we need to do here is shuffle the bits appropriately.  As
+	 above, the two 16-bit halves must be swapped on a
+	 little-endian system.  */
       value = (((value & 0x7e0) << 16)
 	       | ((value & 0xf800) << 5)
 	       | (value & 0x1f));
@@ -6248,6 +6239,13 @@ mips_elf_perform_relocation (info, howto
   /* Set the field.  */
   x |= (value & howto->dst_mask);
 
+  /* Swap the high- and low-order 16 bits on little-endian systems
+     when doing a MIPS16 relocation.  */
+  if ((ELF32_R_TYPE (relocation->r_info) == R_MIPS16_GPREL
+       || ELF32_R_TYPE (relocation->r_info) == R_MIPS16_26)
+      && bfd_little_endian (input_bfd))
+    x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16));
+  
   /* Put the value into the output.  */
   bfd_put (8 * bfd_get_reloc_size (howto), input_bfd, x, location);
 }


More information about the Binutils mailing list