Index: lld/COFF/Driver.cpp =================================================================== --- lld/COFF/Driver.cpp +++ lld/COFF/Driver.cpp @@ -10,13 +10,13 @@ #include "Driver.h" #include "Config.h" #include "InputFiles.h" -#include "Memory.h" #include "MinGW.h" #include "SymbolTable.h" #include "Symbols.h" #include "Writer.h" #include "lld/Common/Driver.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Version.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringSwitch.h" @@ -50,10 +50,6 @@ Configuration *Config; LinkerDriver *Driver; -BumpPtrAllocator BAlloc; -StringSaver Saver{BAlloc}; -std::vector SpecificAllocBase::Instances; - bool link(ArrayRef Args, bool CanExitEarly, raw_ostream &Diag) { errorHandler().LogName = Args[0]; errorHandler().ErrorOS = &Diag; Index: lld/COFF/DriverUtils.cpp =================================================================== --- lld/COFF/DriverUtils.cpp +++ lld/COFF/DriverUtils.cpp @@ -15,9 +15,9 @@ #include "Config.h" #include "Driver.h" -#include "Memory.h" #include "Symbols.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/Optional.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/BinaryFormat/COFF.h" Index: lld/COFF/InputFiles.cpp =================================================================== --- lld/COFF/InputFiles.cpp +++ lld/COFF/InputFiles.cpp @@ -11,10 +11,10 @@ #include "Chunks.h" #include "Config.h" #include "Driver.h" -#include "Memory.h" #include "SymbolTable.h" #include "Symbols.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm-c/lto.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Triple.h" Index: lld/COFF/Memory.h =================================================================== --- lld/COFF/Memory.h +++ /dev/null @@ -1,52 +0,0 @@ -//===- Memory.h -------------------------------------------------*- C++ -*-===// -// -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// See ELF/Memory.h -// -//===----------------------------------------------------------------------===// - -#ifndef LLD_COFF_MEMORY_H -#define LLD_COFF_MEMORY_H - -#include "llvm/Support/Allocator.h" -#include "llvm/Support/StringSaver.h" -#include - -namespace lld { -namespace coff { - -extern llvm::BumpPtrAllocator BAlloc; -extern llvm::StringSaver Saver; - -struct SpecificAllocBase { - SpecificAllocBase() { Instances.push_back(this); } - virtual ~SpecificAllocBase() = default; - virtual void reset() = 0; - static std::vector Instances; -}; - -template struct SpecificAlloc : public SpecificAllocBase { - void reset() override { Alloc.DestroyAll(); } - llvm::SpecificBumpPtrAllocator Alloc; -}; - -template T *make(U &&... Args) { - static SpecificAlloc Alloc; - return new (Alloc.Alloc.Allocate()) T(std::forward(Args)...); -} - -inline void freeArena() { - for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances) - Alloc->reset(); - BAlloc.Reset(); -} -} -} - -#endif Index: lld/COFF/SymbolTable.cpp =================================================================== --- lld/COFF/SymbolTable.cpp +++ lld/COFF/SymbolTable.cpp @@ -11,9 +11,9 @@ #include "Config.h" #include "Driver.h" #include "LTO.h" -#include "Memory.h" #include "Symbols.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/IR/LLVMContext.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" Index: lld/COFF/Symbols.h =================================================================== --- lld/COFF/Symbols.h +++ lld/COFF/Symbols.h @@ -12,8 +12,8 @@ #include "Chunks.h" #include "Config.h" -#include "Memory.h" #include "lld/Common/LLVM.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/Object/Archive.h" #include "llvm/Object/COFF.h" Index: lld/COFF/Symbols.cpp =================================================================== --- lld/COFF/Symbols.cpp +++ lld/COFF/Symbols.cpp @@ -9,9 +9,9 @@ #include "Symbols.h" #include "InputFiles.h" -#include "Memory.h" #include "Strings.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" Index: lld/COFF/Writer.cpp =================================================================== --- lld/COFF/Writer.cpp +++ lld/COFF/Writer.cpp @@ -12,11 +12,11 @@ #include "DLL.h" #include "InputFiles.h" #include "MapFile.h" -#include "Memory.h" #include "PDB.h" #include "SymbolTable.h" #include "Symbols.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringSwitch.h" Index: lld/Common/CMakeLists.txt =================================================================== --- lld/Common/CMakeLists.txt +++ lld/Common/CMakeLists.txt @@ -5,6 +5,7 @@ add_lld_library(lldCommon Args.cpp ErrorHandler.cpp + Memory.cpp Reproduce.cpp Strings.cpp TargetOptionsCommandFlags.cpp Index: lld/Common/Memory.cpp =================================================================== --- /dev/null +++ lld/Common/Memory.cpp @@ -0,0 +1,23 @@ +//===- Memory.cpp ---------------------------------------------------------===// +// +// The LLVM Linker +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lld/Common/Memory.h" + +using namespace llvm; +using namespace lld; + +BumpPtrAllocator lld::BAlloc; +StringSaver lld::Saver{BAlloc}; +std::vector lld::SpecificAllocBase::Instances; + +void lld::freeArena() { + for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances) + Alloc->reset(); + BAlloc.Reset(); +} Index: lld/ELF/Driver.cpp =================================================================== --- lld/ELF/Driver.cpp +++ lld/ELF/Driver.cpp @@ -30,7 +30,6 @@ #include "InputFiles.h" #include "InputSection.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "ScriptParser.h" #include "Strings.h" @@ -41,6 +40,7 @@ #include "lld/Common/Args.h" #include "lld/Common/Driver.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "lld/Common/Version.h" #include "llvm/ADT/StringExtras.h" @@ -65,10 +65,6 @@ Configuration *elf::Config; LinkerDriver *elf::Driver; -BumpPtrAllocator elf::BAlloc; -StringSaver elf::Saver{BAlloc}; -std::vector elf::SpecificAllocBase::Instances; - static void setConfigs(); bool elf::link(ArrayRef Args, bool CanExitEarly, Index: lld/ELF/DriverUtils.cpp =================================================================== --- lld/ELF/DriverUtils.cpp +++ lld/ELF/DriverUtils.cpp @@ -14,8 +14,8 @@ //===----------------------------------------------------------------------===// #include "Driver.h" -#include "Memory.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Reproduce.h" #include "lld/Common/Version.h" #include "llvm/ADT/Optional.h" Index: lld/ELF/GdbIndex.cpp =================================================================== --- lld/ELF/GdbIndex.cpp +++ lld/ELF/GdbIndex.cpp @@ -15,7 +15,7 @@ //===----------------------------------------------------------------------===// #include "GdbIndex.h" -#include "Memory.h" +#include "lld/Common/Memory.h" #include "llvm/DebugInfo/DWARF/DWARFDebugPubTable.h" #include "llvm/Object/ELFObjectFile.h" Index: lld/ELF/InputFiles.cpp =================================================================== --- lld/ELF/InputFiles.cpp +++ lld/ELF/InputFiles.cpp @@ -10,11 +10,11 @@ #include "InputFiles.h" #include "InputSection.h" #include "LinkerScript.h" -#include "Memory.h" #include "SymbolTable.h" #include "Symbols.h" #include "SyntheticSections.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/STLExtras.h" #include "llvm/CodeGen/Analysis.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" Index: lld/ELF/InputSection.cpp =================================================================== --- lld/ELF/InputSection.cpp +++ lld/ELF/InputSection.cpp @@ -12,13 +12,13 @@ #include "EhFrame.h" #include "InputFiles.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "Relocations.h" #include "SyntheticSections.h" #include "Target.h" #include "Thunks.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/Object/Decompressor.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Compression.h" Index: lld/ELF/LinkerScript.cpp =================================================================== --- lld/ELF/LinkerScript.cpp +++ lld/ELF/LinkerScript.cpp @@ -14,7 +14,6 @@ #include "LinkerScript.h" #include "Config.h" #include "InputSection.h" -#include "Memory.h" #include "OutputSections.h" #include "Strings.h" #include "SymbolTable.h" @@ -22,6 +21,7 @@ #include "SyntheticSections.h" #include "Target.h" #include "Writer.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringRef.h" Index: lld/ELF/MarkLive.cpp =================================================================== --- lld/ELF/MarkLive.cpp +++ lld/ELF/MarkLive.cpp @@ -22,13 +22,13 @@ #include "InputSection.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "Strings.h" #include "SymbolTable.h" #include "Symbols.h" #include "Target.h" #include "Writer.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Object/ELF.h" #include Index: lld/ELF/OutputSections.cpp =================================================================== --- lld/ELF/OutputSections.cpp +++ lld/ELF/OutputSections.cpp @@ -10,11 +10,11 @@ #include "OutputSections.h" #include "Config.h" #include "LinkerScript.h" -#include "Memory.h" #include "Strings.h" #include "SymbolTable.h" #include "SyntheticSections.h" #include "Target.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Support/Compression.h" Index: lld/ELF/Relocations.cpp =================================================================== --- lld/ELF/Relocations.cpp +++ lld/ELF/Relocations.cpp @@ -44,13 +44,13 @@ #include "Relocations.h" #include "Config.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "Strings.h" #include "SymbolTable.h" #include "SyntheticSections.h" #include "Target.h" #include "Thunks.h" +#include "lld/Common/Memory.h" #include "llvm/Support/Endian.h" #include "llvm/Support/raw_ostream.h" Index: lld/ELF/ScriptParser.cpp =================================================================== --- lld/ELF/ScriptParser.cpp +++ lld/ELF/ScriptParser.cpp @@ -17,11 +17,11 @@ #include "Driver.h" #include "InputSection.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "ScriptLexer.h" #include "Symbols.h" #include "Target.h" +#include "lld/Common/Memory.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSet.h" Index: lld/ELF/SymbolTable.cpp =================================================================== --- lld/ELF/SymbolTable.cpp +++ lld/ELF/SymbolTable.cpp @@ -17,10 +17,10 @@ #include "SymbolTable.h" #include "Config.h" #include "LinkerScript.h" -#include "Memory.h" #include "Symbols.h" #include "SyntheticSections.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Strings.h" #include "llvm/ADT/STLExtras.h" Index: lld/ELF/SyntheticSections.cpp =================================================================== --- lld/ELF/SyntheticSections.cpp +++ lld/ELF/SyntheticSections.cpp @@ -19,13 +19,13 @@ #include "Config.h" #include "InputFiles.h" #include "LinkerScript.h" -#include "Memory.h" #include "OutputSections.h" #include "Strings.h" #include "SymbolTable.h" #include "Target.h" #include "Writer.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "lld/Common/Version.h" #include "llvm/BinaryFormat/Dwarf.h" Index: lld/ELF/Thunks.cpp =================================================================== --- lld/ELF/Thunks.cpp +++ lld/ELF/Thunks.cpp @@ -24,12 +24,12 @@ #include "Thunks.h" #include "Config.h" #include "InputSection.h" -#include "Memory.h" #include "OutputSections.h" #include "Symbols.h" #include "SyntheticSections.h" #include "Target.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/BinaryFormat/ELF.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Endian.h" Index: lld/ELF/Writer.cpp =================================================================== --- lld/ELF/Writer.cpp +++ lld/ELF/Writer.cpp @@ -12,13 +12,13 @@ #include "Filesystem.h" #include "LinkerScript.h" #include "MapFile.h" -#include "Memory.h" #include "OutputSections.h" #include "Relocations.h" #include "Strings.h" #include "SymbolTable.h" #include "SyntheticSections.h" #include "Target.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSwitch.h" Index: lld/include/lld/Common/Memory.h =================================================================== --- lld/include/lld/Common/Memory.h +++ lld/include/lld/Common/Memory.h @@ -21,20 +21,21 @@ // //===----------------------------------------------------------------------===// -#ifndef LLD_ELF_MEMORY_H -#define LLD_ELF_MEMORY_H +#ifndef LLD_COMMON_MEMORY_H +#define LLD_COMMON_MEMORY_H #include "llvm/Support/Allocator.h" #include "llvm/Support/StringSaver.h" #include namespace lld { -namespace elf { // Use this arena if your object doesn't have a destructor. extern llvm::BumpPtrAllocator BAlloc; extern llvm::StringSaver Saver; +void freeArena(); + // These two classes are hack to keep track of all // SpecificBumpPtrAllocator instances. struct SpecificAllocBase { @@ -56,12 +57,6 @@ return new (Alloc.Alloc.Allocate()) T(std::forward(Args)...); } -inline void freeArena() { - for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances) - Alloc->reset(); - BAlloc.Reset(); -} -} // namespace elf } // namespace lld #endif Index: lld/wasm/Driver.cpp =================================================================== --- lld/wasm/Driver.cpp +++ lld/wasm/Driver.cpp @@ -9,11 +9,11 @@ #include "lld/Common/Driver.h" #include "Config.h" -#include "Memory.h" #include "SymbolTable.h" #include "Writer.h" #include "lld/Common/Args.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "lld/Common/Version.h" #include "llvm/ADT/Twine.h" @@ -61,9 +61,7 @@ } // anonymous namespace -std::vector lld::wasm::SpecificAllocBase::Instances; Configuration *lld::wasm::Config; -BumpPtrAllocator lld::wasm::BAlloc; bool lld::wasm::link(ArrayRef Args, bool CanExitEarly, raw_ostream &Error) { Index: lld/wasm/InputFiles.cpp =================================================================== --- lld/wasm/InputFiles.cpp +++ lld/wasm/InputFiles.cpp @@ -11,10 +11,10 @@ #include "Config.h" #include "InputSegment.h" -#include "Memory.h" #include "Strings.h" #include "SymbolTable.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "llvm/Object/Binary.h" #include "llvm/Object/Wasm.h" #include "llvm/Support/raw_ostream.h" Index: lld/wasm/Memory.h =================================================================== --- lld/wasm/Memory.h +++ /dev/null @@ -1,52 +0,0 @@ -//===- Memory.h -------------------------------------------------*- C++ -*-===// -// -// The LLVM Linker -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// See WASM/Memory.h -// -//===----------------------------------------------------------------------===// - -#ifndef LLD_WASM_MEMORY_H -#define LLD_WASM_MEMORY_H - -#include "llvm/Support/Allocator.h" -#include "llvm/Support/StringSaver.h" -#include - -namespace lld { -namespace wasm { - -extern llvm::BumpPtrAllocator BAlloc; -extern llvm::StringSaver Saver; - -struct SpecificAllocBase { - SpecificAllocBase() { Instances.push_back(this); } - virtual ~SpecificAllocBase() = default; - virtual void reset() = 0; - static std::vector Instances; -}; - -template struct SpecificAlloc : public SpecificAllocBase { - void reset() override { Alloc.DestroyAll(); } - llvm::SpecificBumpPtrAllocator Alloc; -}; - -template T *make(U &&... Args) { - static SpecificAlloc Alloc; - return new (Alloc.Alloc.Allocate()) T(std::forward(Args)...); -} - -inline void freeArena() { - for (SpecificAllocBase *Alloc : SpecificAllocBase::Instances) - Alloc->reset(); - BAlloc.Reset(); -} -} // namespace wasm -} // namespace lld - -#endif Index: lld/wasm/OutputSections.cpp =================================================================== --- lld/wasm/OutputSections.cpp +++ lld/wasm/OutputSections.cpp @@ -11,10 +11,10 @@ #include "Config.h" #include "InputFiles.h" -#include "Memory.h" #include "OutputSegment.h" #include "SymbolTable.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/LEB128.h" Index: lld/wasm/SymbolTable.cpp =================================================================== --- lld/wasm/SymbolTable.cpp +++ lld/wasm/SymbolTable.cpp @@ -10,9 +10,9 @@ #include "SymbolTable.h" #include "Config.h" -#include "Memory.h" #include "Strings.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include Index: lld/wasm/Writer.cpp =================================================================== --- lld/wasm/Writer.cpp +++ lld/wasm/Writer.cpp @@ -10,12 +10,12 @@ #include "Writer.h" #include "Config.h" -#include "Memory.h" #include "OutputSections.h" #include "OutputSegment.h" #include "SymbolTable.h" #include "WriterUtils.h" #include "lld/Common/ErrorHandler.h" +#include "lld/Common/Memory.h" #include "lld/Common/Threads.h" #include "llvm/Support/FileOutputBuffer.h" #include "llvm/Support/Format.h"