Index: llvm/lib/BinaryFormat/XCOFF.cpp =================================================================== --- llvm/lib/BinaryFormat/XCOFF.cpp +++ llvm/lib/BinaryFormat/XCOFF.cpp @@ -22,6 +22,8 @@ return "TC0"; case XCOFF::XMC_BS: return "BS"; + case XCOFF::XMC_RO: + return "RO"; default: report_fatal_error("Unhandled storage-mapping class."); } Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1861,6 +1861,10 @@ if (Kind.isBSS()) return DataSection; + if (Kind.isReadOnly() && !Kind.isMergeableConst() && + !Kind.isMergeableCString()) + return ReadOnlySection; + report_fatal_error("XCOFF other section types not yet implemented."); } Index: llvm/lib/MC/MCObjectFileInfo.cpp =================================================================== --- llvm/lib/MC/MCObjectFileInfo.cpp +++ llvm/lib/MC/MCObjectFileInfo.cpp @@ -777,6 +777,10 @@ DataSection = Ctx->getXCOFFSection( ".data", XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD, XCOFF::C_HIDEXT, SectionKind::getData()); + + ReadOnlySection = Ctx->getXCOFFSection( + ".rodata", XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD, + XCOFF::C_HIDEXT, SectionKind::getReadOnly()); } void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC, Index: llvm/lib/MC/MCSectionXCOFF.cpp =================================================================== --- llvm/lib/MC/MCSectionXCOFF.cpp +++ llvm/lib/MC/MCSectionXCOFF.cpp @@ -27,6 +27,13 @@ return; } + if (getKind().isReadOnly()) { + if (getMappingClass() != XCOFF::XMC_RO) + report_fatal_error("Unhandled storage-mapping class for .rodata csect."); + OS << "\t.csect " << QualName->getName() << '\n'; + return; + } + if (getKind().isData()) { switch (getMappingClass()) { case XCOFF::XMC_RW: Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1747,7 +1747,9 @@ report_fatal_error("COMDAT not yet supported by AIX."); SectionKind GVKind = getObjFileLowering().getKindForGlobal(GV, TM); - if (!GVKind.isCommon() && !GVKind.isBSS() && !GVKind.isData()) + if ((!GVKind.isCommon() && !GVKind.isBSS() && !GVKind.isData() && + !GVKind.isReadOnly()) || + GVKind.isMergeableCString() || GVKind.isMergeableConst()) report_fatal_error("Encountered a global variable kind that is " "not supported yet."); Index: llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll @@ -0,0 +1,50 @@ +; RUN: llc -verify-machineinstrs -mcpu=pwr7 -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s +; RUN: llc -verify-machineinstrs -mcpu=pwr7 -mtriple powerpc64-ibm-aix-xcoff < %s | FileCheck %s + +@const_ivar = constant i32 35, align 4 +@const_llvar = constant i64 36, align 8 +@const_svar = constant i16 37, align 2 +@const_fvar = constant float 8.000000e+02, align 4 +@const_dvar = constant double 9.000000e+02, align 8 +@const_over_aligned = constant double 9.000000e+02, align 32 +@const_chrarray = constant [4 x i8] c"abcd", align 1 +@const_dblarr = constant [4 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00], align 8 + +; CHECK: .csect .rodata[RO] +; CHECK-NEXT: .globl const_ivar +; CHECK-NEXT: .align 2 +; CHECK-NEXT: const_ivar: +; CHECK-NEXT: .long 35 +; CHECK-NEXT: .globl const_llvar +; CHECK-NEXT: .align 3 +; CHECK-NEXT: const_llvar: +; CHECK-NEXT: .llong 36 +; CHECK-NEXT: .globl const_svar +; CHECK-NEXT: .align 1 +; CHECK-NEXT: const_svar: +; CHECK-NEXT: .short 37 +; CHECK-NEXT: .globl const_fvar +; CHECK-NEXT: .align 2 +; CHECK-NEXT: const_fvar: +; CHECK-NEXT: .long 1145569280 +; CHECK-NEXT: .globl const_dvar +; CHECK-NEXT: .align 3 +; CHECK-NEXT: const_dvar: +; CHECK-NEXT: .llong 4651127699538968576 +; CHECK-NEXT: .globl const_over_aligned +; CHECK-NEXT: .align 5 +; CHECK-NEXT: const_over_aligned: +; CHECK-NEXT: .llong 4651127699538968576 +; CHECK-NEXT: .globl const_chrarray +; CHECK-NEXT: const_chrarray: +; CHECK-NEXT: .byte 97 +; CHECK-NEXT: .byte 98 +; CHECK-NEXT: .byte 99 +; CHECK-NEXT: .byte 100 +; CHECK-NEXT: .globl const_dblarr +; CHECK-NEXT: .align 3 +; CHECK-NEXT: const_dblarr: +; CHECK-NEXT: .llong 4607182418800017408 +; CHECK-NEXT: .llong 4611686018427387904 +; CHECK-NEXT: .llong 4613937818241073152 +; CHECK-NEXT: .llong 4616189618054758400