From 2b714b56a9c8cf3a7ee6a2dbf9b7d03af331f2c2 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 11 Oct 2017 03:12:53 +0000 Subject: [PATCH] Split decompressAndMergeSection into two separate functions. Even though they are called sequentially, they are separate operations, so it is better to split it. llvm-svn: 315422 --- lld/ELF/Driver.cpp | 3 ++- lld/ELF/InputSection.cpp | 5 +---- lld/ELF/SyntheticSections.cpp | 37 +++++++++++++++++++++-------------- lld/ELF/SyntheticSections.h | 3 ++- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index b470f7094509..04c1c3fc504c 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -1107,7 +1107,8 @@ template void LinkerDriver::link(opt::InputArgList &Args) { // Do size optimizations: garbage collection, merging of SHF_MERGE sections // and identical code folding. markLive(); - decompressAndMergeSections(); + decompressSections(); + mergeSections(); if (Config->ICF) doIcf(); diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index b63c09a7ba78..32b946d32fbc 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -196,10 +196,7 @@ OutputSection *SectionBase::getOutputSection() { // Uncompress section contents if required. Note that this function // is called from parallelForEach, so it must be thread-safe. void InputSectionBase::maybeUncompress() { - if (UncompressBuf) - return; - - if (!Decompressor::isCompressedELFSection(Flags, Name)) + if (UncompressBuf || !Decompressor::isCompressedELFSection(Flags, Name)) return; Decompressor Dec = check(Decompressor::create(Name, toStringRef(Data), diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 1548749cde64..20d815ac216b 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2305,21 +2305,28 @@ static MergeSyntheticSection *createMergeSynthetic(StringRef Name, return make(Name, Type, Flags, Alignment); } -// This function decompresses compressed sections and scans over the input -// sections to create mergeable synthetic sections. It removes -// MergeInputSections from the input section array and adds new synthetic -// sections at the location of the first input section that it replaces. It then -// finalizes each synthetic section in order to compute an output offset for -// each piece of each input section. -void elf::decompressAndMergeSections() { - // splitIntoPieces needs to be called on each MergeInputSection before calling - // finalizeContents(). Do that first. - parallelForEach(InputSections, [](InputSectionBase *S) { - if (!S->Live) - return; - S->maybeUncompress(); - if (auto *MS = dyn_cast(S)) - MS->splitIntoPieces(); +// Debug sections may be compressed by zlib. Uncompress if exists. +void elf::decompressSections() { + parallelForEach(InputSections, [](InputSectionBase *Sec) { + if (Sec->Live) + Sec->maybeUncompress(); + }); +} + +// This function scans over the inputsections to create mergeable +// synthetic sections. +// +// It removes MergeInputSections from the input section array and adds +// new synthetic sections at the location of the first input section +// that it replaces. It then finalizes each synthetic section in order +// to compute an output offset for each piece of each input section. +void elf::mergeSections() { + // splitIntoPieces needs to be called on each MergeInputSection + // before calling finalizeContents(). Do that first. + parallelForEach(InputSections, [](InputSectionBase *Sec) { + if (Sec->Live) + if (auto *S = dyn_cast(Sec)) + S->splitIntoPieces(); }); std::vector MergeSections; diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 9cc904a70d7f..c6a51ad33151 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -805,7 +805,8 @@ private: template void createCommonSections(); InputSection *createInterpSection(); template MergeInputSection *createCommentSection(); -void decompressAndMergeSections(); +void decompressSections(); +void mergeSections(); SymbolBody *addSyntheticLocal(StringRef Name, uint8_t Type, uint64_t Value, uint64_t Size, InputSectionBase *Section); -- 2.34.1