[PowerPC][AIX] Adds support for writing the data section in object files
Adds support for generating the XCOFF data section in object files for global variables with initialization.
Merged aix-xcoff-common.ll into aix-xcoff-data.ll.
Changed variable name charr to chrarray in the test case to test if readobj works with 8-character names.
Authored by: xingxue
Reviewers: hubert.reinterptrtcast, sfertile, jasonliu, daltenty, Xiangling_L.
Reviewed by: hubert.reinterpretcast, sfertile, daltenty.
Subscribers: DiggerLin, Wuzish, nemanjai, hiraditya, MaskRay, jsji, shchenz, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67125
diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index 05f3f76..d8f9e0b 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -158,15 +158,17 @@
// the sections. Should have one for each set of csects that get mapped into
// the same section and get handled in a 'similar' way.
CsectGroup ProgramCodeCsects{CsectGroup::LabelDefSupported, {}};
+ CsectGroup DataCsects{CsectGroup::LabelDefSupported, {}};
CsectGroup BSSCsects{CsectGroup::LabelDefUnsupported, {}};
// The Predefined sections.
Section Text;
+ Section Data;
Section BSS;
// All the XCOFF sections, in the order they will appear in the section header
// table.
- std::array<Section *const, 2> Sections{{&Text, &BSS}};
+ std::array<Section *const, 3> Sections{{&Text, &Data, &BSS}};
CsectGroup &getCsectGroup(const MCSectionXCOFF *MCSec);
@@ -224,6 +226,8 @@
Strings(StringTableBuilder::XCOFF),
Text(".text", XCOFF::STYP_TEXT, /* IsVirtual */ false,
CsectGroups{&ProgramCodeCsects}),
+ Data(".data", XCOFF::STYP_DATA, /* IsVirtual */ false,
+ CsectGroups{&DataCsects}),
BSS(".bss", XCOFF::STYP_BSS, /* IsVirtual */ true,
CsectGroups{&BSSCsects}) {}
@@ -251,6 +255,9 @@
if (XCOFF::XTY_CM == MCSec->getCSectType())
return BSSCsects;
+ if (XCOFF::XTY_SD == MCSec->getCSectType())
+ return DataCsects;
+
report_fatal_error("Unhandled mapping of read-write csect to section.");
case XCOFF::XMC_BS:
assert(XCOFF::XTY_CM == MCSec->getCSectType() &&