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]

Get rid of some ugly code


I've been meaning to do this for a long time.

Index: bfd/ChangeLog
	* elf32-i386.c (elf_i386_relocate_section): Replace ugly
	complicated tests for unresolvable relocs with a simple direct
	scheme using "unresolved_reloc" var.

-- 
Alan Modra

Index: bfd/elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.30
diff -u -p -r1.30 elf32-i386.c
--- elf32-i386.c	2001/06/23 10:03:53	1.30
+++ elf32-i386.c	2001/06/23 10:12:57
@@ -1448,6 +1448,7 @@ elf_i386_relocate_section (output_bfd, i
       asection *sec;
       bfd_vma off;
       bfd_vma relocation;
+      boolean unresolved_reloc;
       bfd_reloc_status_type r;
       unsigned int indx;
 
@@ -1494,6 +1495,7 @@ elf_i386_relocate_section (output_bfd, i
       h = NULL;
       sym = NULL;
       sec = NULL;
+      unresolved_reloc = false;
       if (r_symndx < symtab_hdr->sh_info)
 	{
 	  sym = local_syms + r_symndx;
@@ -1514,51 +1516,12 @@ elf_i386_relocate_section (output_bfd, i
 	      || h->root.type == bfd_link_hash_defweak)
 	    {
 	      sec = h->root.u.def.section;
-	      if (r_type == R_386_GOTPC
-		  || (r_type == R_386_PLT32
-		      && htab->splt != NULL
-		      && h->plt.offset != (bfd_vma) -1)
-		  || (r_type == R_386_GOT32
-		      && (WILL_CALL_FINISH_DYNAMIC_SYMBOL
-			  (htab->root.dynamic_sections_created, info, h))
-		      && !(info->shared
-			   && (info->symbolic
-			       || h->dynindx == -1
-			       || (h->elf_link_hash_flags
-				   & ELF_LINK_FORCED_LOCAL))
-			   && (h->elf_link_hash_flags
-			       & ELF_LINK_HASH_DEF_REGULAR)))
-		  || ((r_type == R_386_32
-		       || r_type == R_386_PC32)
-		      && ((info->shared
-			   && ((!info->symbolic && h->dynindx != -1)
-			       || (h->elf_link_hash_flags
-				   & ELF_LINK_HASH_DEF_REGULAR) == 0))
-			  || (!info->shared
-			      && h->dynindx != -1
-			      && (h->elf_link_hash_flags
-				  & ELF_LINK_NON_GOT_REF) == 0
-			      && (h->elf_link_hash_flags
-				  & ELF_LINK_HASH_DEF_REGULAR) == 0))
-		      && ((input_section->flags & SEC_ALLOC) != 0
-			  /* DWARF will emit R_386_32 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
-			      && (h->elf_link_hash_flags
-				  & ELF_LINK_HASH_DEF_DYNAMIC) != 0))))
-		/* In these cases, we don't need the relocation
-		   value.  We check specially because in some
-		   obscure cases sec->output_section will be NULL.  */
-		;
-	      else if (sec->output_section == NULL)
-		(*_bfd_error_handler)
-		  (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
-		   bfd_get_filename (input_bfd),
-		   bfd_get_section_name (input_bfd, input_section),
-		   (long) rel->r_offset,
-		   h->root.root.string);
+	      if (sec->output_section == NULL)
+		/* 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
 			      + sec->output_section->vma
@@ -1669,6 +1632,7 @@ elf_i386_relocate_section (output_bfd, i
 	    abort ();
 
 	  relocation = htab->sgot->output_offset + off;
+	  unresolved_reloc = false;
 	  break;
 
 	case R_386_GOTOFF:
@@ -1686,6 +1650,7 @@ elf_i386_relocate_section (output_bfd, i
 	case R_386_GOTPC:
 	  /* Use global offset table as symbol value.  */
 	  relocation = htab->sgot->output_section->vma;
+	  unresolved_reloc = false;
 	  break;
 
 	case R_386_PLT32:
@@ -1709,6 +1674,7 @@ elf_i386_relocate_section (output_bfd, i
 	  relocation = (htab->splt->output_section->vma
 			+ htab->splt->output_offset
 			+ h->plt.offset);
+	  unresolved_reloc = false;
 	  break;
 
 	case R_386_32:
@@ -1844,6 +1810,14 @@ elf_i386_relocate_section (output_bfd, i
 	  break;
 	}
 
+      if (unresolved_reloc)
+	(*_bfd_error_handler)
+	  (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"),
+	   bfd_get_filename (input_bfd),
+	   bfd_get_section_name (input_bfd, input_section),
+	   (long) rel->r_offset,
+	   h->root.root.string);
+
       r = _bfd_final_link_relocate (howto, input_bfd, input_section,
 				    contents, rel->r_offset,
 				    relocation, (bfd_vma) 0);


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