COFF, ELF2: Pass output file path implicitly using Config global variable.

Various parameters are passed implicitly using Config global variable
already. Output file path is no different from others, so there was no
special reason to handle that differnetly.

This patch changes the signature of writeResult(SymbolTable *, StringRef)
to writeResult(SymbolTable *).

llvm-svn: 244180
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index fc5d040..088e536 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -726,7 +726,7 @@
     touchFile(Arg->getValue());
 
   // Write the result.
-  if (auto EC = writeResult(&Symtab, Config->OutputFile)) {
+  if (auto EC = writeResult(&Symtab)) {
     llvm::errs() << EC.message() << "\n";
     return false;
   }
diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp
index 0d34587..f08d948 100644
--- a/lld/COFF/Writer.cpp
+++ b/lld/COFF/Writer.cpp
@@ -45,7 +45,7 @@
 // The writer writes a SymbolTable result to a file.
 class Writer {
 public:
-  Writer(SymbolTable *T, StringRef S) : Symtab(T), OutputPath(S) {}
+  Writer(SymbolTable *T) : Symtab(T) {}
   std::error_code run();
 
 private:
@@ -77,7 +77,6 @@
   std::map<StringRef, std::vector<DefinedImportData *>> binImports();
 
   SymbolTable *Symtab;
-  StringRef OutputPath;
   std::unique_ptr<llvm::FileOutputBuffer> Buffer;
   llvm::SpecificBumpPtrAllocator<OutputSection> CAlloc;
   llvm::SpecificBumpPtrAllocator<BaserelChunk> BAlloc;
@@ -102,9 +101,7 @@
 namespace lld {
 namespace coff {
 
-std::error_code writeResult(SymbolTable *T, StringRef Path) {
-  return Writer(T, Path).run();
-}
+std::error_code writeResult(SymbolTable *T) { return Writer(T).run(); }
 
 // OutputSection represents a section in an output file. It's a
 // container of chunks. OutputSection and Chunk are 1:N relationship.
@@ -233,7 +230,7 @@
   assignAddresses();
   removeEmptySections();
   createSymbolAndStringTable();
-  if (auto EC = openFile(OutputPath))
+  if (auto EC = openFile(Config->OutputFile))
     return EC;
   if (Config->is64()) {
     writeHeader<pe32plus_header>();
diff --git a/lld/COFF/Writer.h b/lld/COFF/Writer.h
index 37caae8..0a213e2 100644
--- a/lld/COFF/Writer.h
+++ b/lld/COFF/Writer.h
@@ -18,7 +18,7 @@
 class Chunk;
 class OutputSection;
 
-std::error_code writeResult(SymbolTable *T, StringRef Path);
+std::error_code writeResult(SymbolTable *T);
 
 // Implemented in ICF.cpp.
 void doICF(const std::vector<Chunk *> &Chunks);
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index ab4fc2e..f48a33b 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -119,16 +119,16 @@
   ObjectFileBase &FirstObj = *Symtab.ObjectFiles[0];
   switch (FirstObj.kind()) {
   case InputFile::Object32LEKind:
-    writeResult<object::ELF32LE>(&Symtab, Config->OutputFile);
+    writeResult<object::ELF32LE>(&Symtab);
     return;
   case InputFile::Object32BEKind:
-    writeResult<object::ELF32BE>(&Symtab, Config->OutputFile);
+    writeResult<object::ELF32BE>(&Symtab);
     return;
   case InputFile::Object64LEKind:
-    writeResult<object::ELF64LE>(&Symtab, Config->OutputFile);
+    writeResult<object::ELF64LE>(&Symtab);
     return;
   case InputFile::Object64BEKind:
-    writeResult<object::ELF64BE>(&Symtab, Config->OutputFile);
+    writeResult<object::ELF64BE>(&Symtab);
     return;
   }
 }
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index b7bfd46..e4c5617 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Chunks.h"
+#include "Config.h"
 #include "Driver.h"
 #include "SymbolTable.h"
 #include "Writer.h"
@@ -28,7 +29,7 @@
 template <class ELFT> class Writer {
 public:
   typedef typename llvm::object::ELFFile<ELFT>::uintX_t uintX_t;
-  Writer(SymbolTable *T, StringRef S) : Symtab(T), OutputPath(S) {}
+  Writer(SymbolTable *T) : Symtab(T) {}
   void run();
 
 private:
@@ -39,7 +40,6 @@
   void writeSections();
 
   SymbolTable *Symtab;
-  StringRef OutputPath;
   std::unique_ptr<llvm::FileOutputBuffer> Buffer;
   llvm::SpecificBumpPtrAllocator<OutputSection> CAlloc;
   std::vector<OutputSection *> OutputSections;
@@ -80,14 +80,12 @@
 };
 
 template <class ELFT>
-void writeResult(SymbolTable *Symtab, StringRef Path) {
-  Writer<ELFT>(Symtab, Path).run();
-}
+void writeResult(SymbolTable *Symtab) { Writer<ELFT>(Symtab).run(); }
 
-template void writeResult<ELF32LE>(SymbolTable *, StringRef);
-template void writeResult<ELF32BE>(SymbolTable *, StringRef);
-template void writeResult<ELF64LE>(SymbolTable *, StringRef);
-template void writeResult<ELF64BE>(SymbolTable *, StringRef);
+template void writeResult<ELF32LE>(SymbolTable *);
+template void writeResult<ELF32BE>(SymbolTable *);
+template void writeResult<ELF64LE>(SymbolTable *);
+template void writeResult<ELF64BE>(SymbolTable *);
 
 } // namespace elf2
 } // namespace lld
@@ -96,7 +94,7 @@
 template <class ELFT> void Writer<ELFT>::run() {
   createSections();
   assignAddresses();
-  openFile(OutputPath);
+  openFile(Config->OutputFile);
   writeHeader();
   writeSections();
   error(Buffer->commit());
diff --git a/lld/ELF/Writer.h b/lld/ELF/Writer.h
index 5302d6b..b54251e 100644
--- a/lld/ELF/Writer.h
+++ b/lld/ELF/Writer.h
@@ -17,7 +17,7 @@
 class SymbolTable;
 
 template <class ELFT>
-void writeResult(SymbolTable *Symtab, StringRef Path);
+void writeResult(SymbolTable *Symtab);
 
 }
 }