@@ -583,42 +583,23 @@ void MCAssembler::writeSectionData(raw_ostream &OS,
583
583
const MCSection *Sec) const {
584
584
assert (getBackendPtr () && " Expected assembler backend" );
585
585
586
- // Ignore virtual sections.
587
586
if (Sec->isVirtualSection ()) {
588
587
assert (getSectionFileSize (*Sec) == 0 && " Invalid size for section!" );
589
588
590
- // Check that contents are only things legal inside a virtual section.
589
+ // Ensure no fixups or non-zero bytes are written to BSS sections, catching
590
+ // errors in both input assembly code and MCStreamer API usage. Location is
591
+ // not tracked for efficiency.
592
+ auto Fn = [](char c) { return c != 0 ; };
591
593
for (const MCFragment &F : *Sec) {
592
- switch (F.getKind ()) {
593
- default : llvm_unreachable (" Invalid fragment in virtual section!" );
594
- case MCFragment::FT_Data: {
595
- // Check that we aren't trying to write a non-zero contents (or fixups)
596
- // into a virtual section. This is to support clients which use standard
597
- // directives to fill the contents of virtual sections.
598
- if (F.getFixups ().size () || F.getVarFixups ().size ())
599
- reportError (SMLoc (), Sec->getVirtualSectionKind () + " section '" +
600
- Sec->getName () + " ' cannot have fixups" );
601
- for (char C : F.getContents ())
602
- if (C) {
603
- reportError (SMLoc (), Sec->getVirtualSectionKind () + " section '" +
604
- Sec->getName () +
605
- " ' cannot have non-zero initializers" );
606
- break ;
607
- }
594
+ if (any_of (F.getContents (), Fn) || any_of (F.getVarContents (), Fn)) {
595
+ reportError (SMLoc (), Sec->getVirtualSectionKind () + " section '" +
596
+ Sec->getName () +
597
+ " ' cannot have non-zero bytes" );
608
598
break ;
609
599
}
610
- case MCFragment::FT_Align:
611
- // Check that we aren't trying to write a non-zero value into a virtual
612
- // section.
613
- assert ((cast<MCAlignFragment>(F).getFillLen () == 0 ||
614
- cast<MCAlignFragment>(F).getFill () == 0 ) &&
615
- " Invalid align in virtual section!" );
616
- break ;
617
- case MCFragment::FT_Fill:
618
- assert ((cast<MCFillFragment>(F).getValue () == 0 ) &&
619
- " Invalid fill in virtual section!" );
620
- break ;
621
- case MCFragment::FT_Org:
600
+ if (F.getFixups ().size () || F.getVarFixups ().size ()) {
601
+ reportError (SMLoc (), Sec->getVirtualSectionKind () + " section '" +
602
+ Sec->getName () + " ' cannot have fixups" );
622
603
break ;
623
604
}
624
605
}
0 commit comments