@@ -142,11 +142,11 @@ struct ELFWriter {
142
142
bool is64Bit () const ;
143
143
bool usesRela (const MCSectionELF &Sec) const ;
144
144
145
- uint64_t align (unsigned Alignment);
145
+ uint64_t align (Align Alignment);
146
146
147
147
bool maybeWriteCompression (uint32_t ChType, uint64_t Size ,
148
148
SmallVectorImpl<uint8_t > &CompressedContents,
149
- unsigned Alignment);
149
+ Align Alignment);
150
150
151
151
public:
152
152
ELFWriter (ELFObjectWriter &OWriter, raw_pwrite_stream &OS,
@@ -201,7 +201,7 @@ struct ELFWriter {
201
201
202
202
void WriteSecHdrEntry (uint32_t Name, uint32_t Type, uint64_t Flags,
203
203
uint64_t Address, uint64_t Offset, uint64_t Size ,
204
- uint32_t Link, uint32_t Info, uint64_t Alignment,
204
+ uint32_t Link, uint32_t Info, MaybeAlign Alignment,
205
205
uint64_t EntrySize);
206
206
207
207
void writeRelocations (const MCAssembler &Asm, const MCSectionELF &Sec);
@@ -317,8 +317,9 @@ class ELFDwoObjectWriter : public ELFObjectWriter {
317
317
318
318
} // end anonymous namespace
319
319
320
- uint64_t ELFWriter::align (unsigned Alignment) {
321
- uint64_t Offset = W.OS .tell (), NewOffset = alignTo (Offset, Alignment);
320
+ uint64_t ELFWriter::align (Align Alignment) {
321
+ uint64_t Offset = W.OS .tell ();
322
+ uint64_t NewOffset = alignTo (Offset, Alignment);
322
323
W.OS .write_zeros (NewOffset - Offset);
323
324
return NewOffset;
324
325
}
@@ -622,7 +623,7 @@ void ELFWriter::computeSymbolTable(
622
623
SymtabSection->setAlignment (is64Bit () ? Align (8 ) : Align (4 ));
623
624
SymbolTableIndex = addToSectionTable (SymtabSection);
624
625
625
- uint64_t SecStart = align (SymtabSection->getAlignment ());
626
+ uint64_t SecStart = align (SymtabSection->getAlign ());
626
627
627
628
// The first entry is the undefined symbol entry.
628
629
Writer.writeSymbol (0 , 0 , 0 , 0 , 0 , 0 , false );
@@ -820,7 +821,7 @@ MCSectionELF *ELFWriter::createRelocationSection(MCContext &Ctx,
820
821
// Include the debug info compression header.
821
822
bool ELFWriter::maybeWriteCompression (
822
823
uint32_t ChType, uint64_t Size ,
823
- SmallVectorImpl<uint8_t > &CompressedContents, unsigned Alignment) {
824
+ SmallVectorImpl<uint8_t > &CompressedContents, Align Alignment) {
824
825
uint64_t HdrSize =
825
826
is64Bit () ? sizeof (ELF::Elf32_Chdr) : sizeof (ELF::Elf64_Chdr);
826
827
if (Size <= HdrSize + CompressedContents.size ())
@@ -831,12 +832,12 @@ bool ELFWriter::maybeWriteCompression(
831
832
write (static_cast <ELF::Elf64_Word>(ChType));
832
833
write (static_cast <ELF::Elf64_Word>(0 )); // ch_reserved field.
833
834
write (static_cast <ELF::Elf64_Xword>(Size ));
834
- write (static_cast <ELF::Elf64_Xword>(Alignment));
835
+ write (static_cast <ELF::Elf64_Xword>(Alignment. value () ));
835
836
} else {
836
837
// Write Elf32_Chdr header otherwise.
837
838
write (static_cast <ELF::Elf32_Word>(ChType));
838
839
write (static_cast <ELF::Elf32_Word>(Size ));
839
- write (static_cast <ELF::Elf32_Word>(Alignment));
840
+ write (static_cast <ELF::Elf32_Word>(Alignment. value () ));
840
841
}
841
842
return true ;
842
843
}
@@ -878,7 +879,7 @@ void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
878
879
compression::compress (compression::Params (CompressionType), Uncompressed,
879
880
Compressed);
880
881
if (!maybeWriteCompression (ChType, UncompressedData.size (), Compressed,
881
- Sec.getAlignment ())) {
882
+ Sec.getAlign ())) {
882
883
W.OS << UncompressedData;
883
884
return ;
884
885
}
@@ -893,7 +894,7 @@ void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
893
894
void ELFWriter::WriteSecHdrEntry (uint32_t Name, uint32_t Type, uint64_t Flags,
894
895
uint64_t Address, uint64_t Offset,
895
896
uint64_t Size , uint32_t Link, uint32_t Info,
896
- uint64_t Alignment, uint64_t EntrySize) {
897
+ MaybeAlign Alignment, uint64_t EntrySize) {
897
898
W.write <uint32_t >(Name); // sh_name: index into string table
898
899
W.write <uint32_t >(Type); // sh_type
899
900
WriteWord (Flags); // sh_flags
@@ -902,7 +903,7 @@ void ELFWriter::WriteSecHdrEntry(uint32_t Name, uint32_t Type, uint64_t Flags,
902
903
WriteWord (Size ); // sh_size
903
904
W.write <uint32_t >(Link); // sh_link
904
905
W.write <uint32_t >(Info); // sh_info
905
- WriteWord (Alignment); // sh_addralign
906
+ WriteWord (Alignment ? Alignment-> value () : 0 ); // sh_addralign
906
907
WriteWord (EntrySize); // sh_entsize
907
908
}
908
909
@@ -1024,7 +1025,7 @@ void ELFWriter::writeSection(const SectionIndexMapTy &SectionIndexMap,
1024
1025
1025
1026
WriteSecHdrEntry (StrTabBuilder.getOffset (Section.getName ()),
1026
1027
Section.getType (), Section.getFlags (), 0 , Offset, Size ,
1027
- sh_link, sh_info, Section.getAlignment (),
1028
+ sh_link, sh_info, Section.getAlign (),
1028
1029
Section.getEntrySize ());
1029
1030
}
1030
1031
@@ -1036,7 +1037,7 @@ void ELFWriter::writeSectionHeader(
1036
1037
// Null section first.
1037
1038
uint64_t FirstSectionSize =
1038
1039
(NumSections + 1 ) >= ELF::SHN_LORESERVE ? NumSections + 1 : 0 ;
1039
- WriteSecHdrEntry (0 , 0 , 0 , 0 , 0 , FirstSectionSize, 0 , 0 , 0 , 0 );
1040
+ WriteSecHdrEntry (0 , 0 , 0 , 0 , 0 , FirstSectionSize, 0 , 0 , None , 0 );
1040
1041
1041
1042
for (const MCSectionELF *Section : SectionTable) {
1042
1043
uint32_t GroupSymbolIndex;
@@ -1087,7 +1088,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
1087
1088
continue ;
1088
1089
1089
1090
// Remember the offset into the file for this section.
1090
- const uint64_t SecStart = align (Section.getAlignment ());
1091
+ const uint64_t SecStart = align (Section.getAlign ());
1091
1092
1092
1093
const MCSymbolELF *SignatureSymbol = Section.getGroup ();
1093
1094
writeSectionData (Asm, Section, Layout);
@@ -1124,7 +1125,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
1124
1125
1125
1126
for (MCSectionELF *Group : Groups) {
1126
1127
// Remember the offset into the file for this section.
1127
- const uint64_t SecStart = align (Group->getAlignment ());
1128
+ const uint64_t SecStart = align (Group->getAlign ());
1128
1129
1129
1130
const MCSymbol *SignatureSymbol = Group->getGroup ();
1130
1131
assert (SignatureSymbol);
@@ -1156,7 +1157,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
1156
1157
1157
1158
for (MCSectionELF *RelSection : Relocations) {
1158
1159
// Remember the offset into the file for this section.
1159
- const uint64_t SecStart = align (RelSection->getAlignment ());
1160
+ const uint64_t SecStart = align (RelSection->getAlign ());
1160
1161
1161
1162
writeRelocations (Asm,
1162
1163
cast<MCSectionELF>(*RelSection->getLinkedToSection ()));
@@ -1179,7 +1180,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
1179
1180
SectionOffsets[StrtabSection] = std::make_pair (SecStart, W.OS .tell ());
1180
1181
}
1181
1182
1182
- const uint64_t SectionHeaderOffset = align (is64Bit () ? 8 : 4 );
1183
+ const uint64_t SectionHeaderOffset = align (is64Bit () ? Align ( 8 ) : Align ( 4 ) );
1183
1184
1184
1185
// ... then the section header table ...
1185
1186
writeSectionHeader (Layout, SectionIndexMap, SectionOffsets);
0 commit comments