From c207a89c91e24928c505c7bd8bc5508f69976d68 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 20 Dec 2016 05:47:55 +0000 Subject: [PATCH] Remove `Compressed` member from InputSectionData. This value is used only once, and we can compute a value. So we don't need to save it. llvm-svn: 290164 --- lld/ELF/Driver.cpp | 2 +- lld/ELF/InputSection.cpp | 13 +++++-------- lld/ELF/InputSection.h | 13 +++++++------ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index a2b01c7..d5bd4fa 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -827,7 +827,7 @@ template void LinkerDriver::link(opt::InputArgList &Args) { [](InputSectionBase *S) { if (!S->Live) return; - if (S->Compressed) + if (S->isCompressed()) S->uncompress(); if (auto *MS = dyn_cast>(S)) MS->splitIntoPieces(); diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 963995e..805e51d 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -46,13 +46,6 @@ static ArrayRef getSectionContents(elf::ObjectFile *File, return check(File->getObj().getSectionContents(Hdr)); } -// ELF supports ZLIB-compressed section. Returns true if the section -// is compressed. -template -static bool isCompressed(typename ELFT::uint Flags, StringRef Name) { - return (Flags & SHF_COMPRESSED) || Name.startswith(".zdebug"); -} - template InputSectionBase::InputSectionBase(elf::ObjectFile *File, uintX_t Flags, uint32_t Type, @@ -60,7 +53,7 @@ InputSectionBase::InputSectionBase(elf::ObjectFile *File, uint32_t Info, uintX_t Addralign, ArrayRef Data, StringRef Name, Kind SectionKind) - : InputSectionData(SectionKind, Name, Data, isCompressed(Flags, Name), + : InputSectionData(SectionKind, Name, Data, !Config->GcSections || !(Flags & SHF_ALLOC)), File(File), Flags(Flags), Entsize(Entsize), Type(Type), Link(Link), Info(Info), Repl(this) { @@ -135,6 +128,10 @@ typename ELFT::uint InputSectionBase::getOffset(uintX_t Offset) const { llvm_unreachable("invalid section kind"); } +template bool InputSectionBase::isCompressed() const { + return (Flags & SHF_COMPRESSED) || Name.startswith(".zdebug"); +} + // Returns compressed data and its size when uncompressed. template std::pair, uint64_t> diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index af22254..adbc1e1 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -45,9 +45,9 @@ public: // The garbage collector sets sections' Live bits. // If GC is disabled, all sections are considered live by default. InputSectionData(Kind SectionKind, StringRef Name, ArrayRef Data, - bool Compressed, bool Live) - : SectionKind(SectionKind), Live(Live), Assigned(false), - Compressed(Compressed), Name(Name), Data(Data) {} + bool Live) + : SectionKind(SectionKind), Live(Live), Assigned(false), Name(Name), + Data(Data) {} private: unsigned SectionKind : 3; @@ -57,7 +57,6 @@ public: unsigned Live : 1; // for garbage collection unsigned Assigned : 1; // for linker script - unsigned Compressed : 1; // true if section data is compressed uint32_t Alignment; StringRef Name; ArrayRef Data; @@ -94,8 +93,7 @@ public: uint32_t Info; InputSectionBase() - : InputSectionData(Regular, "", ArrayRef(), false, false), - Repl(this) { + : InputSectionData(Regular, "", ArrayRef(), false), Repl(this) { NumRelocations = 0; AreRelocsRela = false; } @@ -140,6 +138,9 @@ public: // section. uintX_t getOffset(uintX_t Offset) const; + // ELF supports ZLIB-compressed section. + // Returns true if the section is compressed. + bool isCompressed() const; void uncompress(); // Returns a source location string. Used to construct an error message. -- 2.7.4