Add IBM 370 support.
[binutils-gdb.git] / ld / ldfile.c
index 1dfa31f219266e40035c9d6bed4805f8b51d4c90..6c00cab91e3d90d2f169f581e8bc40611affcaba 100644 (file)
@@ -111,14 +111,40 @@ ldfile_try_open_bfd (attempt, entry)
        info_msg (_("attempt to open %s succeeded\n"), attempt);
     }
 
-  if (entry->the_bfd != NULL)
-    return true;
-  else
+  if (entry->the_bfd == NULL)
     {
       if (bfd_get_error () == bfd_error_invalid_target)
        einfo (_("%F%P: invalid BFD target `%s'\n"), entry->target);
       return false;
     }
+
+  /* If we are searching for this file, see if the architecture is
+     compatible with the output file.  If it isn't, keep searching.
+     If we can't open the file as an object file, stop the search
+     here.  */
+
+  if (entry->search_dirs_flag)
+    {
+      bfd *check;
+
+      if (bfd_check_format (entry->the_bfd, bfd_archive))
+       check = bfd_openr_next_archived_file (entry->the_bfd, NULL);
+      else
+       check = entry->the_bfd;
+
+      if (! bfd_check_format (check, bfd_object))
+       return true;
+      if (bfd_arch_get_compatible (check, output_bfd) == NULL)
+       {
+         einfo (_("%P: skipping incompatible %s when searching for %s"),
+                attempt, entry->local_sym_name);
+         bfd_close (entry->the_bfd);
+         entry->the_bfd = NULL;
+         return false;
+       }
+    }
+
+  return true;
 }
 
 /* Search for and open the file specified by ENTRY.  If it is an