Index: ELF/InputSection.h =================================================================== --- ELF/InputSection.h +++ ELF/InputSection.h @@ -236,6 +236,7 @@ // Splittable sections are handled as a sequence of data // rather than a single large blob of data. std::vector Pieces; + llvm::DenseMap OffsetMap; // Returns I'th piece's data. This function is very hot when // string merging is enabled, so we want to inline. @@ -254,14 +255,11 @@ } SyntheticSection *getParent() const; - void initOffsetMap(); private: void splitStrings(ArrayRef A, size_t Size); void splitNonStrings(ArrayRef A, size_t Size); - llvm::DenseMap OffsetMap; - llvm::DenseSet LiveOffsets; }; Index: ELF/InputSection.cpp =================================================================== --- ELF/InputSection.cpp +++ ELF/InputSection.cpp @@ -985,12 +985,6 @@ return Piece.OutputOff + Addend; } -void MergeInputSection::initOffsetMap() { - OffsetMap.reserve(Pieces.size()); - for (size_t I = 0; I < Pieces.size(); ++I) - OffsetMap[Pieces[I].InputOff] = I; -} - template InputSection::InputSection(ObjFile &, const ELF32LE::Shdr &, StringRef); template InputSection::InputSection(ObjFile &, const ELF32BE::Shdr &, Index: ELF/SyntheticSections.cpp =================================================================== --- ELF/SyntheticSections.cpp +++ ELF/SyntheticSections.cpp @@ -2438,10 +2438,15 @@ // finalize() fixed tail-optimized strings, so we can now get // offsets of strings. Get an offset for each string and save it // to a corresponding StringPiece for easy access. - for (MergeInputSection *Sec : Sections) - for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I) - if (Sec->Pieces[I].Live) - Sec->Pieces[I].OutputOff = Builder.getOffset(Sec->getData(I)); + for (MergeInputSection *Sec : Sections) { + Sec->OffsetMap.reserve(Sec->Pieces.size()); + for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I) { + SectionPiece &P = Sec->Pieces[I]; + Sec->OffsetMap[P.InputOff] = I; + if (P.Live) + P.OutputOff = Builder.getOffset(Sec->getData(I)); + } + } } void MergeNoTailSection::writeTo(uint8_t *Buf) { @@ -2494,10 +2499,13 @@ // So far, section pieces have offsets from beginning of shards, but // we want offsets from beginning of the whole section. Fix them. parallelForEach(Sections, [&](MergeInputSection *Sec) { - for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I) - if (Sec->Pieces[I].Live) - Sec->Pieces[I].OutputOff += - ShardOffsets[getShardId(Sec->Pieces[I].Hash)]; + Sec->OffsetMap.reserve(Sec->Pieces.size()); + for (size_t I = 0, E = Sec->Pieces.size(); I != E; ++I) { + SectionPiece &P = Sec->Pieces[I]; + Sec->OffsetMap[P.InputOff] = I; + if (P.Live) + P.OutputOff += ShardOffsets[getShardId(P.Hash)]; + } }); } @@ -2573,11 +2581,8 @@ } (*I)->addSection(MS); } - for (auto *MS : MergeSections) { + for (auto *MS : MergeSections) MS->finalizeContents(); - parallelForEach(MS->Sections, - [](MergeInputSection *Sec) { Sec->initOffsetMap(); }); - } std::vector &V = InputSections; V.erase(std::remove(V.begin(), V.end(), nullptr), V.end());