From 116d83fbe0e505f56adc217243c64781e73e3f30 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 19 Oct 2016 23:13:40 +0000 Subject: [PATCH] Don't call markLiveAt for non alloc sections. We don't gc them anyway, so just use an early return in Enqueue. llvm-svn: 284663 --- lld/ELF/InputSection.cpp | 3 ++- lld/ELF/InputSection.h | 5 ++++- lld/ELF/MarkLive.cpp | 11 ++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 76795a24ac62..ff91463a8fe0 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -53,7 +53,8 @@ InputSectionBase::InputSectionBase(elf::ObjectFile *File, const Elf_Shdr *Hdr, StringRef Name, Kind SectionKind) : InputSectionData(SectionKind, Name, getSectionContents(File, Hdr), - isCompressed(Hdr, Name), !Config->GcSections), + isCompressed(Hdr, Name), + !Config->GcSections || !(Hdr->sh_flags & SHF_ALLOC)), Header(Hdr), File(File), Repl(this) { // The ELF spec states that a value of 0 means the section has // no alignment constraits. diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 3fd89bd8ec89..fcac34c1b0a0 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -167,7 +167,10 @@ public: void splitIntoPieces(); // Mark the piece at a given offset live. Used by GC. - void markLiveAt(uintX_t Offset) { LiveOffsets.insert(Offset); } + void markLiveAt(uintX_t Offset) { + assert(this->getSectionHdr()->sh_flags & llvm::ELF::SHF_ALLOC); + LiveOffsets.insert(Offset); + } // Translate an offset in the input section to an offset // in the output section. diff --git a/lld/ELF/MarkLive.cpp b/lld/ELF/MarkLive.cpp index 847575711d21..452fc29ab911 100644 --- a/lld/ELF/MarkLive.cpp +++ b/lld/ELF/MarkLive.cpp @@ -201,6 +201,10 @@ template void elf::markLive() { if (!R.Sec || R.Sec == &InputSection::Discarded) return; + // We don't gc non alloc sections. + if (!(R.Sec->getSectionHdr()->sh_flags & SHF_ALLOC)) + return; + // Usually, a whole section is marked as live or dead, but in mergeable // (splittable) sections, each piece of data has independent liveness bit. // So we explicitly tell it which offset is in use. @@ -210,12 +214,9 @@ template void elf::markLive() { if (R.Sec->Live) return; R.Sec->Live = true; - // Add input section to the queue. We don't want to consider relocations - // from non-allocatable input sections, because we can bring those - // allocatable sections to living which otherwise would be dead. + // Add input section to the queue. if (InputSection *S = dyn_cast>(R.Sec)) - if (S->getSectionHdr()->sh_flags & SHF_ALLOC) - Q.push_back(S); + Q.push_back(S); }; auto MarkSymbol = [&](const SymbolBody *Sym) {