Index: lld/trunk/ELF/CMakeLists.txt =================================================================== --- lld/trunk/ELF/CMakeLists.txt +++ lld/trunk/ELF/CMakeLists.txt @@ -14,6 +14,7 @@ LTO.cpp LinkerScript.cpp MarkLive.cpp + Memory.cpp Mips.cpp OutputSections.cpp Relocations.cpp Index: lld/trunk/ELF/Driver.h =================================================================== --- lld/trunk/ELF/Driver.h +++ lld/trunk/ELF/Driver.h @@ -50,7 +50,6 @@ // True if we are in -format=binary and -format=elf. bool InBinary = false; - llvm::BumpPtrAllocator Alloc; std::vector Files; std::vector> OwningMBs; }; @@ -60,9 +59,6 @@ public: ELFOptTable(); llvm::opt::InputArgList parse(ArrayRef Argv); - -private: - llvm::BumpPtrAllocator Alloc; }; // Create enum with OPT_xxx values for each option in Options.td Index: lld/trunk/ELF/Driver.cpp =================================================================== --- lld/trunk/ELF/Driver.cpp +++ lld/trunk/ELF/Driver.cpp @@ -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 @@ Driver->main(Args, CanExitEarly); InputFile::freePool(); + freeArena(); return !HasError; } @@ -141,7 +143,7 @@ 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 @@ 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)); } } Index: lld/trunk/ELF/DriverUtils.cpp =================================================================== --- lld/trunk/ELF/DriverUtils.cpp +++ lld/trunk/ELF/DriverUtils.cpp @@ -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 Args = this->ParseArgs(Vec, MissingIndex, MissingCount); // Expand response files. '@' is replaced by the file's contents. - StringSaver Saver(Alloc); cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), Vec); // Parse options and then do error checking. Index: lld/trunk/ELF/InputFiles.h =================================================================== --- lld/trunk/ELF/InputFiles.h +++ lld/trunk/ELF/InputFiles.h @@ -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 @@ -181,7 +180,7 @@ ArrayRef getLocalSymbols(); ArrayRef getNonLocalSymbols(); - explicit ObjectFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef M); + explicit ObjectFile(MemoryBufferRef M); void parse(llvm::DenseSet &ComdatGroups); ArrayRef *> getSections() const { return Sections; } @@ -214,10 +213,6 @@ // st_name of the symbol. std::vector *, 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 @@ template std::vector getElfSymbols(); std::vector getBitcodeSymbols(); - llvm::BumpPtrAllocator Alloc; - llvm::StringSaver Saver{Alloc}; bool Seen = false; }; @@ -307,8 +300,6 @@ private: std::vector Symbols; - llvm::BumpPtrAllocator Alloc; - llvm::StringSaver Saver{Alloc}; }; // .so file. @@ -335,7 +326,7 @@ return F->kind() == Base::SharedKind; } - explicit SharedFile(llvm::BumpPtrAllocator &Alloc, MemoryBufferRef M); + explicit SharedFile(MemoryBufferRef M); void parseSoName(); void parseRest(); @@ -367,15 +358,12 @@ ArrayRef getSections() const { return Sections; } private: - llvm::BumpPtrAllocator Alloc; - llvm::StringSaver Saver{Alloc}; std::vector 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 Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -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 -elf::ObjectFile::ObjectFile(BumpPtrAllocator &Alloc, MemoryBufferRef M) - : ELFFileBase(Base::ObjectKind, M), Alloc(Alloc) {} +elf::ObjectFile::ObjectFile(MemoryBufferRef M) + : ELFFileBase(Base::ObjectKind, M) {} template ArrayRef elf::ObjectFile::getNonLocalSymbols() { @@ -482,9 +483,9 @@ 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(*Sym, Sec); + return new (BAlloc) DefinedRegular(*Sym, Sec); } StringRef Name = check(Sym->getName(this->StringTable)); @@ -553,7 +554,7 @@ } template -SharedFile::SharedFile(BumpPtrAllocator &Alloc, MemoryBufferRef M) +SharedFile::SharedFile(MemoryBufferRef M) : ELFFileBase(Base::SharedKind, M), AsNeeded(Config->AsNeeded) {} template @@ -745,7 +746,7 @@ template static Symbol *createBitcodeSymbol(const std::vector &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 @@ } for (const lto::InputFile::Symbol &ObjSym : Obj->symbols()) - Symbols.push_back( - createBitcodeSymbol(KeptComdats, ObjSym, Saver, this)); + Symbols.push_back(createBitcodeSymbol(KeptComdats, ObjSym, this)); } template