This is the mail archive of the binutils@sourceware.org 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]

[Xtensa] a few small repairs in bfd


I've committed this patch to fix a few small issues for Xtensa:

1) When the linker finds an invalid relocation against a dynamic symbol, it should not continue trying to process that relocation. The symptom of this is getting multiple error messages for the same problem, so it's not critical but still good to fix.

2) All code for Xtensa on GNU/Linux is supposed to be PIC, but it is possible for someone to compile non-PIC code with a toolchain configured for xtensa-elf. If the non-PIC code uses the "longcalls" option, it should be able to basically work, as long as the linker ignores R_XTENSA_ASM_EXPAND relocations against dynamic symbols.

3) The ld-elf/weak-dyn-1 test was failing because it uses a special linker script to generate a shared object, and that script did not include the special Xtensa .xt.lit section. The patch avoids a seg fault in this case, even though the output is unlikely to be useful for much of anything.

I tested this patch by manually linking a few combinations of PIC and non-PIC code, as well as running the binutils testsuites for both xtensa-elf and xtensa-linux-uclibc targets.

2008-02-04  Bob Wilson  <bob.wilson@acm.org>
	
	* elf32-xtensa (elf_xtensa_relocate_section): After finding an invalid
	relocation, do not continue processing it.  Ignore R_XTENSA_ASM_EXPAND
	relocations against dynamic symbols.
	(elf_xtensa_finish_dynamic_sections): Do not fail if there is no
	.xt.lit section.
Index: elf32-xtensa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-xtensa.c,v
retrieving revision 1.106
diff -u -p -r1.106 elf32-xtensa.c
--- elf32-xtensa.c	11 Jan 2008 09:07:03 -0000	1.106
+++ elf32-xtensa.c	4 Feb 2008 21:24:35 -0000
@@ -2164,6 +2164,7 @@ elf_xtensa_relocate_section (bfd *output
 		    (info, error_message, input_bfd, input_section,
 		     rel->r_offset)))
 		return FALSE;
+	      continue;
 	    }
 	  else if ((r_type == R_XTENSA_32 || r_type == R_XTENSA_PLT)
 		   && (input_section->flags & SEC_ALLOC) != 0
@@ -2244,6 +2245,13 @@ elf_xtensa_relocate_section (bfd *output
 	      BFD_ASSERT (sizeof (Elf32_External_Rela) * srel->reloc_count
 			  <= srel->size);
 	    }
+	  else if (r_type == R_XTENSA_ASM_EXPAND && dynamic_symbol)
+	    {
+	      /* This should only happen for non-PIC code, which is not
+		 supposed to be used on systems with dynamic linking.
+		 Just ignore these relocations.  */
+	      continue;
+	    }
 	}
 
       /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
@@ -2467,7 +2475,7 @@ elf_xtensa_finish_dynamic_sections (bfd 
   bfd *dynobj;
   asection *sdyn, *srelplt, *sgot, *sxtlit, *sgotloc;
   Elf32_External_Dyn *dyncon, *dynconend;
-  int num_xtlit_entries;
+  int num_xtlit_entries = 0;
 
   if (! elf_hash_table (info)->dynamic_sections_created)
     return TRUE;
@@ -2592,11 +2600,14 @@ elf_xtensa_finish_dynamic_sections (bfd 
   BFD_ASSERT (! info->relocatable);
   sxtlit = bfd_get_section_by_name (output_bfd, ".xt.lit");
   sgotloc = htab->sgotloc;
-  BFD_ASSERT (sxtlit && sgotloc);
-  num_xtlit_entries =
-    elf_xtensa_combine_prop_entries (output_bfd, sxtlit, sgotloc);
-  if (num_xtlit_entries < 0)
-    return FALSE;
+  BFD_ASSERT (sgotloc);
+  if (sxtlit)
+    {
+      num_xtlit_entries =
+	elf_xtensa_combine_prop_entries (output_bfd, sxtlit, sgotloc);
+      if (num_xtlit_entries < 0)
+	return FALSE;
+    }
 
   dyncon = (Elf32_External_Dyn *) sdyn->contents;
   dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);

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