This is the mail archive of the binutils@sources.redhat.com 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]

Commited patch for elf*-sparc.c (was binutils: "unexpected reloc type 0x17" on sparc)


On Fri, Jun 29, 2001 at 09:59:36AM -0700, Ian Lance Taylor wrote:
> I believe that to be fully correct here you must consider the
> alignment of the program segment into which the output section is
> being placed.  This can be approximated by considering the alignment
> of the output section.

Here is what I've commited.
I added an flags & SEC_ALLOC check instead (which means e.g. that we no
longer output useless .rela.stab on sparc when nobody uses it) and ALLOCed
section VMAs (note that at that point the final addresses are already
computed) will be at least page size aligned, so there is no need to check
it (especially when it could pesimize things).

2001-07-11  Jakub Jelinek  <jakub@redhat.com>

	* elf32-sparc.c (_bfd_sparc_elf_howto_table): Remove support for
	R_SPARC_UA64.
	(elf32_sparc_check_relocs): Likewise.
	Only create .rela section for alloced sections in shared libraries.
	(elf32_sparc_relocate_section): Likewise.
	Remove redundant check.
	Optimize unaligned reloc usage.
	* elf64-sparc.c (sparc64_elf_relocate_section): Remove redundant
	check.

	* testsuite/gas/sparc/unalign.s: Remove .uaxword test.
	* testsuite/gas/sparc/unalign.d: Adjust accordingly.

--- bfd/elf32-sparc.c.jj	Fri Jun 29 11:58:58 2001
+++ bfd/elf32-sparc.c	Wed Jul 11 16:59:53 2001
@@ -120,7 +120,7 @@ reloc_howto_type _bfd_sparc_elf_howto_ta
   HOWTO(R_SPARC_NONE,      0,0, 0,false,0,complain_overflow_dont,    bfd_elf_generic_reloc,  "R_SPARC_NONE",    false,0,0x00000000,true),
   HOWTO(R_SPARC_NONE,      0,0, 0,false,0,complain_overflow_dont,    bfd_elf_generic_reloc,  "R_SPARC_NONE",    false,0,0x00000000,true),
   HOWTO(R_SPARC_NONE,      0,0, 0,false,0,complain_overflow_dont,    bfd_elf_generic_reloc,  "R_SPARC_NONE",    false,0,0x00000000,true),
-  HOWTO(R_SPARC_UA64,      0,4,64,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc,  "R_SPARC_UA64",    false,0,(~ (bfd_vma)0), true),
+  HOWTO(R_SPARC_UA64,      0,0, 0,false,0,complain_overflow_dont,    sparc_elf_notsupported_reloc,  "R_SPARC_UA64",    false,0,0x00000000,true),
   HOWTO(R_SPARC_UA16,      0,1,16,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc,  "R_SPARC_UA16",    false,0,0x0000ffff,true),
   HOWTO(R_SPARC_REV32,     0,2,32,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc,  "R_SPARC_REV32",   false,0,0xffffffff,true),
 };
@@ -554,11 +554,10 @@ elf32_sparc_check_relocs (abfd, info, se
 	case R_SPARC_LO10:
 	case R_SPARC_UA16:
 	case R_SPARC_UA32:
-	case R_SPARC_UA64:
 	  if (h != NULL)
 	    h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;
 
-	  if (info->shared)
+	  if (info->shared && (sec->flags & SEC_ALLOC))
 	    {
 	      /* When creating a shared object, we must copy these
                  relocs into the output file.  We create a reloc
@@ -1223,7 +1222,6 @@ elf32_sparc_relocate_section (output_bfd
 			  || r_type == R_SPARC_LO10
 			  || r_type == R_SPARC_UA16
 			  || r_type == R_SPARC_UA32
-			  || r_type == R_SPARC_UA64
 			  || ((r_type == R_SPARC_PC10
 			       || r_type == R_SPARC_PC22)
 			      && strcmp (h->root.root.string,
@@ -1412,8 +1410,7 @@ elf32_sparc_relocate_section (output_bfd
 	case R_SPARC_LO10:
 	case R_SPARC_UA16:
 	case R_SPARC_UA32:
-	case R_SPARC_UA64:
-	  if (info->shared)
+	  if (info->shared && (input_section->flags & SEC_ALLOC))
 	    {
 	      Elf_Internal_Rela outrel;
 	      boolean skip;
@@ -1463,6 +1460,28 @@ elf32_sparc_relocate_section (output_bfd
 	      outrel.r_offset += (input_section->output_section->vma
 				  + input_section->output_offset);
 
+	      /* Optimize unaligned reloc usage now that we know where
+		 it finally resides.  */
+	      switch (r_type)
+		{
+		case R_SPARC_16:
+		  if (outrel.r_offset & 1)
+		    r_type = R_SPARC_UA16;
+		  break;
+		case R_SPARC_UA16:
+		  if (!(outrel.r_offset & 1))
+		    r_type = R_SPARC_16;
+		  break;
+		case R_SPARC_32:
+		  if (outrel.r_offset & 3)
+		    r_type = R_SPARC_UA32;
+		  break;
+		case R_SPARC_UA32:
+		  if (!(outrel.r_offset & 3))
+		    r_type = R_SPARC_32;
+		  break;
+		}
+
 	      if (skip)
 		memset (&outrel, 0, sizeof outrel);
 	      /* h->dynindx may be -1 if the symbol was marked to
@@ -1535,12 +1554,8 @@ elf32_sparc_relocate_section (output_bfd
 	      ++sreloc->reloc_count;
 
 	      /* This reloc will be computed at runtime, so there's no
-                 need to do anything now, unless this is a RELATIVE
-                 reloc in an unallocated section.  */
-	      if (skip
-		  || (input_section->flags & SEC_ALLOC) != 0
-		  || ELF32_R_TYPE (outrel.r_info) != R_SPARC_RELATIVE)
-		continue;
+                 need to do anything now.  */
+	      continue;
 	    }
 	  break;
 
@@ -2024,7 +2039,7 @@ elf32_sparc_object_p (abfd)
     }
   else if (elf_elfheader (abfd)->e_flags & EF_SPARC_LEDATA)
     return bfd_default_set_arch_mach (abfd, bfd_arch_sparc,
-                                      bfd_mach_sparc_sparclite_le);
+				      bfd_mach_sparc_sparclite_le);
   else
     return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc);
 }
--- bfd/elf64-sparc.c.jj	Fri Jun 29 11:58:58 2001
+++ bfd/elf64-sparc.c	Wed Jul 11 16:57:38 2001
@@ -2283,12 +2283,8 @@ sparc64_elf_relocate_section (output_bfd
 		++sreloc->reloc_count;
 
 		/* This reloc will be computed at runtime, so there's no
-		   need to do anything now, unless this is a RELATIVE
-		   reloc in an unallocated section.  */
-		if (skip
-		    || (input_section->flags & SEC_ALLOC) != 0
-		    || ELF64_R_TYPE_ID (outrel.r_info) != R_SPARC_RELATIVE)
-		  continue;
+		   need to do anything now.  */
+		continue;
 	      }
 	    break;
 	    }
--- gas/testsuite/gas/sparc/unalign.s.jj	Fri Jun  1 23:50:16 2001
+++ gas/testsuite/gas/sparc/unalign.s	Wed Jul 11 15:09:08 2001
@@ -7,9 +7,6 @@ foo:
 	.byte 0x2
 	.uahalf		jim
 	.byte 0x3
-	.uaxword	harry
 	.byte 0x4
 	.byte 0x5
 	.byte 0x6
-
-
--- gas/testsuite/gas/sparc/unalign.d.jj	Sun Jun  3 02:18:03 2001
+++ gas/testsuite/gas/sparc/unalign.d	Wed Jul 11 15:19:05 2001
@@ -12,7 +12,4 @@ Disassembly of section .data:
 			1: R_SPARC_UA32	fred
    4:	00 02 00 00 	(unimp|illtrap)  0x20000
 			6: R_SPARC_UA16	jim
-   8:	03 00 00 00 	sethi  %hi\(0\), %g1
-			9: R_SPARC_UA64	harry
-   c:	00 00 00 00 	(unimp|illtrap)  0
-  10:	00 04 05 06 	(unimp|illtrap)  0x40506
+   8:	03 04 05 06 	sethi  %hi\(0x10141800\), %g1


	Jakub


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