[lld] r311938 - Remove Symtab aliases.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 14:51:07 PDT 2017


Author: ruiu
Date: Mon Aug 28 14:51:07 2017
New Revision: 311938

URL: http://llvm.org/viewvc/llvm-project?rev=311938&view=rev
Log:
Remove Symtab aliases.

Various classes have `Symtab` member variables even though we have
lld::coff::Symtab variable because previous attempts to make COFF lld's
internal structure resemble to ELF's was incomplete. This patch finishes
that job by removing member variables.

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

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=311938&r1=311937&r2=311938&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Mon Aug 28 14:51:07 2017
@@ -55,9 +55,13 @@ std::vector<SpecificAllocBase *> Specifi
 bool link(ArrayRef<const char *> Args, raw_ostream &Diag) {
   ErrorCount = 0;
   ErrorOS = &Diag;
+
   Config = make<Configuration>();
   Config->Argv = {Args.begin(), Args.end()};
   Config->ColorDiagnostics = ErrorOS->has_colors();
+
+  Symtab = make<SymbolTable>();
+
   Driver = make<LinkerDriver>();
   Driver->link(Args);
   return !ErrorCount;
@@ -118,15 +122,15 @@ void LinkerDriver::addBuffer(std::unique
 
   FilePaths.push_back(MBRef.getBufferIdentifier());
   if (Magic == file_magic::archive)
-    return Symtab.addFile(make<ArchiveFile>(MBRef));
+    return Symtab->addFile(make<ArchiveFile>(MBRef));
   if (Magic == file_magic::bitcode)
-    return Symtab.addFile(make<BitcodeFile>(MBRef));
+    return Symtab->addFile(make<BitcodeFile>(MBRef));
 
   if (Magic == file_magic::coff_cl_gl_object)
     error(MBRef.getBufferIdentifier() + ": is not a native COFF file. "
           "Recompile without /GL");
   else
-    Symtab.addFile(make<ObjFile>(MBRef));
+    Symtab->addFile(make<ObjFile>(MBRef));
 }
 
 void LinkerDriver::enqueuePath(StringRef Path) {
@@ -146,7 +150,7 @@ void LinkerDriver::addArchiveBuffer(Memo
                                     StringRef ParentName) {
   file_magic Magic = identify_magic(MB.getBuffer());
   if (Magic == file_magic::coff_import_library) {
-    Symtab.addFile(make<ImportFile>(MB));
+    Symtab->addFile(make<ImportFile>(MB));
     return;
   }
 
@@ -161,7 +165,7 @@ void LinkerDriver::addArchiveBuffer(Memo
   }
 
   Obj->ParentName = ParentName;
-  Symtab.addFile(Obj);
+  Symtab->addFile(Obj);
   log("Loaded " + toString(Obj) + " for " + SymName);
 }
 
@@ -314,7 +318,7 @@ void LinkerDriver::addLibSearchPaths() {
 }
 
 SymbolBody *LinkerDriver::addUndefined(StringRef Name) {
-  SymbolBody *B = Symtab.addUndefined(Name);
+  SymbolBody *B = Symtab->addUndefined(Name);
   Config->GCRoot.insert(B);
   return B;
 }
@@ -337,8 +341,8 @@ StringRef LinkerDriver::findDefaultEntry
       {"wWinMain", "wWinMainCRTStartup"},
   };
   for (auto E : Entries) {
-    StringRef Entry = Symtab.findMangle(mangle(E[0]));
-    if (!Entry.empty() && !isa<Undefined>(Symtab.find(Entry)->body()))
+    StringRef Entry = Symtab->findMangle(mangle(E[0]));
+    if (!Entry.empty() && !isa<Undefined>(Symtab->find(Entry)->body()))
       return mangle(E[1]);
   }
   return "";
@@ -347,9 +351,9 @@ StringRef LinkerDriver::findDefaultEntry
 WindowsSubsystem LinkerDriver::inferSubsystem() {
   if (Config->DLL)
     return IMAGE_SUBSYSTEM_WINDOWS_GUI;
-  if (Symtab.findUnderscore("main") || Symtab.findUnderscore("wmain"))
+  if (Symtab->findUnderscore("main") || Symtab->findUnderscore("wmain"))
     return IMAGE_SUBSYSTEM_WINDOWS_CUI;
-  if (Symtab.findUnderscore("WinMain") || Symtab.findUnderscore("wWinMain"))
+  if (Symtab->findUnderscore("WinMain") || Symtab->findUnderscore("wWinMain"))
     return IMAGE_SUBSYSTEM_WINDOWS_GUI;
   return IMAGE_SUBSYSTEM_UNKNOWN;
 }
@@ -654,7 +658,7 @@ void LinkerDriver::invokeMSVC(opt::Input
     }
   }
 
-  std::vector<StringRef> ObjFiles = Symtab.compileBitcodeFiles();
+  std::vector<StringRef> ObjFiles = Symtab->compileBitcodeFiles();
   runMSVCLinker(Rsp, ObjFiles);
 
   for (StringRef Path : Temps)
@@ -1071,21 +1075,21 @@ void LinkerDriver::link(ArrayRef<const c
   if (Config->ImageBase == uint64_t(-1))
     Config->ImageBase = getDefaultImageBase();
 
-  Symtab.addSynthetic(mangle("__ImageBase"), nullptr);
+  Symtab->addSynthetic(mangle("__ImageBase"), nullptr);
   if (Config->Machine == I386) {
-    Symtab.addAbsolute("___safe_se_handler_table", 0);
-    Symtab.addAbsolute("___safe_se_handler_count", 0);
+    Symtab->addAbsolute("___safe_se_handler_table", 0);
+    Symtab->addAbsolute("___safe_se_handler_count", 0);
   }
 
   // We do not support /guard:cf (control flow protection) yet.
   // Define CFG symbols anyway so that we can link MSVC 2015 CRT.
-  Symtab.addAbsolute(mangle("__guard_fids_count"), 0);
-  Symtab.addAbsolute(mangle("__guard_fids_table"), 0);
-  Symtab.addAbsolute(mangle("__guard_flags"), 0x100);
-  Symtab.addAbsolute(mangle("__guard_iat_count"), 0);
-  Symtab.addAbsolute(mangle("__guard_iat_table"), 0);
-  Symtab.addAbsolute(mangle("__guard_longjmp_count"), 0);
-  Symtab.addAbsolute(mangle("__guard_longjmp_table"), 0);
+  Symtab->addAbsolute(mangle("__guard_fids_count"), 0);
+  Symtab->addAbsolute(mangle("__guard_fids_table"), 0);
+  Symtab->addAbsolute(mangle("__guard_flags"), 0x100);
+  Symtab->addAbsolute(mangle("__guard_iat_count"), 0);
+  Symtab->addAbsolute(mangle("__guard_iat_table"), 0);
+  Symtab->addAbsolute(mangle("__guard_longjmp_count"), 0);
+  Symtab->addAbsolute(mangle("__guard_longjmp_table"), 0);
 
   // This code may add new undefined symbols to the link, which may enqueue more
   // symbol resolution tasks, so we need to continue executing tasks until we
@@ -1094,7 +1098,7 @@ void LinkerDriver::link(ArrayRef<const c
     // Windows specific -- if entry point is not found,
     // search for its mangled names.
     if (Config->Entry)
-      Symtab.mangleMaybe(Config->Entry);
+      Symtab->mangleMaybe(Config->Entry);
 
     // Windows specific -- Make sure we resolve all dllexported symbols.
     for (Export &E : Config->Exports) {
@@ -1102,7 +1106,7 @@ void LinkerDriver::link(ArrayRef<const c
         continue;
       E.Sym = addUndefined(E.Name);
       if (!E.Directives)
-        Symtab.mangleMaybe(E.Sym);
+        Symtab->mangleMaybe(E.Sym);
     }
 
     // Add weak aliases. Weak aliases is a mechanism to give remaining
@@ -1110,16 +1114,16 @@ void LinkerDriver::link(ArrayRef<const c
     for (auto Pair : Config->AlternateNames) {
       StringRef From = Pair.first;
       StringRef To = Pair.second;
-      Symbol *Sym = Symtab.find(From);
+      Symbol *Sym = Symtab->find(From);
       if (!Sym)
         continue;
       if (auto *U = dyn_cast<Undefined>(Sym->body()))
         if (!U->WeakAlias)
-          U->WeakAlias = Symtab.addUndefined(To);
+          U->WeakAlias = Symtab->addUndefined(To);
     }
 
     // Windows specific -- if __load_config_used can be resolved, resolve it.
-    if (Symtab.findUnderscore("_load_config_used"))
+    if (Symtab->findUnderscore("_load_config_used"))
       addUndefined(mangle("_load_config_used"));
   } while (run());
 
@@ -1135,11 +1139,11 @@ void LinkerDriver::link(ArrayRef<const c
 
   // Do LTO by compiling bitcode input files to a set of native COFF files then
   // link those files.
-  Symtab.addCombinedLTOObjects();
+  Symtab->addCombinedLTOObjects();
   run();
 
   // Make sure we have resolved all symbols.
-  Symtab.reportRemainingUndefines();
+  Symtab->reportRemainingUndefines();
 
   // Windows specific -- if no /subsystem is given, we need to infer
   // that from entry point name.
@@ -1170,7 +1174,7 @@ void LinkerDriver::link(ArrayRef<const c
   for (auto Pair : Config->AlignComm) {
     StringRef Name = Pair.first;
     int Align = Pair.second;
-    Symbol *Sym = Symtab.find(Name);
+    Symbol *Sym = Symtab->find(Name);
     if (!Sym) {
       warn("/aligncomm symbol " + Name + " not found");
       continue;
@@ -1189,14 +1193,14 @@ void LinkerDriver::link(ArrayRef<const c
 
   // Identify unreferenced COMDAT sections.
   if (Config->DoGC)
-    markLive(Symtab.getChunks());
+    markLive(Symtab->getChunks());
 
   // Identify identical COMDAT sections to merge them.
   if (Config->DoICF)
-    doICF(Symtab.getChunks());
+    doICF(Symtab->getChunks());
 
   // Write the result.
-  writeResult(&Symtab);
+  writeResult();
 
   // Call exit to avoid calling destructors.
   exit(0);

Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=311938&r1=311937&r2=311938&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Mon Aug 28 14:51:07 2017
@@ -66,7 +66,6 @@ private:
 
 class LinkerDriver {
 public:
-  LinkerDriver() { coff::Symtab = &Symtab; }
   void link(llvm::ArrayRef<const char *> Args);
 
   // Used by the resolver to parse .drectve section contents.
@@ -77,8 +76,6 @@ public:
                             StringRef ParentName);
 
 private:
-  SymbolTable Symtab;
-
   std::unique_ptr<llvm::TarWriter> Tar; // for /linkrepro
 
   // Opens a file. Path has to be resolved already.

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=311938&r1=311937&r2=311938&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Mon Aug 28 14:51:07 2017
@@ -108,7 +108,6 @@ public:
 // The writer writes a SymbolTable result to a file.
 class Writer {
 public:
-  Writer(SymbolTable *T) : Symtab(T) {}
   void run();
 
 private:
@@ -138,7 +137,6 @@ private:
   uint32_t getSizeOfInitializedData();
   std::map<StringRef, std::vector<DefinedImportData *>> binImports();
 
-  SymbolTable *Symtab;
   std::unique_ptr<FileOutputBuffer> Buffer;
   std::vector<OutputSection *> OutputSections;
   std::vector<char> Strtab;
@@ -164,7 +162,7 @@ private:
 namespace lld {
 namespace coff {
 
-void writeResult(SymbolTable *T) { Writer(T).run(); }
+void writeResult() { Writer().run(); }
 
 void OutputSection::setRVA(uint64_t RVA) {
   Header.VirtualAddress = RVA;

Modified: lld/trunk/COFF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.h?rev=311938&r1=311937&r2=311938&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.h (original)
+++ lld/trunk/COFF/Writer.h Mon Aug 28 14:51:07 2017
@@ -18,11 +18,9 @@
 
 namespace lld {
 namespace coff {
-class SymbolTable;
-
 static const int PageSize = 4096;
 
-void writeResult(SymbolTable *T);
+void writeResult();
 
 // OutputSection represents a section in an output file. It's a
 // container of chunks. OutputSection and Chunk are 1:N relationship.




More information about the llvm-commits mailing list