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]

[patch] elf32-rx.c: more paranoia about backend choice


The "ns" backend is only supposed to be selected when the user asks
for it with objcopy -I (for example), but the logic in the common
parts isn't sufficient for the old code to do that reliably.
Committed.

	* elf32-rx.c (rx_elf_object_p): Add more checks for "scanning" to
	avoid using the special non-swapping target when not explicitly
	requested.

Index: elf32-rx.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-rx.c,v
retrieving revision 1.14
diff -p -U5 -r1.14 elf32-rx.c
--- elf32-rx.c	22 Nov 2011 19:46:20 -0000	1.14
+++ elf32-rx.c	22 Nov 2011 19:49:30 -0000
@@ -30,10 +30,11 @@
 
 /* This is a meta-target that's used only with objcopy, to avoid the
    endian-swap we would otherwise get.  We check for this in
    rx_elf_object_p().  */
 const bfd_target bfd_elf32_rx_be_ns_vec;
+const bfd_target bfd_elf32_rx_be_vec;
 
 #ifdef DEBUG
 char * rx_get_reloc (long);
 void rx_dump_symtab (bfd *, void *, void *);
 #endif
@@ -3026,18 +3027,28 @@ rx_elf_object_p (bfd * abfd)
   int i;
   unsigned int u;
   Elf_Internal_Phdr *phdr = elf_tdata (abfd)->phdr;
   int nphdrs = elf_elfheader (abfd)->e_phnum;
   sec_ptr bsec;
+  static int saw_be = FALSE;
 
   /* We never want to automatically choose the non-swapping big-endian
      target.  The user can only get that explicitly, such as with -I
      and objcopy.  */
   if (abfd->xvec == &bfd_elf32_rx_be_ns_vec
       && abfd->target_defaulted)
     return FALSE;
 
+  /* BFD->target_defaulted is not set to TRUE when a target is chosen
+     as a fallback, so we check for "scanning" to know when to stop
+     using the non-swapping target.  */
+  if (abfd->xvec == &bfd_elf32_rx_be_ns_vec
+      && saw_be)
+    return FALSE;
+  if (abfd->xvec == &bfd_elf32_rx_be_vec)
+    saw_be = TRUE;
+
   bfd_default_set_arch_mach (abfd, bfd_arch_rx,
 			     elf32_rx_machine (abfd));
 
   /* For each PHDR in the object, we must find some section that
      corresponds (based on matching file offsets) and use its VMA


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