From a8631e3887698583e5bd0f118921571dd92757b1 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 27 Oct 2016 13:32:32 +0000 Subject: [PATCH] Use fewer allocators. Instead of having 3 section allocators per file, have 3 for all files. This is a substantial performance improvement for some cases. Linking chromium without gc speeds up by 1.065x. This requires using _exit in fatal since we have to avoid destructing an InputSection if fatal is called from the constructor. Thanks to Rui for the suggestion. llvm-svn: 285290 --- lld/ELF/Error.cpp | 12 +++++++++++- lld/ELF/Error.h | 1 + lld/ELF/InputFiles.cpp | 12 ++++++++---- lld/ELF/InputFiles.h | 18 +++++++++++++++--- lld/ELF/Writer.cpp | 8 +------- 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/lld/ELF/Error.cpp b/lld/ELF/Error.cpp index 6c9fb09..bbe9fa1 100644 --- a/lld/ELF/Error.cpp +++ b/lld/ELF/Error.cpp @@ -14,6 +14,10 @@ #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" +#if !defined(_MSC_VER) && !defined(__MINGW32__) +#include +#endif + using namespace llvm; namespace lld { @@ -43,9 +47,15 @@ void elf::error(std::error_code EC, const Twine &Prefix) { error(Prefix + ": " + EC.message()); } +void elf::exitLld(int Val) { + outs().flush(); + errs().flush(); + _exit(Val); +} + void elf::fatal(const Twine &Msg) { *ErrorOS << Argv0 << ": error: " << Msg << "\n"; - exit(1); + exitLld(1); } void elf::fatal(std::error_code EC, const Twine &Prefix) { diff --git a/lld/ELF/Error.h b/lld/ELF/Error.h index 6cb9548..5776d83 100644 --- a/lld/ELF/Error.h +++ b/lld/ELF/Error.h @@ -45,6 +45,7 @@ template void error(const ErrorOr &V, const Twine &Prefix) { error(V.getError(), Prefix); } +LLVM_ATTRIBUTE_NORETURN void exitLld(int Val); LLVM_ATTRIBUTE_NORETURN void fatal(const Twine &Msg); LLVM_ATTRIBUTE_NORETURN void fatal(std::error_code EC, const Twine &Prefix); diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 507090d..b0c177f 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -386,7 +386,8 @@ elf::ObjectFile::createInputSection(const Elf_Shdr &Sec) { // If -r is given, we do not interpret or apply relocation // but just copy relocation sections to output. if (Config->Relocatable) - return new (IAlloc.Allocate()) InputSection(this, &Sec, Name); + return new (GAlloc::IAlloc.Allocate()) + InputSection(this, &Sec, Name); // Find the relocation target section and associate this // section with it. @@ -428,11 +429,14 @@ elf::ObjectFile::createInputSection(const Elf_Shdr &Sec) { // .eh_frame_hdr section for runtime. So we handle them with a special // class. For relocatable outputs, they are just passed through. if (Name == ".eh_frame" && !Config->Relocatable) - return new (EHAlloc.Allocate()) EhInputSection(this, &Sec, Name); + return new (GAlloc::EHAlloc.Allocate()) + EhInputSection(this, &Sec, Name); if (shouldMerge(Sec)) - return new (MAlloc.Allocate()) MergeInputSection(this, &Sec, Name); - return new (IAlloc.Allocate()) InputSection(this, &Sec, Name); + return new (GAlloc::MAlloc.Allocate()) + MergeInputSection(this, &Sec, Name); + return new (GAlloc::IAlloc.Allocate()) + InputSection(this, &Sec, Name); } template void elf::ObjectFile::initializeSymbols() { diff --git a/lld/ELF/InputFiles.h b/lld/ELF/InputFiles.h index ca232fc..083e867 100644 --- a/lld/ELF/InputFiles.h +++ b/lld/ELF/InputFiles.h @@ -38,6 +38,21 @@ class InputFile; namespace lld { namespace elf { +template struct GAlloc { + static llvm::SpecificBumpPtrAllocator> IAlloc; + static llvm::SpecificBumpPtrAllocator> MAlloc; + static llvm::SpecificBumpPtrAllocator> EHAlloc; +}; + +template +llvm::SpecificBumpPtrAllocator> GAlloc::IAlloc; + +template +llvm::SpecificBumpPtrAllocator> GAlloc::MAlloc; + +template +llvm::SpecificBumpPtrAllocator> GAlloc::EHAlloc; + using llvm::object::Archive; class InputFile; @@ -233,9 +248,6 @@ private: // MIPS .MIPS.abiflags section defined by this file. std::unique_ptr> MipsAbiFlags; - llvm::SpecificBumpPtrAllocator> IAlloc; - llvm::SpecificBumpPtrAllocator> MAlloc; - llvm::SpecificBumpPtrAllocator> EHAlloc; std::unique_ptr> DIH; }; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index a280194..8a39398 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -23,10 +23,6 @@ #include "llvm/Support/raw_ostream.h" #include -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#include -#endif - using namespace llvm; using namespace llvm::ELF; using namespace llvm::object; @@ -324,9 +320,7 @@ template void Writer::run() { // Flush the output streams and exit immediately. A full shutdown is a good // test that we are keeping track of all allocated memory, but actually // freeing it is a waste of time in a regular linker run. - outs().flush(); - errs().flush(); - _exit(0); + exitLld(0); } } -- 2.7.4