@@ -145,14 +145,16 @@ bool XCOFFWriter::initSectionHeaders(uint64_t &CurrentOffset) {
145
145
uint64_t CurrentEndTDataAddr = 0 ;
146
146
for (uint16_t I = 0 , E = InitSections.size (); I < E; ++I) {
147
147
// Assign indices for sections.
148
- if (InitSections[I].SectionName .size () &&
149
- !SectionIndexMap[InitSections[I].SectionName ]) {
150
- // The section index starts from 1.
151
- SectionIndexMap[InitSections[I].SectionName ] = I + 1 ;
152
- if ((I + 1 ) > MaxSectionIndex) {
153
- ErrHandler (" exceeded the maximum permitted section index of " +
154
- Twine (MaxSectionIndex));
155
- return false ;
148
+ if (InitSections[I].SectionName .size ()) {
149
+ int16_t &SectionIndex = SectionIndexMap[InitSections[I].SectionName ];
150
+ if (!SectionIndex) {
151
+ // The section index starts from 1.
152
+ SectionIndex = I + 1 ;
153
+ if ((I + 1 ) > MaxSectionIndex) {
154
+ ErrHandler (" exceeded the maximum permitted section index of " +
155
+ Twine (MaxSectionIndex));
156
+ return false ;
157
+ }
156
158
}
157
159
}
158
160
@@ -779,19 +781,19 @@ bool XCOFFWriter::writeSymbols() {
779
781
W.write <uint32_t >(YamlSym.Value );
780
782
}
781
783
if (YamlSym.SectionName ) {
782
- if (!SectionIndexMap.count (*YamlSym.SectionName )) {
784
+ auto It = SectionIndexMap.find (*YamlSym.SectionName );
785
+ if (It == SectionIndexMap.end ()) {
783
786
ErrHandler (" the SectionName " + *YamlSym.SectionName +
784
787
" specified in the symbol does not exist" );
785
788
return false ;
786
789
}
787
- if (YamlSym.SectionIndex &&
788
- SectionIndexMap[*YamlSym.SectionName ] != *YamlSym.SectionIndex ) {
790
+ if (YamlSym.SectionIndex && It->second != *YamlSym.SectionIndex ) {
789
791
ErrHandler (" the SectionName " + *YamlSym.SectionName +
790
792
" and the SectionIndex (" + Twine (*YamlSym.SectionIndex ) +
791
793
" ) refer to different sections" );
792
794
return false ;
793
795
}
794
- W.write <int16_t >(SectionIndexMap[*YamlSym. SectionName ] );
796
+ W.write <int16_t >(It-> second );
795
797
} else {
796
798
W.write <int16_t >(YamlSym.SectionIndex .value_or (0 ));
797
799
}
0 commit comments