[lld] r285452 - Consolidate BumpPtrAllocators.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 28 13:57:26 PDT 2016


Author: ruiu
Date: Fri Oct 28 15:57:25 2016
New Revision: 285452

URL: http://llvm.org/viewvc/llvm-project?rev=285452&view=rev
Log:
Consolidate BumpPtrAllocators.

Previously, we have a lot of BumpPtrAllocators, but all these
allocators virtually have the same lifetime because they are
not freed until the linker finishes its job. This patch aggregates
them into a single allocator.

Differential revision: https://reviews.llvm.org/D26042

Added:
    lld/trunk/ELF/Memory.cpp
    lld/trunk/ELF/Memory.h
Modified:
    lld/trunk/ELF/CMakeLists.txt
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Driver.h
    lld/trunk/ELF/DriverUtils.cpp
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/ELF/InputFiles.h
    lld/trunk/ELF/LTO.cpp
    lld/trunk/ELF/LTO.h
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/LinkerScript.h
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/SymbolTable.h
    lld/trunk/ELF/Symbols.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/Thunks.cpp
    lld/trunk/ELF/Writer.cpp
    lld/trunk/ELF/Writer.h

Modified: lld/trunk/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/CMakeLists.txt?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/CMakeLists.txt (original)
+++ lld/trunk/ELF/CMakeLists.txt Fri Oct 28 15:57:25 2016
@@ -14,6 +14,7 @@ add_lld_library(lldELF
   LTO.cpp
   LinkerScript.cpp
   MarkLive.cpp
+  Memory.cpp
   Mips.cpp
   OutputSections.cpp
   Relocations.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Fri Oct 28 15:57:25 2016
@@ -14,6 +14,7 @@
 #include "InputFiles.h"
 #include "InputSection.h"
 #include "LinkerScript.h"
+#include "Memory.h"
 #include "Strings.h"
 #include "SymbolListFile.h"
 #include "SymbolTable.h"
@@ -54,6 +55,7 @@ bool elf::link(ArrayRef<const char *> Ar
 
   Driver->main(Args, CanExitEarly);
   InputFile::freePool();
+  freeArena();
   return !HasError;
 }
 
@@ -141,7 +143,7 @@ void LinkerDriver::addFile(StringRef Pat
   case file_magic::archive:
     if (InWholeArchive) {
       for (MemoryBufferRef MB : getArchiveMembers(MBRef))
-        Files.push_back(createObjectFile(Alloc, MB, Path));
+        Files.push_back(createObjectFile(MB, Path));
       return;
     }
     Files.push_back(new ArchiveFile(MBRef));
@@ -151,13 +153,13 @@ void LinkerDriver::addFile(StringRef Pat
       error("attempted static link of dynamic object " + Path);
       return;
     }
-    Files.push_back(createSharedFile(Alloc, MBRef));
+    Files.push_back(createSharedFile(MBRef));
     return;
   default:
     if (InLib)
       Files.push_back(new LazyObjectFile(MBRef));
     else
-      Files.push_back(createObjectFile(Alloc, MBRef));
+      Files.push_back(createObjectFile(MBRef));
   }
 }
 

Modified: lld/trunk/ELF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.h?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.h (original)
+++ lld/trunk/ELF/Driver.h Fri Oct 28 15:57:25 2016
@@ -50,7 +50,6 @@ private:
   // True if we are in -format=binary and -format=elf.
   bool InBinary = false;
 
-  llvm::BumpPtrAllocator Alloc;
   std::vector<InputFile *> Files;
   std::vector<std::unique_ptr<MemoryBuffer>> OwningMBs;
 };
@@ -60,9 +59,6 @@ class ELFOptTable : public llvm::opt::Op
 public:
   ELFOptTable();
   llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);
-
-private:
-  llvm::BumpPtrAllocator Alloc;
 };
 
 // Create enum with OPT_xxx values for each option in Options.td

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Fri Oct 28 15:57:25 2016
@@ -15,6 +15,7 @@
 
 #include "Driver.h"
 #include "Error.h"
+#include "Memory.h"
 #include "lld/Config/Version.h"
 #include "lld/Core/Reproduce.h"
 #include "llvm/ADT/STLExtras.h"
@@ -23,7 +24,6 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/StringSaver.h"
 
 using namespace llvm;
 using namespace llvm::sys;
@@ -78,7 +78,6 @@ opt::InputArgList ELFOptTable::parse(Arr
   opt::InputArgList Args = this->ParseArgs(Vec, MissingIndex, MissingCount);
 
   // Expand response files. '@<filename>' is replaced by the file's contents.
-  StringSaver Saver(Alloc);
   cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), Vec);
 
   // Parse options and then do error checking.

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Fri Oct 28 15:57:25 2016
@@ -12,6 +12,7 @@
 #include "Error.h"
 #include "InputSection.h"
 #include "LinkerScript.h"
+#include "Memory.h"
 #include "SymbolTable.h"
 #include "Symbols.h"
 #include "llvm/ADT/STLExtras.h"
@@ -142,8 +143,8 @@ template <class ELFT> void ELFFileBase<E
 }
 
 template <class ELFT>
-elf::ObjectFile<ELFT>::ObjectFile(BumpPtrAllocator &Alloc, MemoryBufferRef M)
-    : ELFFileBase<ELFT>(Base::ObjectKind, M), Alloc(Alloc) {}
+elf::ObjectFile<ELFT>::ObjectFile(MemoryBufferRef M)
+    : ELFFileBase<ELFT>(Base::ObjectKind, M) {}
 
 template <class ELFT>
 ArrayRef<SymbolBody *> elf::ObjectFile<ELFT>::getNonLocalSymbols() {
@@ -482,9 +483,9 @@ SymbolBody *elf::ObjectFile<ELFT>::creat
     if (Sym->getType() == STT_FILE)
       SourceFile = check(Sym->getName(this->StringTable));
     if (Sym->st_shndx == SHN_UNDEF)
-      return new (this->Alloc)
+      return new (BAlloc)
           Undefined(Sym->st_name, Sym->st_other, Sym->getType(), this);
-    return new (this->Alloc) DefinedRegular<ELFT>(*Sym, Sec);
+    return new (BAlloc) DefinedRegular<ELFT>(*Sym, Sec);
   }
 
   StringRef Name = check(Sym->getName(this->StringTable));
@@ -553,7 +554,7 @@ ArchiveFile::getMember(const Archive::Sy
 }
 
 template <class ELFT>
-SharedFile<ELFT>::SharedFile(BumpPtrAllocator &Alloc, MemoryBufferRef M)
+SharedFile<ELFT>::SharedFile(MemoryBufferRef M)
     : ELFFileBase<ELFT>(Base::SharedKind, M), AsNeeded(Config->AsNeeded) {}
 
 template <class ELFT>
@@ -745,7 +746,7 @@ static uint8_t mapVisibility(GlobalValue
 template <class ELFT>
 static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats,
                                    const lto::InputFile::Symbol &ObjSym,
-                                   StringSaver &Saver, BitcodeFile *F) {
+                                   BitcodeFile *F) {
   StringRef NameRef = Saver.save(ObjSym.getName());
   uint32_t Flags = ObjSym.getFlags();
   uint32_t Binding = (Flags & BasicSymbolRef::SF_Weak) ? STB_WEAK : STB_GLOBAL;
@@ -794,12 +795,11 @@ void BitcodeFile::parse(DenseSet<CachedH
   }
 
   for (const lto::InputFile::Symbol &ObjSym : Obj->symbols())
-    Symbols.push_back(
-        createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, Saver, this));
+    Symbols.push_back(createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, this));
 }
 
 template <template <class> class T>
-static InputFile *createELFFile(BumpPtrAllocator &Alloc, MemoryBufferRef MB) {
+static InputFile *createELFFile(MemoryBufferRef MB) {
   unsigned char Size;
   unsigned char Endian;
   std::tie(Size, Endian) = getElfArchType(MB.getBuffer());
@@ -808,13 +808,13 @@ static InputFile *createELFFile(BumpPtrA
 
   InputFile *Obj;
   if (Size == ELFCLASS32 && Endian == ELFDATA2LSB)
-    Obj = new T<ELF32LE>(Alloc, MB);
+    Obj = new T<ELF32LE>(MB);
   else if (Size == ELFCLASS32 && Endian == ELFDATA2MSB)
-    Obj = new T<ELF32BE>(Alloc, MB);
+    Obj = new T<ELF32BE>(MB);
   else if (Size == ELFCLASS64 && Endian == ELFDATA2LSB)
-    Obj = new T<ELF64LE>(Alloc, MB);
+    Obj = new T<ELF64LE>(MB);
   else if (Size == ELFCLASS64 && Endian == ELFDATA2MSB)
-    Obj = new T<ELF64BE>(Alloc, MB);
+    Obj = new T<ELF64BE>(MB);
   else
     fatal("invalid file class: " + MB.getBufferIdentifier());
 
@@ -853,18 +853,17 @@ static bool isBitcode(MemoryBufferRef MB
   return identify_magic(MB.getBuffer()) == file_magic::bitcode;
 }
 
-InputFile *elf::createObjectFile(BumpPtrAllocator &Alloc, MemoryBufferRef MB,
-                                 StringRef ArchiveName,
+InputFile *elf::createObjectFile(MemoryBufferRef MB, StringRef ArchiveName,
                                  uint64_t OffsetInArchive) {
-  InputFile *F = isBitcode(MB) ? new BitcodeFile(MB)
-                               : createELFFile<ObjectFile>(Alloc, MB);
+  InputFile *F =
+      isBitcode(MB) ? new BitcodeFile(MB) : createELFFile<ObjectFile>(MB);
   F->ArchiveName = ArchiveName;
   F->OffsetInArchive = OffsetInArchive;
   return F;
 }
 
-InputFile *elf::createSharedFile(BumpPtrAllocator &Alloc, MemoryBufferRef MB) {
-  return createELFFile<SharedFile>(Alloc, MB);
+InputFile *elf::createSharedFile(MemoryBufferRef MB) {
+  return createELFFile<SharedFile>(MB);
 }
 
 MemoryBufferRef LazyObjectFile::getBuffer() {

Modified: lld/trunk/ELF/InputFiles.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.h?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.h (original)
+++ lld/trunk/ELF/InputFiles.h Fri Oct 28 15:57:25 2016
@@ -24,7 +24,6 @@
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/ELF.h"
 #include "llvm/Object/IRObjectFile.h"
-#include "llvm/Support/StringSaver.h"
 
 #include <map>
 
@@ -181,7 +180,7 @@ public:
   ArrayRef<SymbolBody *> getLocalSymbols();
   ArrayRef<SymbolBody *> getNonLocalSymbols();
 
-  explicit ObjectFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef M);
+  explicit ObjectFile(MemoryBufferRef M);
   void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
 
   ArrayRef<InputSectionBase<ELFT> *> getSections() const { return Sections; }
@@ -214,10 +213,6 @@ public:
   // st_name of the symbol.
   std::vector<std::pair<const DefinedRegular<ELFT> *, unsigned>> KeptLocalSyms;
 
-  // SymbolBodies and Thunks for sections in this file are allocated
-  // using this buffer.
-  llvm::BumpPtrAllocator &Alloc;
-
   // Name of source file obtained from STT_FILE symbol value,
   // or empty string if there is no such symbol in object file
   // symbol table.
@@ -273,8 +268,6 @@ private:
   template <class ELFT> std::vector<StringRef> getElfSymbols();
   std::vector<StringRef> getBitcodeSymbols();
 
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Saver{Alloc};
   bool Seen = false;
 };
 
@@ -307,8 +300,6 @@ public:
 
 private:
   std::vector<Symbol *> Symbols;
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Saver{Alloc};
 };
 
 // .so file.
@@ -335,7 +326,7 @@ public:
     return F->kind() == Base::SharedKind;
   }
 
-  explicit SharedFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef M);
+  explicit SharedFile(MemoryBufferRef M);
 
   void parseSoName();
   void parseRest();
@@ -367,15 +358,12 @@ public:
   ArrayRef<InputSectionData *> getSections() const { return Sections; }
 
 private:
-  llvm::BumpPtrAllocator Alloc;
-  llvm::StringSaver Saver{Alloc};
   std::vector<InputSectionData *> Sections;
 };
 
-InputFile *createObjectFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef MB,
-                            StringRef ArchiveName = "",
+InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "",
                             uint64_t OffsetInArchive = 0);
-InputFile *createSharedFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef MB);
+InputFile *createSharedFile(MemoryBufferRef MB);
 
 } // namespace elf
 } // namespace lld

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Fri Oct 28 15:57:25 2016
@@ -137,8 +137,7 @@ std::vector<InputFile *> BitcodeCompiler
       else
         saveBuffer(Buff[I], Config->OutputFile + Twine(I) + ".lto.o");
     }
-    InputFile *Obj =
-        createObjectFile(Alloc, MemoryBufferRef(Buff[I], "lto.tmp"));
+    InputFile *Obj = createObjectFile(MemoryBufferRef(Buff[I], "lto.tmp"));
     Ret.push_back(Obj);
   }
   return Ret;

Modified: lld/trunk/ELF/LTO.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.h?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.h (original)
+++ lld/trunk/ELF/LTO.h Fri Oct 28 15:57:25 2016
@@ -49,7 +49,6 @@ public:
 private:
   std::unique_ptr<llvm::lto::LTO> LtoObj;
   std::vector<SmallString<0>> Buff;
-  llvm::BumpPtrAllocator Alloc;
 };
 }
 }

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Oct 28 15:57:25 2016
@@ -21,11 +21,12 @@
 #include "Config.h"
 #include "Driver.h"
 #include "InputSection.h"
+#include "Memory.h"
 #include "OutputSections.h"
 #include "ScriptParser.h"
 #include "Strings.h"
-#include "Symbols.h"
 #include "SymbolTable.h"
+#include "Symbols.h"
 #include "Target.h"
 #include "Writer.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -33,7 +34,6 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/StringSaver.h"
 
 using namespace llvm;
 using namespace llvm::ELF;
@@ -351,7 +351,7 @@ void LinkerScript<ELFT>::createSections(
   for (ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles())
     for (InputSectionBase<ELFT> *S : F->getSections())
       if (!isDiscarded(S) && !S->OutSec)
-        addSection(Factory, S, getOutputSectionName(S->Name, Opt.Alloc));
+        addSection(Factory, S, getOutputSectionName(S->Name));
 }
 
 // Sets value of a section-defined symbol. Two kinds of
@@ -954,7 +954,6 @@ private:
   void readLocal();
 
   ScriptConfiguration &Opt = *ScriptConfig;
-  StringSaver Saver = {ScriptConfig->Alloc};
   bool IsUnderSysroot;
 };
 

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Fri Oct 28 15:57:25 2016
@@ -188,8 +188,6 @@ struct ScriptConfiguration {
 
   bool HasSections = false;
 
-  llvm::BumpPtrAllocator Alloc;
-
   // List of section patterns specified with KEEP commands. They will
   // be kept even if they are unused and --gc-sections is specified.
   std::vector<InputSectionDescription *> KeptSections;

Added: lld/trunk/ELF/Memory.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Memory.cpp?rev=285452&view=auto
==============================================================================
--- lld/trunk/ELF/Memory.cpp (added)
+++ lld/trunk/ELF/Memory.cpp Fri Oct 28 15:57:25 2016
@@ -0,0 +1,15 @@
+//===- Memory.cpp -----------------------------------------------*- C++ -*-===//
+//
+//                             The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Memory.h"
+
+llvm::BumpPtrAllocator lld::elf::BAlloc;
+llvm::StringSaver lld::elf::Saver{BAlloc};
+
+void lld::elf::freeArena() { BAlloc.Reset(); }

Added: lld/trunk/ELF/Memory.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Memory.h?rev=285452&view=auto
==============================================================================
--- lld/trunk/ELF/Memory.h (added)
+++ lld/trunk/ELF/Memory.h Fri Oct 28 15:57:25 2016
@@ -0,0 +1,37 @@
+//===- Memory.h -------------------------------------------------*- C++ -*-===//
+//
+//                             The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines arena allocators.
+//
+// Almost all large objects, such as files, sections or symbols, are
+// used for the entire lifetime of the linker once they are created.
+// This usage characteristic makes arena allocator an attractive choice
+// where the entire linker is one arena. With an arena, newly created
+// objects belong to the arena and freed all at once when everything is done.
+// Arena allocators are efficient and easy to understand.
+// Most objects are allocated using the arena allocators defined by this file.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_ELF_MEMORY_H
+#define LLD_ELF_MEMORY_H
+
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/StringSaver.h"
+
+namespace lld {
+namespace elf {
+extern llvm::BumpPtrAllocator BAlloc;
+extern llvm::StringSaver Saver;
+
+void freeArena();
+}
+}
+
+#endif

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Fri Oct 28 15:57:25 2016
@@ -18,10 +18,10 @@
 #include "Config.h"
 #include "Error.h"
 #include "LinkerScript.h"
+#include "Memory.h"
 #include "SymbolListFile.h"
 #include "Symbols.h"
 #include "llvm/Bitcode/ReaderWriter.h"
-#include "llvm/Support/StringSaver.h"
 
 using namespace llvm;
 using namespace llvm::object;
@@ -150,7 +150,6 @@ template <class ELFT> void SymbolTable<E
   SymbolBody *B = find(Name);
   if (!B)
     return;
-  StringSaver Saver(Alloc);
   Symbol *Sym = B->symbol();
   Symbol *Real = addUndefined(Saver.save("__real_" + Name));
   Symbol *Wrap = addUndefined(Saver.save("__wrap_" + Name));
@@ -214,7 +213,7 @@ std::pair<Symbol *, bool> SymbolTable<EL
 
   Symbol *Sym;
   if (IsNew) {
-    Sym = new (Alloc) Symbol;
+    Sym = new (BAlloc) Symbol;
     Sym->Binding = STB_WEAK;
     Sym->Visibility = STV_DEFAULT;
     Sym->IsUsedInRegularObj = false;
@@ -289,7 +288,7 @@ Symbol *SymbolTable<ELFT>::addUndefined(
     // its type. See also comment in addLazyArchive.
     if (S->isWeak())
       L->Type = Type;
-    else if (InputFile *F = L->fetch(Alloc))
+    else if (InputFile *F = L->fetch())
       addFile(F);
   }
   return S;
@@ -509,7 +508,7 @@ void SymbolTable<ELFT>::addLazyArchive(A
   }
   std::pair<MemoryBufferRef, uint64_t> MBInfo = F->getMember(&Sym);
   if (!MBInfo.first.getBuffer().empty())
-    addFile(createObjectFile(Alloc, MBInfo.first, F->getName(), MBInfo.second));
+    addFile(createObjectFile(MBInfo.first, F->getName(), MBInfo.second));
 }
 
 template <class ELFT>
@@ -530,7 +529,7 @@ void SymbolTable<ELFT>::addLazyObject(St
   } else {
     MemoryBufferRef MBRef = Obj.getBuffer();
     if (!MBRef.getBuffer().empty())
-      addFile(createObjectFile(Alloc, MBRef));
+      addFile(createObjectFile(MBRef));
   }
 }
 
@@ -538,7 +537,7 @@ void SymbolTable<ELFT>::addLazyObject(St
 template <class ELFT> void SymbolTable<ELFT>::scanUndefinedFlags() {
   for (StringRef S : Config->Undefined)
     if (auto *L = dyn_cast_or_null<Lazy>(find(S)))
-      if (InputFile *File = L->fetch(Alloc))
+      if (InputFile *File = L->fetch())
         addFile(File);
 }
 

Modified: lld/trunk/ELF/SymbolTable.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.h (original)
+++ lld/trunk/ELF/SymbolTable.h Fri Oct 28 15:57:25 2016
@@ -127,7 +127,6 @@ private:
   // once symbol resolution is finished.
   llvm::DenseMap<SymName, SymIndex> Symtab;
   std::vector<Symbol *> SymVector;
-  llvm::BumpPtrAllocator Alloc;
 
   // Comdat groups define "link once" sections. If two comdat groups have the
   // same name, only one of them is linked, and the other is ignored. This set

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Fri Oct 28 15:57:25 2016
@@ -227,10 +227,10 @@ DefinedCommon::DefinedCommon(StringRef N
   this->File = File;
 }
 
-InputFile *Lazy::fetch(BumpPtrAllocator &Alloc) {
+InputFile *Lazy::fetch() {
   if (auto *S = dyn_cast<LazyArchive>(this))
-    return S->fetch(Alloc);
-  return cast<LazyObject>(this)->fetch(Alloc);
+    return S->fetch();
+  return cast<LazyObject>(this)->fetch();
 }
 
 LazyArchive::LazyArchive(ArchiveFile &File,
@@ -244,22 +244,21 @@ LazyObject::LazyObject(StringRef Name, L
   this->File = &File;
 }
 
-InputFile *LazyArchive::fetch(BumpPtrAllocator &Alloc) {
+InputFile *LazyArchive::fetch() {
   std::pair<MemoryBufferRef, uint64_t> MBInfo = file()->getMember(&Sym);
 
   // getMember returns an empty buffer if the member was already
   // read from the library.
   if (MBInfo.first.getBuffer().empty())
     return nullptr;
-  return createObjectFile(Alloc, MBInfo.first, file()->getName(),
-                          MBInfo.second);
+  return createObjectFile(MBInfo.first, file()->getName(), MBInfo.second);
 }
 
-InputFile *LazyObject::fetch(BumpPtrAllocator &Alloc) {
+InputFile *LazyObject::fetch() {
   MemoryBufferRef MBRef = file()->getBuffer();
   if (MBRef.getBuffer().empty())
     return nullptr;
-  return createObjectFile(Alloc, MBRef);
+  return createObjectFile(MBRef);
 }
 
 bool Symbol::includeInDynsym() const {

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Fri Oct 28 15:57:25 2016
@@ -323,7 +323,7 @@ public:
 
   // Returns an object file for this symbol, or a nullptr if the file
   // was already returned.
-  InputFile *fetch(llvm::BumpPtrAllocator &Alloc);
+  InputFile *fetch();
 
 protected:
   Lazy(SymbolBody::Kind K, StringRef Name, uint8_t Type)
@@ -341,7 +341,7 @@ public:
   }
 
   ArchiveFile *file() { return (ArchiveFile *)this->File; }
-  InputFile *fetch(llvm::BumpPtrAllocator &Alloc);
+  InputFile *fetch();
 
 private:
   const llvm::object::Archive::Symbol Sym;
@@ -358,7 +358,7 @@ public:
   }
 
   LazyObjectFile *file() { return (LazyObjectFile *)this->File; }
-  InputFile *fetch(llvm::BumpPtrAllocator &Alloc);
+  InputFile *fetch();
 };
 
 // Some linker-generated symbols need to be created as

Modified: lld/trunk/ELF/Thunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Thunks.cpp?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/Thunks.cpp (original)
+++ lld/trunk/ELF/Thunks.cpp Fri Oct 28 15:57:25 2016
@@ -25,6 +25,7 @@
 #include "Error.h"
 #include "InputFiles.h"
 #include "InputSection.h"
+#include "Memory.h"
 #include "OutputSections.h"
 #include "Symbols.h"
 #include "Target.h"
@@ -190,19 +191,18 @@ static Thunk<ELFT> *createThunkArm(uint3
   // ARM relocations need ARM to Thumb interworking Thunks.
   // Thumb relocations need Thumb to ARM relocations.
   // Use position independent Thunks if we require position independent code.
-  BumpPtrAllocator &Alloc = IS.getFile()->Alloc;
   switch (Reloc) {
   case R_ARM_PC24:
   case R_ARM_PLT32:
   case R_ARM_JUMP24:
     if (Config->Pic)
-      return new (Alloc) ARMToThumbV7PILongThunk<ELFT>(S, IS);
-    return new (Alloc) ARMToThumbV7ABSLongThunk<ELFT>(S, IS);
+      return new (BAlloc) ARMToThumbV7PILongThunk<ELFT>(S, IS);
+    return new (BAlloc) ARMToThumbV7ABSLongThunk<ELFT>(S, IS);
   case R_ARM_THM_JUMP19:
   case R_ARM_THM_JUMP24:
     if (Config->Pic)
-      return new (Alloc) ThumbToARMV7PILongThunk<ELFT>(S, IS);
-    return new (Alloc) ThumbToARMV7ABSLongThunk<ELFT>(S, IS);
+      return new (BAlloc) ThumbToARMV7PILongThunk<ELFT>(S, IS);
+    return new (BAlloc) ThumbToARMV7ABSLongThunk<ELFT>(S, IS);
   }
   fatal("unrecognized relocation type");
 }
@@ -236,7 +236,7 @@ static void addThunkMips(uint32_t RelocT
   // Mips Thunks are added to the InputSection defining S.
   auto *R = cast<DefinedRegular<ELFT>>(&S);
   auto *Sec = cast<InputSection<ELFT>>(R->Section);
-  auto *T = new (IS.getFile()->Alloc) MipsThunk<ELFT>(S, *Sec);
+  auto *T = new (BAlloc) MipsThunk<ELFT>(S, *Sec);
   Sec->addThunk(T);
   R->ThunkData = T;
 }

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Oct 28 15:57:25 2016
@@ -10,6 +10,7 @@
 #include "Writer.h"
 #include "Config.h"
 #include "LinkerScript.h"
+#include "Memory.h"
 #include "OutputSections.h"
 #include "Relocations.h"
 #include "Strings.h"
@@ -19,7 +20,6 @@
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/FileOutputBuffer.h"
-#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/raw_ostream.h"
 #include <climits>
 
@@ -74,7 +74,6 @@ private:
 
   std::unique_ptr<FileOutputBuffer> Buffer;
 
-  BumpPtrAllocator Alloc;
   std::vector<OutputSectionBase<ELFT> *> OutputSections;
   OutputSectionFactory<ELFT> Factory;
 
@@ -90,7 +89,7 @@ private:
 };
 } // anonymous namespace
 
-StringRef elf::getOutputSectionName(StringRef Name, BumpPtrAllocator &Alloc) {
+StringRef elf::getOutputSectionName(StringRef Name) {
   if (Config->Relocatable)
     return Name;
 
@@ -106,7 +105,7 @@ StringRef elf::getOutputSectionName(Stri
   // ".zdebug_" is a prefix for ZLIB-compressed sections.
   // Because we decompressed input sections, we want to remove 'z'.
   if (Name.startswith(".zdebug_"))
-    return StringSaver(Alloc).save(Twine(".") + Name.substr(2));
+    return Saver.save(Twine(".") + Name.substr(2));
   return Name;
 }
 
@@ -705,7 +704,7 @@ template <class ELFT> void Writer<ELFT>:
     }
     OutputSectionBase<ELFT> *Sec;
     bool IsNew;
-    StringRef OutsecName = getOutputSectionName(IS->Name, Alloc);
+    StringRef OutsecName = getOutputSectionName(IS->Name);
     std::tie(Sec, IsNew) = Factory.create(IS, OutsecName);
     if (IsNew)
       OutputSections.push_back(Sec);
@@ -983,7 +982,6 @@ void Writer<ELFT>::addStartStopSymbols(O
   StringRef S = Sec->getName();
   if (!isValidCIdentifier(S))
     return;
-  StringSaver Saver(Alloc);
   addOptionalSynthetic(Saver.save("__start_" + S), Sec, 0, STV_DEFAULT);
   addOptionalSynthetic(Saver.save("__stop_" + S), Sec,
                        DefinedSynthetic<ELFT>::SectionEnd, STV_DEFAULT);

Modified: lld/trunk/ELF/Writer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.h?rev=285452&r1=285451&r2=285452&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.h (original)
+++ lld/trunk/ELF/Writer.h Fri Oct 28 15:57:25 2016
@@ -11,7 +11,6 @@
 #define LLD_ELF_WRITER_H
 
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Allocator.h"
 #include <cstdint>
 #include <memory>
 
@@ -38,8 +37,7 @@ template <class ELFT> struct PhdrEntry {
   bool HasLMA = false;
 };
 
-llvm::StringRef getOutputSectionName(llvm::StringRef Name,
-                                     llvm::BumpPtrAllocator &Alloc);
+llvm::StringRef getOutputSectionName(llvm::StringRef Name);
 
 template <class ELFT> void reportDiscarded(InputSectionBase<ELFT> *IS);
 




More information about the llvm-commits mailing list