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]

SH: debugging relocs


I'm a little less confident in this one - I'm not sure I cleared
unresolved_reloc everywhere I ought to.  Also based on Richard's changes to
the SPARC port.

Thoughts?

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

2002-08-22  Daniel Jacobowitz  <drow@mvista.com>

	* elf32-sh.c (sh_elf_relocate_section): Clean unresolved
	relocation checking to match other targets.

--- elf32-sh.c	2002-08-22 12:46:11.000000000 -0400
+++ elf32-sh.c.mod	2002-08-22 12:42:08.000000000 -0400
@@ -4026,10 +4026,11 @@ sh_elf_relocate_section (output_bfd, inf
       Elf_Internal_Sym *sym;
       asection *sec;
       struct elf_link_hash_entry *h;
-      bfd_vma relocation;
+      bfd_vma relocation, off;
       bfd_vma addend = (bfd_vma) 0;
       bfd_reloc_status_type r;
       int seen_stt_datalabel = 0;
+      boolean unresolved_reloc;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
 
@@ -4068,6 +4069,7 @@ sh_elf_relocate_section (output_bfd, inf
       h = NULL;
       sym = NULL;
       sec = NULL;
+      unresolved_reloc = false;
       if (r_symndx < symtab_hdr->sh_info)
 	{
 	  sym = local_syms + r_symndx;
@@ -4170,61 +4172,19 @@ sh_elf_relocate_section (output_bfd, inf
 #endif
 	      h = (struct elf_link_hash_entry *) h->root.u.i.link;
 	    }
+
+	  relocation = 0;
 	  if (h->root.type == bfd_link_hash_defined
 	      || h->root.type == bfd_link_hash_defweak)
 	    {
 	      sec = h->root.u.def.section;
-	      /* In these cases, we don't need the relocation value.
-		 We check specially because in some obscure cases
-		 sec->output_section will be NULL.  */
-	      if (r_type == R_SH_GOTPC
-		  || r_type == R_SH_GOTPC_LOW16
-		  || r_type == R_SH_GOTPC_MEDLOW16
-		  || r_type == R_SH_GOTPC_MEDHI16
-		  || r_type == R_SH_GOTPC_HI16
-		  || ((r_type == R_SH_PLT32
-		       || r_type == R_SH_PLT_LOW16
-		       || r_type == R_SH_PLT_MEDLOW16
-		       || r_type == R_SH_PLT_MEDHI16
-		       || r_type == R_SH_PLT_HI16)
-		      && h->plt.offset != (bfd_vma) -1)
-		  || ((r_type == R_SH_GOT32
-		       || r_type == R_SH_GOT_LOW16
-		       || r_type == R_SH_GOT_MEDLOW16
-		       || r_type == R_SH_GOT_MEDHI16
-		       || r_type == R_SH_GOT_HI16)
-		      && elf_hash_table (info)->dynamic_sections_created
-		      && (! info->shared
-			  || (! info->symbolic && h->dynindx != -1)
-			  || (h->elf_link_hash_flags
-			      & ELF_LINK_HASH_DEF_REGULAR) == 0))
-		  /* The cases above are those in which relocation is
-		     overwritten in the switch block below.  The cases
-		     below are those in which we must defer relocation
-		     to run-time, because we can't resolve absolute
-		     addresses when creating a shared library.  */
-		  || (info->shared
-		      && ((! info->symbolic && h->dynindx != -1)
-			  || (h->elf_link_hash_flags
-			      & ELF_LINK_HASH_DEF_REGULAR) == 0)
-		      && ((r_type == R_SH_DIR32
-			   && !(ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
-				|| ELF_ST_VISIBILITY (h->other) == STV_HIDDEN))
-			  || r_type == R_SH_REL32)
-		      && ((input_section->flags & SEC_ALLOC) != 0
-			  /* DWARF will emit R_SH_DIR32 relocations in its
-			     sections against symbols defined externally
-			     in shared libraries.  We can't do anything
-			     with them here.  */
-			  || (input_section->flags & SEC_DEBUGGING) != 0)))
-		relocation = 0;
-	      else if (sec->output_section == NULL)
+	      if (sec->output_section == NULL)
 		{
-		  (*_bfd_error_handler)
-		    (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
-		     bfd_archive_filename (input_bfd), h->root.root.string,
-		     bfd_get_section_name (input_bfd, input_section));
-		  relocation = 0;
+		  /* Set a flag that will be cleared later if we find a
+		     relocation value for this symbol.  output_section
+		     is typically NULL for symbols satisfied by a shared
+		     library.  */
+		  unresolved_reloc = true;
 		}
 	      else
 		relocation = ((h->root.u.def.value
@@ -4237,18 +4197,17 @@ sh_elf_relocate_section (output_bfd, inf
 				 && ! seen_stt_datalabel));
 	    }
 	  else if (h->root.type == bfd_link_hash_undefweak)
-	    relocation = 0;
+	    ;
 	  else if (info->shared
 	       && (!info->symbolic || info->allow_shlib_undefined)
 	       && !info->no_undefined)
-	    relocation = 0;
+	    ;
 	  else
 	    {
 	      if (! ((*info->callbacks->undefined_symbol)
 		     (info, h->root.root.string, input_bfd,
 		      input_section, rel->r_offset, true)))
 		return false;
-	      relocation = 0;
 	    }
 	}
 
@@ -4447,6 +4406,7 @@ sh_elf_relocate_section (output_bfd, inf
 	  relocation = (sgotplt->output_offset
 			+ ((h->plt.offset / elf_sh_sizeof_plt (info)
 			    - 1 + 3) * 4));
+	  unresolved_reloc = false;
 
 #ifdef GOT_BIAS
 	  relocation -= GOT_BIAS;
@@ -4463,8 +4434,7 @@ sh_elf_relocate_section (output_bfd, inf
 
 	  if (h != NULL)
 	    {
-	      bfd_vma off;
 	      boolean dyn;
 
 	      off = h->got.offset;
 #ifdef INCLUDE_SHMEDIA
@@ -4527,13 +4487,11 @@ sh_elf_relocate_section (output_bfd, inf
 			h->got.offset |= 1;
 		    }
 		}
-
-	      relocation = sgot->output_offset + off;
+	      else
+		unresolved_reloc = false;
 	    }
 	  else
 	    {
-	      bfd_vma off;
-
 #ifdef INCLUDE_SHMEDIA
 	      if (rel->r_addend)
 		{
@@ -4593,8 +4551,8 @@ sh_elf_relocate_section (output_bfd, inf
 		    local_got_offsets[r_symndx] |= 1;
 		}
 
-	      relocation = sgot->output_offset + off;
 	    }
+	  relocation = sgot->output_offset + off;
 
 #ifdef GOT_BIAS
  	  relocation -= GOT_BIAS;
@@ -4654,6 +4612,7 @@ sh_elf_relocate_section (output_bfd, inf
 	  relocation += GOT_BIAS;
 #endif
 
+	  unresolved_reloc = false;
 	  addend = rel->r_addend;
 
 	  goto final_link_relocate;
@@ -4700,6 +4659,7 @@ sh_elf_relocate_section (output_bfd, inf
 #endif
 
 	  addend = rel->r_addend;
+	  unresolved_reloc = false;
 
 	  goto final_link_relocate;
 
@@ -4722,6 +4682,19 @@ sh_elf_relocate_section (output_bfd, inf
 	  }
 	}
 
+      /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
+	 because such sections are not SEC_ALLOC and thus ld.so will
+	 not process them.  */
+      if (unresolved_reloc
+	  && !((input_section->flags & SEC_DEBUGGING) != 0
+	       && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0))
+	(*_bfd_error_handler)
+	  (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
+	   bfd_archive_filename (input_bfd),
+	   bfd_get_section_name (input_bfd, input_section),
+	   (long) rel->r_offset,
+	   h->root.root.string);
+
     relocation_done:
       if (r != bfd_reloc_ok)
 	{


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