[PECOFF] Fix priority of locally imported symbols.

Linker should create _imp_ symbols for local use only when such
symbols cannot be resolved in any other way. If it overrides real
imported symbols, such symbols remain virtually unresolved without
error, causing odd issues. I observed that a program linked with
LLD entered an infinite loop before reaching main() because of
this issue.

This patch moves the virtual file creating _imp_ symbols to the
very end of the input file list. Previously, the file is at the end
of the library file group. Linker might revisit the group many times,
so it was not really at the end of the input file list.

llvm-svn: 207605
diff --git a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
index d9117d0..ff8ed1b 100644
--- a/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
+++ b/lld/lib/ReaderWriter/PECOFF/PECOFFLinkingContext.cpp
@@ -114,7 +114,8 @@
   std::unique_ptr<SimpleFileNode> impFileNode(new SimpleFileNode("imp"));
   impFileNode->appendInputFile(
       std::unique_ptr<File>(new pecoff::LocallyImportedSymbolFile(*this)));
-  getLibraryGroup()->addFile(std::move(impFileNode));
+  getInputGraph().insertElementAt(std::move(impFileNode),
+                                  InputGraph::Position::END);
   return true;
 }
 
diff --git a/lld/test/pecoff/Inputs/drectve.obj.yaml b/lld/test/pecoff/Inputs/drectve.obj.yaml
index cc0c825..22ec63f 100644
--- a/lld/test/pecoff/Inputs/drectve.obj.yaml
+++ b/lld/test/pecoff/Inputs/drectve.obj.yaml
@@ -58,6 +58,12 @@
     SimpleType:      IMAGE_SYM_TYPE_NULL
     ComplexType:     IMAGE_SYM_DTYPE_NULL
     StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
+  - Name:            _fn
+    Value:           0
+    SectionNumber:   0
+    SimpleType:      IMAGE_SYM_TYPE_NULL
+    ComplexType:     IMAGE_SYM_DTYPE_NULL
+    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
   - Name:            .drectve
     Value:           0
     SectionNumber:   2