[PowerPC][AIX] Adds support for writing the .data section in assembly files
Summary:
Adds support for generating the .data section in assembly files for global variables with a non-zero initialization. The support for writing the .data section in XCOFF object files will be added in a follow-on patch. Any relocations are not included in this patch.
Reviewers: hubert.reinterpretcast, sfertile, jasonliu, daltenty, Xiangling_L
Reviewed by: hubert.reinterpretcast
Subscribers: nemanjai, hiraditya, kbarton, MaskRay, jsji, wuzish, shchenz, DiggerLin, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66154
llvm-svn: 369869
diff --git a/llvm/lib/MC/MCAsmInfoXCOFF.cpp b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
index 92dc505..13939f6 100644
--- a/llvm/lib/MC/MCAsmInfoXCOFF.cpp
+++ b/llvm/lib/MC/MCAsmInfoXCOFF.cpp
@@ -17,4 +17,8 @@
HasDotTypeDotSizeDirective = false;
COMMDirectiveAlignmentIsInBytes = false;
LCOMMDirectiveAlignmentType = LCOMM::Log2Alignment;
+ UseDotAlignForAlignment = true;
+ AsciiDirective = nullptr; // not supported
+ AscizDirective = nullptr; // not supported
+ Data64bitsDirective = "\t.llong\t";
}
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index e20ba2f..e37bc4a 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -1119,6 +1119,16 @@
void MCAsmStreamer::EmitValueToAlignment(unsigned ByteAlignment, int64_t Value,
unsigned ValueSize,
unsigned MaxBytesToEmit) {
+ if (MAI->useDotAlignForAlignment()) {
+ if (!isPowerOf2_32(ByteAlignment))
+ report_fatal_error("Only power-of-two alignments are supported "
+ "with .align.");
+ OS << "\t.align\t";
+ OS << Log2_32(ByteAlignment);
+ EmitEOL();
+ return;
+ }
+
// Some assemblers don't support non-power of two alignments, so we always
// emit alignments as a power of two if possible.
if (isPowerOf2_32(ByteAlignment)) {
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index d59453a..861e501 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -770,6 +770,10 @@
TextSection = Ctx->getXCOFFSection(
".text", XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD,
XCOFF::C_HIDEXT, SectionKind::getText());
+
+ DataSection = Ctx->getXCOFFSection(
+ ".data", XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD,
+ XCOFF::C_HIDEXT, SectionKind::getData());
}
void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
diff --git a/llvm/lib/MC/MCSectionXCOFF.cpp b/llvm/lib/MC/MCSectionXCOFF.cpp
index d00a435..db27752 100644
--- a/llvm/lib/MC/MCSectionXCOFF.cpp
+++ b/llvm/lib/MC/MCSectionXCOFF.cpp
@@ -28,6 +28,16 @@
return;
}
+ if (getKind().isData()) {
+ assert(getMappingClass() == XCOFF::XMC_RW &&
+ "Unhandled storage-mapping class for data section.");
+
+ OS << "\t.csect " << getSectionName() << "["
+ << "RW"
+ << "]" << '\n';
+ return;
+ }
+
if (getKind().isBSSLocal() || getKind().isCommon()) {
assert((getMappingClass() == XCOFF::XMC_RW ||
getMappingClass() == XCOFF::XMC_BS) &&