@@ -126,7 +126,8 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S) const {
126126uint64_t MachObjectWriter::getPaddingSize (const MCAssembler &Asm,
127127 const MCSection *Sec) const {
128128 uint64_t EndAddr = getSectionAddress (Sec) + Asm.getSectionAddressSize (*Sec);
129- unsigned Next = cast<MCSectionMachO>(Sec)->getLayoutOrder () + 1 ;
129+ unsigned Next =
130+ static_cast <const MCSectionMachO *>(Sec)->getLayoutOrder () + 1 ;
130131 if (Next >= SectionOrder.size ())
131132 return 0 ;
132133
@@ -259,27 +260,24 @@ void MachObjectWriter::writeSegmentLoadCommand(
259260}
260261
261262void MachObjectWriter::writeSection (const MCAssembler &Asm,
262- const MCSection &Sec, uint64_t VMAddr,
263+ const MCSectionMachO &Sec, uint64_t VMAddr,
263264 uint64_t FileOffset, unsigned Flags,
264265 uint64_t RelocationsStart,
265266 unsigned NumRelocations) {
266- uint64_t SectionSize = Asm.getSectionAddressSize (Sec);
267- const MCSectionMachO &Section = cast<MCSectionMachO>(Sec);
268-
269267 // The offset is unused for virtual sections.
270- if (Section .isBssSection ()) {
268+ if (Sec .isBssSection ()) {
271269 assert (Asm.getSectionFileSize (Sec) == 0 && " Invalid file size!" );
272270 FileOffset = 0 ;
273271 }
274272
275273 // struct section (68 bytes) or
276274 // struct section_64 (80 bytes)
277275
276+ uint64_t SectionSize = Asm.getSectionAddressSize (Sec);
278277 uint64_t Start = W.OS .tell ();
279278 (void ) Start;
280-
281- writeWithPadding (Section.getName (), 16 );
282- writeWithPadding (Section.getSegmentName (), 16 );
279+ writeWithPadding (Sec.getName (), 16 );
280+ writeWithPadding (Sec.getSegmentName (), 16 );
283281 if (is64Bit ()) {
284282 W.write <uint64_t >(VMAddr); // address
285283 W.write <uint64_t >(SectionSize); // size
@@ -290,14 +288,14 @@ void MachObjectWriter::writeSection(const MCAssembler &Asm,
290288 assert (isUInt<32 >(FileOffset) && " Cannot encode offset of section" );
291289 W.write <uint32_t >(FileOffset);
292290
293- W.write <uint32_t >(Log2 (Section .getAlign ()));
291+ W.write <uint32_t >(Log2 (Sec .getAlign ()));
294292 assert ((!NumRelocations || isUInt<32 >(RelocationsStart)) &&
295293 " Cannot encode offset of relocations" );
296294 W.write <uint32_t >(NumRelocations ? RelocationsStart : 0 );
297295 W.write <uint32_t >(NumRelocations);
298296 W.write <uint32_t >(Flags);
299297 W.write <uint32_t >(IndirectSymBase.lookup (&Sec)); // reserved1
300- W.write <uint32_t >(Section .getStubSize ()); // reserved2
298+ W.write <uint32_t >(Sec .getStubSize ()); // reserved2
301299 if (is64Bit ())
302300 W.write <uint32_t >(0 ); // reserved3
303301
@@ -531,7 +529,7 @@ void MachObjectWriter::bindIndirectSymbols(MCAssembler &Asm) {
531529 // Report errors for use of .indirect_symbol not in a symbol pointer section
532530 // or stub section.
533531 for (IndirectSymbolData &ISD : IndirectSymbols) {
534- const MCSectionMachO &Section = cast <MCSectionMachO>(*ISD.Section );
532+ const MCSectionMachO &Section = static_cast <MCSectionMachO & >(*ISD.Section );
535533
536534 if (Section.getType () != MachO::S_NON_LAZY_SYMBOL_POINTERS &&
537535 Section.getType () != MachO::S_LAZY_SYMBOL_POINTERS &&
@@ -545,7 +543,7 @@ void MachObjectWriter::bindIndirectSymbols(MCAssembler &Asm) {
545543
546544 // Bind non-lazy symbol pointers first.
547545 for (auto [IndirectIndex, ISD] : enumerate(IndirectSymbols)) {
548- const auto &Section = cast <MCSectionMachO>(*ISD.Section );
546+ const auto &Section = static_cast <MCSectionMachO & >(*ISD.Section );
549547
550548 if (Section.getType () != MachO::S_NON_LAZY_SYMBOL_POINTERS &&
551549 Section.getType () != MachO::S_THREAD_LOCAL_VARIABLE_POINTERS)
@@ -559,7 +557,7 @@ void MachObjectWriter::bindIndirectSymbols(MCAssembler &Asm) {
559557
560558 // Then lazy symbol pointers and symbol stubs.
561559 for (auto [IndirectIndex, ISD] : enumerate(IndirectSymbols)) {
562- const auto &Section = cast <MCSectionMachO>(*ISD.Section );
560+ const auto &Section = static_cast <MCSectionMachO & >(*ISD.Section );
563561
564562 if (Section.getType () != MachO::S_LAZY_SYMBOL_POINTERS &&
565563 Section.getType () != MachO::S_SYMBOL_STUBS)
@@ -684,13 +682,13 @@ void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm) {
684682 for (MCSection &Sec : Asm) {
685683 if (!Sec.isBssSection ()) {
686684 SectionOrder.push_back (&Sec);
687- cast <MCSectionMachO>(Sec).setLayoutOrder (i++);
685+ static_cast <MCSectionMachO & >(Sec).setLayoutOrder (i++);
688686 }
689687 }
690688 for (MCSection &Sec : Asm) {
691689 if (Sec.isBssSection ()) {
692690 SectionOrder.push_back (&Sec);
693- cast <MCSectionMachO>(Sec).setLayoutOrder (i++);
691+ static_cast <MCSectionMachO & >(Sec).setLayoutOrder (i++);
694692 }
695693 }
696694
@@ -907,7 +905,7 @@ uint64_t MachObjectWriter::writeObject() {
907905 // ... and then the section headers.
908906 uint64_t RelocTableEnd = SectionDataStart + SectionDataFileSize;
909907 for (const MCSection &Section : Asm) {
910- const auto &Sec = cast< MCSectionMachO>(Section);
908+ const auto &Sec = static_cast < const MCSectionMachO & >(Section);
911909 std::vector<RelAndSymbol> &Relocs = Relocations[&Sec];
912910 unsigned NumRelocs = Relocs.size ();
913911 uint64_t SectionStart = SectionDataStart + getSectionAddress (&Sec);
0 commit comments