ChangeLog rotatation and copyright year update
[deliverable/binutils-gdb.git] / bfd / format.c
index 36eeb85e1978bbf432387117fb7f823ba6a47e80..dd6dc8a32ce7d55a60d64adfea4fda243a490d8c 100644 (file)
@@ -1,6 +1,5 @@
 /* Generic BFD support for file formats.
-   Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1999, 2000, 2001, 2002,
-   2003, 2005, 2007, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 1990-2015 Free Software Foundation, Inc.
    Written by Cygnus Support.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -279,7 +278,6 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
   for (target = bfd_target_vector; *target != NULL; target++)
     {
       const bfd_target *temp;
-      bfd_error_type err;
 
       /* Don't check the default target twice.  */
       if (*target == &binary_vec
@@ -310,47 +308,47 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
          match_targ = temp;
          if (preserve.marker != NULL)
            bfd_preserve_finish (abfd, &preserve);
-       }
-
-      if (temp && (abfd->format != bfd_archive || bfd_has_map (abfd)))
-       {
-         /* This format checks out as ok!  */
-         right_targ = temp;
-
-         /* If this is the default target, accept it, even if other
-            targets might match.  People who want those other targets
-            have to set the GNUTARGET variable.  */
-         if (temp == bfd_default_vector[0])
-           goto ok_ret;
-
-         if (matching_vector)
-           matching_vector[match_count] = temp;
-         match_count++;
 
-         if (temp->match_priority < best_match)
+         if (abfd->format != bfd_archive
+             || (bfd_has_map (abfd)
+                 && bfd_get_error () != bfd_error_wrong_object_format))
            {
-             best_match = temp->match_priority;
-             best_count = 0;
+             /* This format checks out as ok!  */
+             right_targ = temp;
+
+             /* If this is the default target, accept it, even if
+                other targets might match.  People who want those
+                other targets have to set the GNUTARGET variable.  */
+             if (temp == bfd_default_vector[0])
+               goto ok_ret;
+
+             if (matching_vector)
+               matching_vector[match_count] = temp;
+             match_count++;
+
+             if (temp->match_priority < best_match)
+               {
+                 best_match = temp->match_priority;
+                 best_count = 0;
+               }
+             best_count++;
+           }
+         else
+           {
+             /* An archive with no armap or objects of the wrong
+                type.  We want this target to match if we get no
+                better matches.  */
+             if (ar_right_targ != bfd_default_vector[0])
+               ar_right_targ = *target;
+             if (matching_vector)
+               matching_vector[ar_match_index] = *target;
+             ar_match_index++;
            }
-         best_count++;
-       }
-      else if (temp
-              || (err = bfd_get_error ()) == bfd_error_wrong_object_format
-              || err == bfd_error_file_ambiguously_recognized)
-       {
-         /* An archive with no armap or objects of the wrong type,
-            or an ambiguous match.  We want this target to match
-            if we get no better matches.  */
-         if (ar_right_targ != bfd_default_vector[0])
-           ar_right_targ = *target;
-         if (matching_vector)
-           matching_vector[ar_match_index] = *target;
-         ar_match_index++;
-       }
-      else if (err != bfd_error_wrong_format)
-       goto err_ret;
 
-      if (temp && !bfd_preserve_save (abfd, &preserve))
+         if (!bfd_preserve_save (abfd, &preserve))
+           goto err_ret;
+       }
+      else if (bfd_get_error () != bfd_error_wrong_format)
        goto err_ret;
     }
 
@@ -377,6 +375,9 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
        }
     }
 
+  /* We have more than one equally good match.  If any of the best
+     matches is a target in config.bfd targ_defvec or targ_selvecs,
+     choose it.  */
   if (match_count > 1)
     {
       const bfd_target * const *assoc = bfd_associated_vector;
@@ -386,7 +387,8 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
          int i = match_count;
 
          while (--i >= 0)
-           if (matching_vector[i] == right_targ)
+           if (matching_vector[i] == right_targ
+               && right_targ->match_priority <= best_match)
              break;
 
          if (i >= 0)
@@ -397,6 +399,22 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
        }
     }
 
+  /* We still have more than one equally good match, and at least some
+     of the targets support match priority.  Choose the first of the
+     best matches.  */
+  if (matching_vector && match_count > 1 && best_count != match_count)
+    {
+      int i;
+
+      for (i = 0; i < match_count; i++)
+       {
+         right_targ = matching_vector[i];
+         if (right_targ->match_priority <= best_match)
+           break;
+       }
+      match_count = 1;
+    }
+
   /* There is way too much undoing of half-known state here.  We
      really shouldn't iterate on live bfd's.  Note that saving the
      whole bfd and restoring it would be even worse; the first thing
This page took 0.025051 seconds and 4 git commands to generate.