@@ -178,15 +178,19 @@ class XCOFFObjectWriter : public MCObjectWriter {
178
178
CsectGroup FuncDSCsects;
179
179
CsectGroup TOCCsects;
180
180
CsectGroup BSSCsects;
181
+ CsectGroup TDataCsects;
182
+ CsectGroup TBSSCsects;
181
183
182
184
// The Predefined sections.
183
185
Section Text;
184
186
Section Data;
185
187
Section BSS;
188
+ Section TData;
189
+ Section TBSS;
186
190
187
191
// All the XCOFF sections, in the order they will appear in the section header
188
192
// table.
189
- std::array<Section *const , 3 > Sections{{&Text, &Data, &BSS}};
193
+ std::array<Section *const , 5 > Sections{{&Text, &Data, &BSS, &TData, &TBSS }};
190
194
191
195
CsectGroup &getCsectGroup (const MCSectionXCOFF *MCSec);
192
196
@@ -250,7 +254,11 @@ XCOFFObjectWriter::XCOFFObjectWriter(
250
254
Data(" .data" , XCOFF::STYP_DATA, /* IsVirtual */ false ,
251
255
CsectGroups{&DataCsects, &FuncDSCsects, &TOCCsects}),
252
256
BSS(" .bss" , XCOFF::STYP_BSS, /* IsVirtual */ true ,
253
- CsectGroups{&BSSCsects}) {}
257
+ CsectGroups{&BSSCsects}),
258
+ TData(" .tdata" , XCOFF::STYP_TDATA, /* IsVirtual */ false ,
259
+ CsectGroups{&TDataCsects}),
260
+ TBSS(" .tbss" , XCOFF::STYP_TBSS, /* IsVirtual */ true ,
261
+ CsectGroups{&TBSSCsects}) {}
254
262
255
263
void XCOFFObjectWriter::reset () {
256
264
// Clear the mappings we created.
@@ -297,6 +305,16 @@ CsectGroup &XCOFFObjectWriter::getCsectGroup(const MCSectionXCOFF *MCSec) {
297
305
" Mapping invalid csect. CSECT with bss storage class must be "
298
306
" common type." );
299
307
return BSSCsects;
308
+ case XCOFF::XMC_TL:
309
+ assert (XCOFF::XTY_SD == MCSec->getCSectType () &&
310
+ " Mapping invalid csect. CSECT with tdata storage class must be "
311
+ " an initialized csect." );
312
+ return TDataCsects;
313
+ case XCOFF::XMC_UL:
314
+ assert (XCOFF::XTY_CM == MCSec->getCSectType () &&
315
+ " Mapping invalid csect. CSECT with tbss storage class must be "
316
+ " an uninitialized csect." );
317
+ return TBSSCsects;
300
318
case XCOFF::XMC_TC0:
301
319
assert (XCOFF::XTY_SD == MCSec->getCSectType () &&
302
320
" Only an initialized csect can contain TOC-base." );
@@ -493,9 +511,11 @@ void XCOFFObjectWriter::writeSections(const MCAssembler &Asm,
493
511
494
512
// There could be a gap (without corresponding zero padding) between
495
513
// sections.
496
- assert (CurrentAddressLocation <= Section->Address &&
514
+ assert (((CurrentAddressLocation <= Section->Address ) ||
515
+ (Section->Flags == XCOFF::STYP_TDATA) ||
516
+ (Section->Flags == XCOFF::STYP_TBSS)) &&
497
517
" CurrentAddressLocation should be less than or equal to section "
498
- " address." );
518
+ " address if the section is not TData or TBSS ." );
499
519
500
520
CurrentAddressLocation = Section->Address ;
501
521
@@ -828,6 +848,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
828
848
uint32_t Address = 0 ;
829
849
// Section indices are 1-based in XCOFF.
830
850
int32_t SectionIndex = 1 ;
851
+ bool HasTDataSection = false ;
831
852
832
853
for (auto *Section : Sections) {
833
854
const bool IsEmpty =
@@ -842,6 +863,16 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
842
863
SectionCount++;
843
864
844
865
bool SectionAddressSet = false ;
866
+ // Reset the starting address to 0 for TData section.
867
+ if (Section->Flags == XCOFF::STYP_TDATA) {
868
+ Address = 0 ;
869
+ HasTDataSection = true ;
870
+ }
871
+ // Reset the starting address to 0 for TBSS section if the object file does
872
+ // not contain TData Section.
873
+ if ((Section->Flags == XCOFF::STYP_TBSS) && !HasTDataSection)
874
+ Address = 0 ;
875
+
845
876
for (auto *Group : Section->Groups ) {
846
877
if (Group->empty ())
847
878
continue ;
0 commit comments