@@ -159,15 +159,12 @@ class CVDebugRecordChunk : public Chunk {
159
159
// PartialSection represents a group of chunks that contribute to an
160
160
// OutputSection. Collating a collection of PartialSections of same name and
161
161
// characteristics constitutes the OutputSection.
162
- class PartialSection {
162
+ class PartialSectionKey {
163
163
public:
164
- PartialSection (StringRef N, uint32_t Chars)
165
- : Name(N), Characteristics(Chars) {}
166
164
StringRef Name;
167
165
unsigned Characteristics;
168
- std::vector<Chunk *> Chunks;
169
166
170
- bool operator <(const PartialSection &Other) const {
167
+ bool operator <(const PartialSectionKey &Other) const {
171
168
int C = Name.compare (Other.Name );
172
169
if (C == 1 )
173
170
return false ;
@@ -177,10 +174,13 @@ class PartialSection {
177
174
}
178
175
};
179
176
180
- struct PartialLess {
181
- bool operator ()(PartialSection *L, PartialSection *R) const {
182
- return *L < *R;
183
- }
177
+ class PartialSection {
178
+ public:
179
+ PartialSection (StringRef N, uint32_t Chars)
180
+ : Name(N), Characteristics(Chars) {}
181
+ StringRef Name;
182
+ unsigned Characteristics;
183
+ std::vector<Chunk *> Chunks;
184
184
};
185
185
186
186
// The writer writes a SymbolTable result to a file.
@@ -234,7 +234,7 @@ class Writer {
234
234
uint32_t getSizeOfInitializedData ();
235
235
236
236
std::unique_ptr<FileOutputBuffer> &Buffer;
237
- std::set< PartialSection *, PartialLess > PartialSections;
237
+ std::map<PartialSectionKey, PartialSection *> PartialSections;
238
238
std::vector<OutputSection *> OutputSections;
239
239
std::vector<char > Strtab;
240
240
std::vector<llvm::object::coff_symbol16> OutputSymtab;
@@ -628,7 +628,8 @@ bool Writer::fixGnuImportChunks() {
628
628
629
629
// Make sure all .idata$* section chunks are mapped as RDATA in order to
630
630
// be sorted into the same sections as our own synthesized .idata chunks.
631
- for (PartialSection *PSec : PartialSections) {
631
+ for (auto It : PartialSections) {
632
+ PartialSection *PSec = It.second ;
632
633
if (!PSec->Name .startswith (" .idata" ))
633
634
continue ;
634
635
if (PSec->Characteristics == RDATA)
@@ -642,7 +643,8 @@ bool Writer::fixGnuImportChunks() {
642
643
bool HasIdata = false ;
643
644
// Sort all .idata$* chunks, grouping chunks from the same library,
644
645
// with alphabetical ordering of the object fils within a library.
645
- for (PartialSection *PSec : PartialSections) {
646
+ for (auto It : PartialSections) {
647
+ PartialSection *PSec = It.second ;
646
648
if (!PSec->Name .startswith (" .idata" ))
647
649
continue ;
648
650
@@ -773,8 +775,8 @@ void Writer::createSections() {
773
775
774
776
// Process an /order option.
775
777
if (!Config->Order .empty ())
776
- for (PartialSection *PSec : PartialSections)
777
- sortBySectionOrder (PSec ->Chunks );
778
+ for (auto It : PartialSections)
779
+ sortBySectionOrder (It. second ->Chunks );
778
780
779
781
if (HasIdata)
780
782
locateImportTables ();
@@ -783,7 +785,8 @@ void Writer::createSections() {
783
785
// '$' and all following characters in input section names are
784
786
// discarded when determining output section. So, .text$foo
785
787
// contributes to .text, for example. See PE/COFF spec 3.2.
786
- for (PartialSection *PSec : PartialSections) {
788
+ for (auto It : PartialSections) {
789
+ PartialSection *PSec = It.second ;
787
790
StringRef Name = getOutputSectionName (PSec->Name );
788
791
uint32_t OutChars = PSec->Characteristics ;
789
792
@@ -1771,19 +1774,16 @@ void Writer::addBaserelBlocks(std::vector<Baserel> &V) {
1771
1774
1772
1775
PartialSection *Writer::createPartialSection (StringRef Name,
1773
1776
uint32_t OutChars) {
1774
- PartialSection *PSec = findPartialSection ( Name, OutChars) ;
1777
+ PartialSection *& PSec = PartialSections[{ Name, OutChars}] ;
1775
1778
if (PSec)
1776
1779
return PSec;
1777
1780
PSec = make<PartialSection>(Name, OutChars);
1778
- PartialSections.insert (PSec);
1779
1781
return PSec;
1780
1782
}
1781
1783
1782
1784
PartialSection *Writer::findPartialSection (StringRef Name, uint32_t OutChars) {
1783
- auto It = find_if (PartialSections, [&](PartialSection *P) {
1784
- return P->Name == Name && P->Characteristics == OutChars;
1785
- });
1785
+ auto It = PartialSections.find ({Name, OutChars});
1786
1786
if (It != PartialSections.end ())
1787
- return *It ;
1787
+ return It-> second ;
1788
1788
return nullptr ;
1789
1789
}
0 commit comments