2005-12-13 H.J. Lu <hongjiu.lu@intel.com>
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 13 Dec 2005 15:34:28 +0000 (15:34 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 13 Dec 2005 15:34:28 +0000 (15:34 +0000)
PR ld/2008
* elf.c (_bfd_elf_setup_sections): Return FALSE if
elf_linked_to_section will be set to NULL.

* format.c (bfd_check_format_matches): Don't check the default
target twice.

bfd/ChangeLog
bfd/elf.c
bfd/format.c

index f7ed00ac08d1b4f159af23dd820b51aaa412ae9f..1cddc7845069bbfb6d02f9f35e66ebe2317d6c95 100644 (file)
@@ -1,3 +1,12 @@
+2005-12-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/2008
+       * elf.c (_bfd_elf_setup_sections): Return FALSE if
+       elf_linked_to_section will be set to NULL.
+
+       * format.c (bfd_check_format_matches): Don't check the default
+       target twice.
+
 2005-12-13  Alan Modra  <amodra@bigpond.net.au>
 
        * elf64-ppc.c (ppc64_elf_relocate_section): Force tail calls in
index 58a90596d31b3481168257963383871255ed83f0..019f72a030e571445a5cf79135be315a0c5f6d60 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -654,8 +654,23 @@ _bfd_elf_setup_sections (bfd *abfd)
            }
          else
            {
+             asection *link;
+
              this_hdr = elf_elfsections (abfd)[elfsec];
-             elf_linked_to_section (s) = this_hdr->bfd_section;
+
+             /* PR 1991, 2008:
+                Some strip/objcopy may leave an incorrect value in
+                sh_link.  We don't want to proceed.  */
+             link = this_hdr->bfd_section;
+             if (link == NULL)
+               {
+                 (*_bfd_error_handler)
+                   (_("%B: sh_link [%d] in section `%A' is incorrect"),
+                    s->owner, s, elfsec);
+                 result = FALSE;
+               }
+
+             elf_linked_to_section (s) = link;
            }
        }
     }
index ba9ca9f6095366cf8ed4dc81cee78b844d83493c..6a34dd2bea488b2b93bf7d34e8304f222ddcc8de 100644 (file)
@@ -217,7 +217,9 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
       const bfd_target *temp;
       bfd_error_type err;
 
-      if (*target == &binary_vec)
+      /* Don't check the default target twice.  */
+      if (*target == &binary_vec
+         || (!abfd->target_defaulted && *target == save_targ))
        continue;
 
       abfd->xvec = *target;    /* Change BFD's target temporarily.  */