+2012-06-25  Alan Modra  <amodra@gmail.com>
+
+       * ldlang.c (load_symbols): Close file and set flags.loaded
+       after parsing script file.
+       (open_input_bfds): Don't segv on closed script.
+
 2012-06-24  H.J. Lu  <hongjiu.lu@intel.com>
 
        * configure.tgt: Enable elf_k1om for x86_64-*-linux-gnux32.
 
     {
       bfd_error_type err;
       struct lang_input_statement_flags save_flags;
+      extern FILE *yyin;
 
       err = bfd_get_error ();
 
       save_flags.missing_file |= input_flags.missing_file;
       input_flags = save_flags;
       pop_stat_ptr ();
+      fclose (yyin);
+      yyin = NULL;
+      entry->flags.loaded = TRUE;
 
       return TRUE;
     }
 #endif
                  && !s->input_statement.flags.whole_archive
                  && s->input_statement.flags.loaded
+                 && s->input_statement.the_bfd != NULL
                  && bfd_check_format (s->input_statement.the_bfd,
                                       bfd_archive))
                s->input_statement.flags.loaded = FALSE;
                       && plugin_insert == NULL
                       && s->input_statement.flags.loaded
                       && s->input_statement.flags.add_DT_NEEDED_for_regular
+                      && s->input_statement.the_bfd != NULL
                       && ((s->input_statement.the_bfd->flags) & DYNAMIC) != 0
                       && plugin_should_reload (s->input_statement.the_bfd))
                {