[lld] r361477 - Remove LazyObjFile::AddedToLink.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu May 23 03:08:56 PDT 2019


Author: ruiu
Date: Thu May 23 03:08:56 2019
New Revision: 361477

URL: http://llvm.org/viewvc/llvm-project?rev=361477&view=rev
Log:
Remove LazyObjFile::AddedToLink.

Instead we can just clear a MemoryBuffer so that we cannot get the
same buffer more than once.

Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/LTO.cpp

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=361477&r1=361476&r2=361477&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu May 23 03:08:56 2019
@@ -1469,21 +1469,15 @@ InputFile *elf::createSharedFile(MemoryB
   return F;
 }
 
-MemoryBufferRef LazyObjFile::getBuffer() {
-  if (AddedToLink)
-    return MemoryBufferRef();
-  AddedToLink = true;
-  return MB;
-}
-
 InputFile *LazyObjFile::fetch() {
-  MemoryBufferRef MBRef = getBuffer();
-  if (MBRef.getBuffer().empty())
+  if (MB.getBuffer().empty())
     return nullptr;
 
-  InputFile *File = createObjectFile(MBRef, ArchiveName, OffsetInArchive);
+  InputFile *File = createObjectFile(MB, ArchiveName, OffsetInArchive);
   File->GroupId = GroupId;
 
+  MB = {};
+
   // Copy symbol vector so that the new InputFile doesn't have to
   // insert the same defined symbols to the symbol table again.
   File->Symbols = std::move(Symbols);
@@ -1538,7 +1532,9 @@ template <class ELFT> void LazyObjFile::
       if (!Sym)
         continue;
       Sym->resolve(LazyObject{*this, Sym->getName()});
-      if (AddedToLink)
+
+      // MemoryBuffer is emptied if this file is instantiated as ObjFile.
+      if (MB.getBuffer().empty())
         return;
     }
     return;

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=361477&r1=361476&r2=361477&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Thu May 23 03:08:56 2019
@@ -307,9 +307,7 @@ public:
   static bool classof(const InputFile *F) { return F->kind() == LazyObjKind; }
 
   template <class ELFT> void parse();
-  MemoryBufferRef getBuffer();
   InputFile *fetch();
-  bool AddedToLink = false;
 
 private:
   uint64_t OffsetInArchive;

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=361477&r1=361476&r2=361477&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Thu May 23 03:08:56 2019
@@ -212,7 +212,7 @@ void BitcodeCompiler::add(BitcodeFile &F
 // distributed build system that depends on that behavior.
 static void thinLTOCreateEmptyIndexFiles() {
   for (LazyObjFile *F : LazyObjFiles) {
-    if (F->AddedToLink || !isBitcode(F->MB))
+    if (!isBitcode(F->MB))
       continue;
     std::string Path = replaceThinLTOSuffix(getThinLTOOutputFile(F->getName()));
     std::unique_ptr<raw_fd_ostream> OS = openFile(Path + ".thinlto.bc");




More information about the llvm-commits mailing list