+ if (flaginfo.info->strip != strip_all && flaginfo.info->discard != discard_all)
+ {
+ /* Add local symbols from foreign inputs. */
+ for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
+ {
+ unsigned int i;
+
+ if (bfd_family_coff (sub) || ! bfd_get_outsymbols (sub))
+ continue;
+ for (i = 0; i < bfd_get_symcount (sub); ++i)
+ {
+ asymbol *sym = bfd_get_outsymbols (sub) [i];
+ file_ptr pos;
+ struct internal_syment isym;
+ union internal_auxent iaux;
+ bfd_size_type string_size = 0, indx;
+ bfd_vma written = 0;
+ bfd_boolean rewrite = FALSE, hash;
+
+ if (! (sym->flags & BSF_LOCAL)
+ || (sym->flags & (BSF_SECTION_SYM | BSF_DEBUGGING_RELOC
+ | BSF_THREAD_LOCAL | BSF_RELC | BSF_SRELC
+ | BSF_SYNTHETIC))
+ || ((sym->flags & BSF_DEBUGGING)
+ && ! (sym->flags & BSF_FILE)))
+ continue;
+
+ /* See if we are discarding symbols with this name. */
+ if ((flaginfo.info->strip == strip_some
+ && (bfd_hash_lookup (flaginfo.info->keep_hash,
+ bfd_asymbol_name(sym), FALSE, FALSE)
+ == NULL))
+ || (((flaginfo.info->discard == discard_sec_merge
+ && (bfd_get_section (sym)->flags & SEC_MERGE)
+ && ! bfd_link_relocatable (flaginfo.info))
+ || flaginfo.info->discard == discard_l)
+ && bfd_is_local_label_name (sub, bfd_asymbol_name(sym))))
+ continue;
+
+ pos = obj_sym_filepos (abfd) + obj_raw_syment_count (abfd)
+ * symesz;
+ if (bfd_seek (abfd, pos, SEEK_SET) != 0)
+ goto error_return;
+ if (! coff_write_alien_symbol(abfd, sym, &isym, &iaux, &written,
+ &string_size, NULL, NULL))
+ goto error_return;
+
+ hash = !flaginfo.info->traditional_format;
+
+ if (string_size >= 6 && isym.n_sclass == C_FILE
+ && ! isym._n._n_n._n_zeroes && isym.n_numaux)
+ {
+ indx = _bfd_stringtab_add (flaginfo.strtab, ".file", hash,
+ FALSE);
+ if (indx == (bfd_size_type) -1)
+ goto error_return;
+ isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
+ bfd_coff_swap_sym_out (abfd, &isym, flaginfo.outsyms);
+ if (bfd_seek (abfd, pos, SEEK_SET) != 0
+ || bfd_bwrite (flaginfo.outsyms, symesz,
+ abfd) != symesz)
+ goto error_return;
+ string_size -= 6;
+ }
+
+ if (string_size)
+ {
+ indx = _bfd_stringtab_add (flaginfo.strtab,
+ bfd_asymbol_name (sym), hash,
+ FALSE);
+ if (indx == (bfd_size_type) -1)
+ goto error_return;
+ if (isym.n_sclass != C_FILE)
+ {
+ isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
+ bfd_coff_swap_sym_out (abfd, &isym, flaginfo.outsyms);
+ rewrite = TRUE;
+ }
+ else
+ {
+ BFD_ASSERT (isym.n_numaux == 1);
+ iaux.x_file.x_n.x_offset = STRING_SIZE_SIZE + indx;
+ bfd_coff_swap_aux_out (abfd, &iaux, isym.n_type, C_FILE,
+ 0, 1, flaginfo.outsyms + symesz);
+ if (bfd_seek (abfd, pos + symesz, SEEK_SET) != 0
+ || bfd_bwrite (flaginfo.outsyms + symesz, symesz,
+ abfd) != symesz)
+ goto error_return;
+ }
+ }
+
+ if (isym.n_sclass == C_FILE)
+ {
+ if (flaginfo.last_file_index != -1)
+ {
+ flaginfo.last_file.n_value = obj_raw_syment_count (abfd);
+ bfd_coff_swap_sym_out (abfd, &flaginfo.last_file,
+ flaginfo.outsyms);
+ pos = obj_sym_filepos (abfd) + flaginfo.last_file_index
+ * symesz;
+ rewrite = TRUE;
+ }
+ flaginfo.last_file_index = obj_raw_syment_count (abfd);
+ flaginfo.last_file = isym;
+ }
+
+ if (rewrite
+ && (bfd_seek (abfd, pos, SEEK_SET) != 0
+ || bfd_bwrite (flaginfo.outsyms, symesz, abfd) != symesz))
+ goto error_return;
+
+ obj_raw_syment_count (abfd) += written;
+ }
+ }
+ }
+
+ if (! bfd_coff_final_link_postscript (abfd, & flaginfo))