@@ -116,10 +116,6 @@ void MCAsmLayout::setSectionAddress(MCSectionData *SD, uint64_t Value) {
116
116
}
117
117
118
118
uint64_t MCAsmLayout::getSectionAddressSize (const MCSectionData *SD) const {
119
- // Empty sections have no size.
120
- if (SD->getFragmentList ().empty ())
121
- return 0 ;
122
-
123
119
// Otherwise, the size is the last fragment's end offset.
124
120
const MCFragment &F = SD->getFragmentList ().back ();
125
121
return getFragmentOffset (&F) + getFragmentEffectiveSize (&F);
@@ -135,10 +131,6 @@ uint64_t MCAsmLayout::getSectionFileSize(const MCSectionData *SD) const {
135
131
}
136
132
137
133
uint64_t MCAsmLayout::getSectionSize (const MCSectionData *SD) const {
138
- // Empty sections have no size.
139
- if (SD->getFragmentList ().empty ())
140
- return 0 ;
141
-
142
134
// The logical size is the address space size minus any tail padding.
143
135
uint64_t Size = getSectionAddressSize (SD);
144
136
const MCAlignFragment *AF =
@@ -611,6 +603,15 @@ void MCAssembler::Finish() {
611
603
unsigned SectionIndex = 0 ;
612
604
unsigned FragmentIndex = 0 ;
613
605
for (MCAssembler::iterator it = begin (), ie = end (); it != ie; ++it) {
606
+ // Create dummy fragments to eliminate any empty sections, this simplifies
607
+ // layout.
608
+ if (it->getFragmentList ().empty ()) {
609
+ unsigned ValueSize = 1 ;
610
+ if (getBackend ().isVirtualSection (it->getSection ()))
611
+ ValueSize = 1 ;
612
+ new MCFillFragment (0 , 1 , 0 , it);
613
+ }
614
+
614
615
it->setOrdinal (SectionIndex++);
615
616
616
617
for (MCSectionData::iterator it2 = it->begin (),
0 commit comments