Add linker-script-included files to reproduce tar files.

Previously, files added using INCLUDE directive weren't added
to reproduce archives. In this patch, I defined a function to
open a file and use that from Driver and LinkerScript.

llvm-svn: 291413
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index ccc1059..e26ab8c 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -1143,20 +1143,21 @@
 
 void ScriptParser::readInclude() {
   StringRef Tok = unquote(next());
+
   // https://sourceware.org/binutils/docs/ld/File-Commands.html:
   // The file will be searched for in the current directory, and in any
   // directory specified with the -L option.
-  auto MBOrErr = MemoryBuffer::getFile(Tok);
-  if (!MBOrErr)
-    if (Optional<std::string> Path = findFromSearchPaths(Tok))
-      MBOrErr = MemoryBuffer::getFile(*Path);
-  if (!MBOrErr) {
-    setError("cannot open " + Tok);
+  if (sys::fs::exists(Tok)) {
+    if (Optional<MemoryBufferRef> MB = readFile(Tok))
+      tokenize(*MB);
     return;
   }
-  MemoryBufferRef MBRef = (*MBOrErr)->getMemBufferRef();
-  make<std::unique_ptr<MemoryBuffer>>(std::move(*MBOrErr)); // take MB ownership
-  tokenize(MBRef);
+  if (Optional<std::string> Path = findFromSearchPaths(Tok)) {
+    if (Optional<MemoryBufferRef> MB = readFile(*Path))
+      tokenize(*MB);
+    return;
+  }
+  setError("cannot open " + Tok);
 }
 
 void ScriptParser::readOutput() {