[lld] r241214 - COFF: Change GCRoot member type from StringRef to Undefined. NFC.

Rui Ueyama ruiu at google.com
Wed Jul 1 17:21:09 PDT 2015


Author: ruiu
Date: Wed Jul  1 19:21:08 2015
New Revision: 241214

URL: http://llvm.org/viewvc/llvm-project?rev=241214&view=rev
Log:
COFF: Change GCRoot member type from StringRef to Undefined. NFC.

I think Undefined symbols are a bit more convenient than StringRefs
since SymbolBodies are handles for symbols. You can get resolved
symbols for undefined symbols just by calling getReplacmenet without
looking up the symbol table.

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

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=241214&r1=241213&r2=241214&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Wed Jul  1 19:21:08 2015
@@ -50,7 +50,7 @@ struct Configuration {
   bool Force = false;
 
   // Symbols in this set are considered as live by the garbage collector.
-  std::set<StringRef> GCRoots;
+  std::set<Undefined *> GCRoot;
 
   std::set<StringRef> NoDefaultLibs;
   bool NoDefaultLibAll = false;

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=241214&r1=241213&r2=241214&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Jul  1 19:21:08 2015
@@ -204,7 +204,7 @@ void LinkerDriver::addLibSearchPaths() {
 
 Undefined *LinkerDriver::addUndefined(StringRef Name) {
   Undefined *U = Symtab.addUndefined(Name);
-  Config->GCRoots.insert(Name);
+  Config->GCRoot.insert(U);
   return U;
 }
 

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=241214&r1=241213&r2=241214&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Wed Jul  1 19:21:08 2015
@@ -391,9 +391,9 @@ ErrorOr<ObjectFile *> SymbolTable::creat
         CG->addMustPreserveSymbol(Body->getName());
 
   // Likewise for other symbols that must be preserved.
-  for (StringRef Name : Config->GCRoots)
-    if (isa<DefinedBitcode>(Symtab[Name]->Body))
-      CG->addMustPreserveSymbol(Name);
+  for (Undefined *U : Config->GCRoot)
+    if (isa<DefinedBitcode>(U->getReplacement()))
+      CG->addMustPreserveSymbol(U->getName());
 
   CG->setModule(BitcodeFiles[0]->releaseModule());
   for (unsigned I = 1, E = BitcodeFiles.size(); I != E; ++I)

Modified: lld/trunk/COFF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Writer.cpp?rev=241214&r1=241213&r2=241214&view=diff
==============================================================================
--- lld/trunk/COFF/Writer.cpp (original)
+++ lld/trunk/COFF/Writer.cpp Wed Jul  1 19:21:08 2015
@@ -117,19 +117,20 @@ void Writer::markLive() {
   // as we push, so sections never appear twice in the list.
   SmallVector<SectionChunk *, 256> Worklist;
 
-  for (StringRef Name : Config->GCRoots)
-    if (auto *D = dyn_cast<DefinedRegular>(Symtab->find(Name)))
-      if (!D->isLive()) {
-        D->markLive();
-        Worklist.push_back(D->getChunk());
-      }
-  for (Chunk *C : Symtab->getChunks())
-    if (auto *SC = dyn_cast<SectionChunk>(C))
-      if (SC->isRoot() && !SC->isLive()) {
-        SC->markLive();
-        Worklist.push_back(SC);
-      }
-
+  for (Undefined *U : Config->GCRoot) {
+    auto *D = cast<DefinedRegular>(U->getReplacement());
+    if (D->isLive())
+      continue;
+    D->markLive();
+    Worklist.push_back(D->getChunk());
+  }
+  for (Chunk *C : Symtab->getChunks()) {
+    auto *SC = dyn_cast<SectionChunk>(C);
+    if (!SC || !SC->isRoot() || SC->isLive())
+      continue;
+    SC->markLive();
+    Worklist.push_back(SC);
+  }
   while (!Worklist.empty()) {
     SectionChunk *SC = Worklist.pop_back_val();
     assert(SC->isLive() && "We mark as live when pushing onto the worklist!");





More information about the llvm-commits mailing list