@@ -119,19 +119,6 @@ struct ELFWriter {
119
119
StringRef Name;
120
120
uint32_t SectionIndex;
121
121
uint32_t Order;
122
-
123
- // Support lexicographic sorting.
124
- bool operator <(const ELFSymbolData &RHS) const {
125
- unsigned LHSType = Symbol->getType ();
126
- unsigned RHSType = RHS.Symbol ->getType ();
127
- if (LHSType == ELF::STT_SECTION && RHSType != ELF::STT_SECTION)
128
- return false ;
129
- if (LHSType != ELF::STT_SECTION && RHSType == ELF::STT_SECTION)
130
- return true ;
131
- if (LHSType == ELF::STT_SECTION && RHSType == ELF::STT_SECTION)
132
- return SectionIndex < RHS.SectionIndex ;
133
- return Name < RHS.Name ;
134
- }
135
122
};
136
123
137
124
// / @}
@@ -157,7 +144,7 @@ struct ELFWriter {
157
144
bool is64Bit () const ;
158
145
bool hasRelocationAddend () const ;
159
146
160
- void align (unsigned Alignment);
147
+ uint64_t align (unsigned Alignment);
161
148
162
149
bool maybeWriteCompression (uint64_t Size,
163
150
SmallVectorImpl<char > &CompressedContents,
@@ -207,8 +194,6 @@ struct ELFWriter {
207
194
MCSectionELF *createRelocationSection (MCContext &Ctx,
208
195
const MCSectionELF &Sec);
209
196
210
- const MCSectionELF *createStringTable (MCContext &Ctx);
211
-
212
197
void writeSectionHeader (const MCAsmLayout &Layout,
213
198
const SectionIndexMapTy &SectionIndexMap,
214
199
const SectionOffsetsTy &SectionOffsets);
@@ -337,9 +322,10 @@ class ELFDwoObjectWriter : public ELFObjectWriter {
337
322
338
323
} // end anonymous namespace
339
324
340
- void ELFWriter::align (unsigned Alignment) {
341
- uint64_t Padding = offsetToAlignment (W.OS .tell (), Align (Alignment));
342
- W.OS .write_zeros (Padding);
325
+ uint64_t ELFWriter::align (unsigned Alignment) {
326
+ uint64_t Offset = W.OS .tell (), NewOffset = alignTo (Offset, Alignment);
327
+ W.OS .write_zeros (NewOffset - Offset);
328
+ return NewOffset;
343
329
}
344
330
345
331
unsigned ELFWriter::addToSectionTable (const MCSectionELF *Sec) {
@@ -458,7 +444,7 @@ void ELFWriter::writeHeader(const MCAssembler &Asm) {
458
444
// e_shnum = # of section header ents
459
445
W.write <uint16_t >(0 );
460
446
461
- // e_shstrndx = Section # of '.shstrtab '
447
+ // e_shstrndx = Section # of '.strtab '
462
448
assert (StringTableIndex < ELF::SHN_LORESERVE);
463
449
W.write <uint16_t >(StringTableIndex);
464
450
}
@@ -619,8 +605,7 @@ void ELFWriter::computeSymbolTable(
619
605
SymtabSection->setAlignment (is64Bit () ? Align (8 ) : Align (4 ));
620
606
SymbolTableIndex = addToSectionTable (SymtabSection);
621
607
622
- align (SymtabSection->getAlignment ());
623
- uint64_t SecStart = W.OS .tell ();
608
+ uint64_t SecStart = align (SymtabSection->getAlignment ());
624
609
625
610
// The first entry is the undefined symbol entry.
626
611
Writer.writeSymbol (0 , 0 , 0 , 0 , 0 , 0 , false );
@@ -985,12 +970,6 @@ void ELFWriter::writeRelocations(const MCAssembler &Asm,
985
970
}
986
971
}
987
972
988
- const MCSectionELF *ELFWriter::createStringTable (MCContext &Ctx) {
989
- const MCSectionELF *StrtabSection = SectionTable[StringTableIndex - 1 ];
990
- StrTabBuilder.write (W.OS );
991
- return StrtabSection;
992
- }
993
-
994
973
void ELFWriter::writeSection (const SectionIndexMapTy &SectionIndexMap,
995
974
uint32_t GroupSymbolIndex, uint64_t Offset,
996
975
uint64_t Size, const MCSectionELF &Section) {
@@ -1105,10 +1084,8 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
1105
1084
if (Mode == DwoOnly && !isDwoSection (Section))
1106
1085
continue ;
1107
1086
1108
- align (Section.getAlignment ());
1109
-
1110
1087
// Remember the offset into the file for this section.
1111
- uint64_t SecStart = W. OS . tell ( );
1088
+ const uint64_t SecStart = align (Section. getAlignment () );
1112
1089
1113
1090
const MCSymbolELF *SignatureSymbol = Section.getGroup ();
1114
1091
writeSectionData (Asm, Section, Layout);
@@ -1151,10 +1128,8 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
1151
1128
}
1152
1129
1153
1130
for (MCSectionELF *Group : Groups) {
1154
- align (Group->getAlignment ());
1155
-
1156
1131
// Remember the offset into the file for this section.
1157
- uint64_t SecStart = W. OS . tell ( );
1132
+ const uint64_t SecStart = align (Group-> getAlignment () );
1158
1133
1159
1134
const MCSymbol *SignatureSymbol = Group->getGroup ();
1160
1135
assert (SignatureSymbol);
@@ -1185,10 +1160,8 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
1185
1160
SectionOffsets);
1186
1161
1187
1162
for (MCSectionELF *RelSection : Relocations) {
1188
- align (RelSection->getAlignment ());
1189
-
1190
1163
// Remember the offset into the file for this section.
1191
- uint64_t SecStart = W. OS . tell ( );
1164
+ const uint64_t SecStart = align (RelSection-> getAlignment () );
1192
1165
1193
1166
writeRelocations (Asm,
1194
1167
cast<MCSectionELF>(*RelSection->getLinkedToSection ()));
@@ -1218,15 +1191,11 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
1218
1191
1219
1192
{
1220
1193
uint64_t SecStart = W.OS .tell ();
1221
- const MCSectionELF *Sec = createStringTable (Ctx);
1222
- uint64_t SecEnd = W.OS .tell ();
1223
- SectionOffsets[Sec] = std::make_pair (SecStart, SecEnd);
1194
+ StrTabBuilder.write (W.OS );
1195
+ SectionOffsets[StrtabSection] = std::make_pair (SecStart, W.OS .tell ());
1224
1196
}
1225
1197
1226
- uint64_t NaturalAlignment = is64Bit () ? 8 : 4 ;
1227
- align (NaturalAlignment);
1228
-
1229
- const uint64_t SectionHeaderOffset = W.OS .tell ();
1198
+ const uint64_t SectionHeaderOffset = align (is64Bit () ? 8 : 4 );
1230
1199
1231
1200
// ... then the section header table ...
1232
1201
writeSectionHeader (Layout, SectionIndexMap, SectionOffsets);
0 commit comments