+2016-04-20  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * ldlang.c (lang_check_relocs): New function.
+       (lang_process): Call lang_check_relocs after lang_gc_sections.
+       * emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Don't
+       call _bfd_elf_link_check_relocs here.
+
 2016-04-20  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/19972
 
   if (!is_elf_hash_table (htab))
     return;
 
-  if (link_info.check_relocs_after_open_input)
-    {
-      bfd *abfd;
-
-      for (abfd = link_info.input_bfds;
-          abfd != (bfd *) NULL; abfd = abfd->link.next)
-       if (!_bfd_elf_link_check_relocs (abfd, &link_info))
-         {
-           /* no object output, fail return */
-           config.make_executable = FALSE;
-           return;
-         }
-    }
-
   if (emit_note_gnu_build_id != NULL)
     {
       bfd *abfd;
 
   link_info.gc_sym_list = sym;
 }
 
+/* Check relocations.  */
+
+static void
+lang_check_relocs (void)
+{
+  if (link_info.check_relocs_after_open_input
+      && bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour)
+    {
+      bfd *abfd;
+
+      for (abfd = link_info.input_bfds;
+          abfd != (bfd *) NULL; abfd = abfd->link.next)
+       if (!_bfd_elf_link_check_relocs (abfd, &link_info))
+         {
+           /* no object output, fail return */
+           config.make_executable = FALSE;
+           break;
+         }
+    }
+}
+
 void
 lang_process (void)
 {
   /* Remove unreferenced sections if asked to.  */
   lang_gc_sections ();
 
+  /* Check relocations.  */
+  lang_check_relocs ();
+
   /* Update wild statements.  */
   update_wild_statements (statement_list.head);