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]
Other format: [Raw text]

ELF/m68k relocation fixes


This fixes the remaining ld testsuite failure.

Andreas.

2003-05-12  Andreas Schwab  <schwab@suse.de>

	* elf32-m68k.c (elf_m68k_check_relocs): Cache reloc section in
	elf_section_data during processing of pc-relative and absolute
	relocations.
	(elf_m68k_relocate_section): Use the cached reloc section instead
	of computing it again.  Fix handling of visibility.  Don't modify
	addend when copying over a relocation into the output.

--- bfd/elf32-m68k.c.~1.55.~	2003-05-12 15:14:49.000000000 +0200
+++ bfd/elf32-m68k.c	2003-05-12 15:42:28.000000000 +0200
@@ -673,6 +673,7 @@ elf_m68k_check_relocs (abfd, info, sec, 
 			  || !bfd_set_section_alignment (dynobj, sreloc, 2))
 			return FALSE;
 		    }
+		  elf_section_data (sec)->sreloc = sreloc;
 		}
 
 	      if (sec->flags & SEC_READONLY
@@ -1627,12 +1628,17 @@ elf_m68k_relocate_section (output_bfd, i
 	  if (info->shared
 	      && r_symndx != 0
 	      && (input_section->flags & SEC_ALLOC) != 0
+	      && (h == NULL
+		  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+		  || h->root.type != bfd_link_hash_undefweak)
 	      && ((r_type != R_68K_PC8
 		   && r_type != R_68K_PC16
 		   && r_type != R_68K_PC32)
-		  || (!info->symbolic
-		      || (h->elf_link_hash_flags
-			  & ELF_LINK_HASH_DEF_REGULAR) == 0)))
+		  || (h != NULL
+		      && h->dynindx != -1
+		      && (!info->symbolic
+			  || (h->elf_link_hash_flags
+			      & ELF_LINK_HASH_DEF_REGULAR) == 0))))
 	    {
 	      Elf_Internal_Rela outrel;
 	      bfd_byte *loc;
@@ -1642,26 +1648,6 @@ elf_m68k_relocate_section (output_bfd, i
 		 are copied into the output file to be resolved at run
 		 time.  */
 
-	      if (sreloc == NULL)
-		{
-		  const char *name;
-
-		  name = (bfd_elf_string_from_elf_section
-			  (input_bfd,
-			   elf_elfheader (input_bfd)->e_shstrndx,
-			   elf_section_data (input_section)->rel_hdr.sh_name));
-		  if (name == NULL)
-		    return FALSE;
-
-		  BFD_ASSERT (strncmp (name, ".rela", 5) == 0
-			      && strcmp (bfd_get_section_name (input_bfd,
-							       input_section),
-					 name + 5) == 0);
-
-		  sreloc = bfd_get_section_by_name (dynobj, name);
-		  BFD_ASSERT (sreloc != NULL);
-		}
-
 	      skip = FALSE;
 	      relocate = FALSE;
 
@@ -1677,19 +1663,22 @@ elf_m68k_relocate_section (output_bfd, i
 
 	      if (skip)
 		memset (&outrel, 0, sizeof outrel);
-	      /* h->dynindx may be -1 if the symbol was marked to
-                 become local.  */
 	      else if (h != NULL
-		       && ((! info->symbolic && h->dynindx != -1)
+		       && h->dynindx != -1
+		       && (r_type == R_68K_PC8
+			   || r_type == R_68K_PC16
+			   || r_type == R_68K_PC32
+			   || !info->shared
+			   || !info->symbolic
 			   || (h->elf_link_hash_flags
 			       & ELF_LINK_HASH_DEF_REGULAR) == 0))
 		{
-		  BFD_ASSERT (h->dynindx != -1);
 		  outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
-		  outrel.r_addend = relocation + rel->r_addend;
+		  outrel.r_addend = rel->r_addend;
 		}
 	      else
 		{
+		  /* This symbol is local, or marked to become local.  */
 		  if (r_type == R_68K_32)
 		    {
 		      relocate = TRUE;
@@ -1730,6 +1719,10 @@ elf_m68k_relocate_section (output_bfd, i
 		    }
 		}
 
+	      sreloc = elf_section_data (input_section)->sreloc;
+	      if (sreloc == NULL)
+		abort ();
+
 	      loc = sreloc->contents;
 	      loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
 	      bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


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