[lld] r244180 - COFF, ELF2: Pass output file path implicitly using Config global variable.

Rui Ueyama ruiu at google.com
Wed Aug 5 16:51:50 PDT 2015


Author: ruiu
Date: Wed Aug  5 18:51:50 2015
New Revision: 244180

URL: http://llvm.org/viewvc/llvm-project?rev=244180&view=rev
Log:
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 *).

Modified:
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Writer.cpp
    lld/trunk/COFF/Writer.h
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Writer.cpp
    lld/trunk/ELF/Writer.h

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=244180&r1=244179&r2=244180&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Aug  5 18:51:50 2015
@@ -726,7 +726,7 @@ bool LinkerDriver::link(llvm::ArrayRef<c
     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;
   }

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=244180&r1=244179&r2=244180&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Wed Aug  5 18:51:50 2015
@@ -45,7 +45,7 @@ namespace {
 // 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 @@ private:
   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 @@ private:
 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 @@ std::error_code Writer::run() {
   assignAddresses();
   removeEmptySections();
   createSymbolAndStringTable();
-  if (auto EC = openFile(OutputPath))
+  if (auto EC = openFile(Config->OutputFile))
     return EC;
   if (Config->is64()) {
     writeHeader<pe32plus_header>();

Modified: lld/trunk/COFF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.h?rev=244180&r1=244179&r2=244180&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.h (original)
+++ lld/trunk/COFF/Writer.h Wed Aug  5 18:51:50 2015
@@ -18,7 +18,7 @@ namespace coff {
 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);

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=244180&r1=244179&r2=244180&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Aug  5 18:51:50 2015
@@ -119,16 +119,16 @@ void LinkerDriver::link(ArrayRef<const c
   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;
   }
 }

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=244180&r1=244179&r2=244180&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Aug  5 18:51:50 2015
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Chunks.h"
+#include "Config.h"
 #include "Driver.h"
 #include "SymbolTable.h"
 #include "Writer.h"
@@ -28,7 +29,7 @@ namespace {
 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 @@ private:
   void writeSections();
 
   SymbolTable *Symtab;
-  StringRef OutputPath;
   std::unique_ptr<llvm::FileOutputBuffer> Buffer;
   llvm::SpecificBumpPtrAllocator<OutputSection> CAlloc;
   std::vector<OutputSection *> OutputSections;
@@ -80,14 +80,12 @@ private:
 };
 
 template <class ELFT>
-void writeResult(SymbolTable *Symtab, StringRef Path) {
-  Writer<ELFT>(Symtab, Path).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);
+void writeResult(SymbolTable *Symtab) { Writer<ELFT>(Symtab).run(); }
+
+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 void writeResult<ELF64BE>(Symbo
 template <class ELFT> void Writer<ELFT>::run() {
   createSections();
   assignAddresses();
-  openFile(OutputPath);
+  openFile(Config->OutputFile);
   writeHeader();
   writeSections();
   error(Buffer->commit());

Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=244180&r1=244179&r2=244180&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Wed Aug  5 18:51:50 2015
@@ -17,7 +17,7 @@ class OutputSection;
 class SymbolTable;
 
 template <class ELFT>
-void writeResult(SymbolTable *Symtab, StringRef Path);
+void writeResult(SymbolTable *Symtab);
 
 }
 }




More information about the llvm-commits mailing list