diff options
-rw-r--r-- | lld/ELF/InputSection.cpp | 13 | ||||
-rw-r--r-- | lld/ELF/InputSection.h | 6 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.cpp | 5 | ||||
-rw-r--r-- | lld/ELF/SyntheticSections.h | 3 |
4 files changed, 13 insertions, 14 deletions
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 7b1342eca53..49426e879fe 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -958,13 +958,6 @@ uint64_t MergeInputSection::getOffset(uint64_t Offset) const { if (!Live) return 0; - // Initialize OffsetMap lazily. - llvm::call_once(InitOffsetMap, [&] { - OffsetMap.reserve(Pieces.size()); - for (size_t I = 0; I < Pieces.size(); ++I) - OffsetMap[Pieces[I].InputOff] = I; - }); - // Find a string starting at a given offset. auto It = OffsetMap.find(Offset); if (It != OffsetMap.end()) @@ -980,6 +973,12 @@ uint64_t MergeInputSection::getOffset(uint64_t Offset) const { 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<ELF32LE> &, const ELF32LE::Shdr &, StringRef); template InputSection::InputSection(ObjFile<ELF32BE> &, const ELF32BE::Shdr &, diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h index 714439b2dbf..56b5412871a 100644 --- a/lld/ELF/InputSection.h +++ b/lld/ELF/InputSection.h @@ -18,8 +18,6 @@ #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/TinyPtrVector.h" #include "llvm/Object/ELF.h" -#include "llvm/Support/Threading.h" -#include <mutex> namespace lld { namespace elf { @@ -256,13 +254,13 @@ public: } SyntheticSection *getParent() const; + void initOffsetMap(); private: void splitStrings(ArrayRef<uint8_t> A, size_t Size); void splitNonStrings(ArrayRef<uint8_t> A, size_t Size); - mutable llvm::DenseMap<uint32_t, uint32_t> OffsetMap; - mutable llvm::once_flag InitOffsetMap; + llvm::DenseMap<uint32_t, uint32_t> OffsetMap; llvm::DenseSet<uint32_t> LiveOffsets; }; diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index fb5b3238bcc..5ff8ac0fc75 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -2573,8 +2573,11 @@ void elf::mergeSections() { } (*I)->addSection(MS); } - for (auto *MS : MergeSections) + for (auto *MS : MergeSections) { MS->finalizeContents(); + parallelForEach(MS->Sections, + [](MergeInputSection *Sec) { Sec->initOffsetMap(); }); + } std::vector<InputSectionBase *> &V = InputSections; V.erase(std::remove(V.begin(), V.end(), nullptr), V.end()); diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h index 7ab43629c9a..9ad76a6525d 100644 --- a/lld/ELF/SyntheticSections.h +++ b/lld/ELF/SyntheticSections.h @@ -684,13 +684,12 @@ public: class MergeSyntheticSection : public SyntheticSection { public: void addSection(MergeInputSection *MS); + std::vector<MergeInputSection *> Sections; protected: MergeSyntheticSection(StringRef Name, uint32_t Type, uint64_t Flags, uint32_t Alignment) : SyntheticSection(Flags, Type, Alignment, Name) {} - - std::vector<MergeInputSection *> Sections; }; class MergeTailSection final : public MergeSyntheticSection { |