Index: COFF/Writer.cpp =================================================================== --- COFF/Writer.cpp +++ COFF/Writer.cpp @@ -159,15 +159,12 @@ // PartialSection represents a group of chunks that contribute to an // OutputSection. Collating a collection of PartialSections of same name and // characteristics constitutes the OutputSection. -class PartialSection { +class PartialSectionKey { public: - PartialSection(StringRef N, uint32_t Chars) - : Name(N), Characteristics(Chars) {} StringRef Name; unsigned Characteristics; - std::vector Chunks; - bool operator<(const PartialSection &Other) const { + bool operator<(const PartialSectionKey &Other) const { int C = Name.compare(Other.Name); if (C == 1) return false; @@ -177,10 +174,13 @@ } }; -struct PartialLess { - bool operator()(PartialSection *L, PartialSection *R) const { - return *L < *R; - } +class PartialSection { +public: + PartialSection(StringRef N, uint32_t Chars) + : Name(N), Characteristics(Chars) {} + StringRef Name; + unsigned Characteristics; + std::vector Chunks; }; // The writer writes a SymbolTable result to a file. @@ -234,7 +234,7 @@ uint32_t getSizeOfInitializedData(); std::unique_ptr &Buffer; - std::set PartialSections; + std::map PartialSections; std::vector OutputSections; std::vector Strtab; std::vector OutputSymtab; @@ -628,7 +628,8 @@ // Make sure all .idata$* section chunks are mapped as RDATA in order to // be sorted into the same sections as our own synthesized .idata chunks. - for (PartialSection *PSec : PartialSections) { + for (auto It : PartialSections) { + PartialSection *PSec = It.second; if (!PSec->Name.startswith(".idata")) continue; if (PSec->Characteristics == RDATA) @@ -642,7 +643,8 @@ bool HasIdata = false; // Sort all .idata$* chunks, grouping chunks from the same library, // with alphabetical ordering of the object fils within a library. - for (PartialSection *PSec : PartialSections) { + for (auto It : PartialSections) { + PartialSection *PSec = It.second; if (!PSec->Name.startswith(".idata")) continue; @@ -773,8 +775,8 @@ // Process an /order option. if (!Config->Order.empty()) - for (PartialSection *PSec : PartialSections) - sortBySectionOrder(PSec->Chunks); + for (auto It : PartialSections) + sortBySectionOrder(It.second->Chunks); if (HasIdata) locateImportTables(); @@ -783,7 +785,8 @@ // '$' and all following characters in input section names are // discarded when determining output section. So, .text$foo // contributes to .text, for example. See PE/COFF spec 3.2. - for (PartialSection *PSec : PartialSections) { + for (auto It : PartialSections) { + PartialSection *PSec = It.second; StringRef Name = getOutputSectionName(PSec->Name); uint32_t OutChars = PSec->Characteristics; @@ -1771,19 +1774,15 @@ PartialSection *Writer::createPartialSection(StringRef Name, uint32_t OutChars) { - PartialSection *PSec = findPartialSection(Name, OutChars); + PartialSectionKey Key = {Name, OutChars}; + PartialSection *&PSec = PartialSections[Key]; if (PSec) return PSec; PSec = make(Name, OutChars); - PartialSections.insert(PSec); return PSec; } PartialSection *Writer::findPartialSection(StringRef Name, uint32_t OutChars) { - auto It = find_if(PartialSections, [&](PartialSection *P) { - return P->Name == Name && P->Characteristics == OutChars; - }); - if (It != PartialSections.end()) - return *It; - return nullptr; + PartialSectionKey Key = {Name, OutChars}; + return PartialSections[Key]; }