Skip to content

Commit 8307fa4

Browse files
author
git apple-llvm automerger
committed
Merge commit 'f98567b3fecb' from llvm.org/main into apple/main
2 parents bf570f1 + f98567b commit 8307fa4

File tree

3 files changed

+687
-11
lines changed

3 files changed

+687
-11
lines changed

llvm/lib/MC/XCOFFObjectWriter.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,19 @@ class XCOFFObjectWriter : public MCObjectWriter {
178178
CsectGroup FuncDSCsects;
179179
CsectGroup TOCCsects;
180180
CsectGroup BSSCsects;
181+
CsectGroup TDataCsects;
182+
CsectGroup TBSSCsects;
181183

182184
// The Predefined sections.
183185
Section Text;
184186
Section Data;
185187
Section BSS;
188+
Section TData;
189+
Section TBSS;
186190

187191
// All the XCOFF sections, in the order they will appear in the section header
188192
// table.
189-
std::array<Section *const, 3> Sections{{&Text, &Data, &BSS}};
193+
std::array<Section *const, 5> Sections{{&Text, &Data, &BSS, &TData, &TBSS}};
190194

191195
CsectGroup &getCsectGroup(const MCSectionXCOFF *MCSec);
192196

@@ -250,7 +254,11 @@ XCOFFObjectWriter::XCOFFObjectWriter(
250254
Data(".data", XCOFF::STYP_DATA, /* IsVirtual */ false,
251255
CsectGroups{&DataCsects, &FuncDSCsects, &TOCCsects}),
252256
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}) {}
254262

255263
void XCOFFObjectWriter::reset() {
256264
// Clear the mappings we created.
@@ -297,6 +305,16 @@ CsectGroup &XCOFFObjectWriter::getCsectGroup(const MCSectionXCOFF *MCSec) {
297305
"Mapping invalid csect. CSECT with bss storage class must be "
298306
"common type.");
299307
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;
300318
case XCOFF::XMC_TC0:
301319
assert(XCOFF::XTY_SD == MCSec->getCSectType() &&
302320
"Only an initialized csect can contain TOC-base.");
@@ -493,9 +511,11 @@ void XCOFFObjectWriter::writeSections(const MCAssembler &Asm,
493511

494512
// There could be a gap (without corresponding zero padding) between
495513
// sections.
496-
assert(CurrentAddressLocation <= Section->Address &&
514+
assert(((CurrentAddressLocation <= Section->Address) ||
515+
(Section->Flags == XCOFF::STYP_TDATA) ||
516+
(Section->Flags == XCOFF::STYP_TBSS)) &&
497517
"CurrentAddressLocation should be less than or equal to section "
498-
"address.");
518+
"address if the section is not TData or TBSS.");
499519

500520
CurrentAddressLocation = Section->Address;
501521

@@ -828,6 +848,7 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
828848
uint32_t Address = 0;
829849
// Section indices are 1-based in XCOFF.
830850
int32_t SectionIndex = 1;
851+
bool HasTDataSection = false;
831852

832853
for (auto *Section : Sections) {
833854
const bool IsEmpty =
@@ -842,6 +863,16 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
842863
SectionCount++;
843864

844865
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+
845876
for (auto *Group : Section->Groups) {
846877
if (Group->empty())
847878
continue;

0 commit comments

Comments
 (0)