Index: llvm/lib/MC/XCOFFObjectWriter.cpp =================================================================== --- llvm/lib/MC/XCOFFObjectWriter.cpp +++ llvm/lib/MC/XCOFFObjectWriter.cpp @@ -150,6 +150,7 @@ // 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 ReadOnlyCsects; CsectGroup DataCsects; CsectGroup FuncDSCsects; CsectGroup TOCCsects; @@ -219,7 +220,7 @@ : W(OS, support::big), TargetObjectWriter(std::move(MOTW)), Strings(StringTableBuilder::XCOFF), Text(".text", XCOFF::STYP_TEXT, /* IsVirtual */ false, - CsectGroups{&ProgramCodeCsects}), + CsectGroups{&ProgramCodeCsects, &ReadOnlyCsects}), Data(".data", XCOFF::STYP_DATA, /* IsVirtual */ false, CsectGroups{&DataCsects, &FuncDSCsects, &TOCCsects}), BSS(".bss", XCOFF::STYP_BSS, /* IsVirtual */ true, @@ -245,6 +246,10 @@ assert(XCOFF::XTY_SD == MCSec->getCSectType() && "Only an initialized csect can contain program code."); return ProgramCodeCsects; + case XCOFF::XMC_RO: + assert(XCOFF::XTY_SD == MCSec->getCSectType() && + "Only an initialized csect can contain read only data."); + return ReadOnlyCsects; case XCOFF::XMC_RW: if (XCOFF::XTY_CM == MCSec->getCSectType()) return BSSCsects; Index: llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll =================================================================== --- llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll +++ llvm/test/CodeGen/PowerPC/aix-xcoff-rodata.ll @@ -1,6 +1,15 @@ ; 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 +; RUN: llc -mtriple powerpc-ibm-aix-xcoff -filetype=obj -o %t.o < %s +; RUN: llvm-readobj --section-headers --file-header %t.o | \ +; RUN: FileCheck --check-prefix=OBJ %s +; RUN: llvm-readobj --syms %t.o | FileCheck --check-prefix=SYMS %s + +; RUN: not llc -mtriple powerpc64-ibm-aix-xcoff -filetype=obj < %s 2>&1 | \ +; RUN: FileCheck --check-prefix=XCOFF64 %s +; XCOFF64: LLVM ERROR: 64-bit XCOFF object files are not supported yet. + @const_ivar = constant i32 35, align 4 @const_llvar = constant i64 36, align 8 @const_svar = constant i16 37, align 2 @@ -48,3 +57,230 @@ ; CHECK-NEXT: .llong 4611686018427387904 ; CHECK-NEXT: .llong 4613937818241073152 ; CHECK-NEXT: .llong 4616189618054758400 + + +; OBJ: File: {{.*}}aix-xcoff-rodata.ll.tmp.o +; OBJ-NEXT: Format: aixcoff-rs6000 +; OBJ-NEXT: Arch: powerpc +; OBJ-NEXT: AddressSize: 32bit +; OBJ-NEXT: FileHeader { +; OBJ-NEXT: Magic: 0x1DF +; OBJ-NEXT: NumberOfSections: 1 +; OBJ-NEXT: TimeStamp: None (0x0) +; OBJ-NEXT: SymbolTableOffset: 0x8C +; OBJ-NEXT: SymbolTableEntries: 20 +; OBJ-NEXT: OptionalHeaderSize: 0x0 +; OBJ-NEXT: Flags: 0x0 +; OBJ-NEXT: } + +; OBJ: Sections [ +; OBJ: Section { +; OBJ-NEXT: Index: 1 +; OBJ-NEXT: Name: .text +; OBJ-NEXT: PhysicalAddress: 0x0 +; OBJ-NEXT: VirtualAddress: 0x0 +; OBJ-NEXT: Size: 0x50 +; OBJ-NEXT: RawDataOffset: 0x3C +; OBJ-NEXT: RelocationPointer: 0x0 +; OBJ-NEXT: LineNumberPointer: 0x0 +; OBJ-NEXT: NumberOfRelocations: 0 +; OBJ-NEXT: NumberOfLineNumbers: 0 +; OBJ-NEXT: Type: STYP_TEXT (0x20) +; OBJ-NEXT: } +; OBJ-NEXT: ] + + +; SYMS: File: {{.*}}aix-xcoff-rodata.ll.tmp.o +; SYMS-NEXT: Format: aixcoff-rs6000 +; SYMS-NEXT: Arch: powerpc +; SYMS-NEXT: AddressSize: 32bit +; SYMS: Symbols [ +; SYMS: Symbol { +; SYMS-NEXT: Index: [[#INDX:]] +; SYMS-NEXT: Name: .rodata +; SYMS-NEXT: Value (RelocatableAddress): 0x0 +; SYMS-NEXT: Section: .text +; SYMS-NEXT: Type: 0x0 +; SYMS-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYMS-NEXT: NumberOfAuxEntries: 1 +; SYMS-NEXT: CSECT Auxiliary Entry { +; SYMS-NEXT: Index: [[#INDX+1]] +; SYMS-NEXT: SectionLen: 80 +; SYMS-NEXT: ParameterHashIndex: 0x0 +; SYMS-NEXT: TypeChkSectNum: 0x0 +; SYMS-NEXT: SymbolAlignmentLog2: 5 +; SYMS-NEXT: SymbolType: XTY_SD (0x1) +; SYMS-NEXT: StorageMappingClass: XMC_RO (0x1) +; SYMS-NEXT: StabInfoIndex: 0x0 +; SYMS-NEXT: StabSectNum: 0x0 +; SYMS-NEXT: } +; SYMS-NEXT: } + +; SYMS: Symbol { +; SYMS-NEXT: Index: [[#INDX+2]] +; SYMS-NEXT: Name: const_ivar +; SYMS-NEXT: Value (RelocatableAddress): 0x0 +; SYMS-NEXT: Section: .text +; SYMS-NEXT: Type: 0x0 +; SYMS-NEXT: StorageClass: C_EXT (0x2) +; SYMS-NEXT: NumberOfAuxEntries: 1 +; SYMS-NEXT: CSECT Auxiliary Entry { +; SYMS-NEXT: Index: [[#INDX+3]] +; SYMS-NEXT: ContainingCsectSymbolIndex: 2 +; SYMS-NEXT: ParameterHashIndex: 0x0 +; SYMS-NEXT: TypeChkSectNum: 0x0 +; SYMS-NEXT: SymbolAlignmentLog2: 0 +; SYMS-NEXT: SymbolType: XTY_LD (0x2) +; SYMS-NEXT: StorageMappingClass: XMC_RO (0x1) +; SYMS-NEXT: StabInfoIndex: 0x0 +; SYMS-NEXT: StabSectNum: 0x0 +; SYMS-NEXT: } +; SYMS-NEXT: } + +; SYMS: Symbol { +; SYMS-NEXT: Index: [[#INDX+4]] +; SYMS-NEXT: Name: const_llvar +; SYMS-NEXT: Value (RelocatableAddress): 0x8 +; SYMS-NEXT: Section: .text +; SYMS-NEXT: Type: 0x0 +; SYMS-NEXT: StorageClass: C_EXT (0x2) +; SYMS-NEXT: NumberOfAuxEntries: 1 +; SYMS-NEXT: CSECT Auxiliary Entry { +; SYMS-NEXT: Index: [[#INDX+5]] +; SYMS-NEXT: ContainingCsectSymbolIndex: 2 +; SYMS-NEXT: ParameterHashIndex: 0x0 +; SYMS-NEXT: TypeChkSectNum: 0x0 +; SYMS-NEXT: SymbolAlignmentLog2: 0 +; SYMS-NEXT: SymbolType: XTY_LD (0x2) +; SYMS-NEXT: StorageMappingClass: XMC_RO (0x1) +; SYMS-NEXT: StabInfoIndex: 0x0 +; SYMS-NEXT: StabSectNum: 0x0 +; SYMS-NEXT: } +; SYMS-NEXT: } + +; SYMS: Symbol { +; SYMS-NEXT: Index: [[#INDX+6]] +; SYMS-NEXT: Name: const_svar +; SYMS-NEXT: Value (RelocatableAddress): 0x10 +; SYMS-NEXT: Section: .text +; SYMS-NEXT: Type: 0x0 +; SYMS-NEXT: StorageClass: C_EXT (0x2) +; SYMS-NEXT: NumberOfAuxEntries: 1 +; SYMS-NEXT: CSECT Auxiliary Entry { +; SYMS-NEXT: Index: [[#INDX+7]] +; SYMS-NEXT: ContainingCsectSymbolIndex: 2 +; SYMS-NEXT: ParameterHashIndex: 0x0 +; SYMS-NEXT: TypeChkSectNum: 0x0 +; SYMS-NEXT: SymbolAlignmentLog2: 0 +; SYMS-NEXT: SymbolType: XTY_LD (0x2) +; SYMS-NEXT: StorageMappingClass: XMC_RO (0x1) +; SYMS-NEXT: StabInfoIndex: 0x0 +; SYMS-NEXT: StabSectNum: 0x0 +; SYMS-NEXT: } +; SYMS-NEXT: } + +; SYMS: Symbol { +; SYMS-NEXT: Index: [[#INDX+8]] +; SYMS-NEXT: Name: const_fvar +; SYMS-NEXT: Value (RelocatableAddress): 0x14 +; SYMS-NEXT: Section: .text +; SYMS-NEXT: Type: 0x0 +; SYMS-NEXT: StorageClass: C_EXT (0x2) +; SYMS-NEXT: NumberOfAuxEntries: 1 +; SYMS-NEXT: CSECT Auxiliary Entry { +; SYMS-NEXT: Index: [[#INDX+9]] +; SYMS-NEXT: ContainingCsectSymbolIndex: 2 +; SYMS-NEXT: ParameterHashIndex: 0x0 +; SYMS-NEXT: TypeChkSectNum: 0x0 +; SYMS-NEXT: SymbolAlignmentLog2: 0 +; SYMS-NEXT: SymbolType: XTY_LD (0x2) +; SYMS-NEXT: StorageMappingClass: XMC_RO (0x1) +; SYMS-NEXT: StabInfoIndex: 0x0 +; SYMS-NEXT: StabSectNum: 0x0 +; SYMS-NEXT: } +; SYMS-NEXT: } + +; SYMS: Symbol { +; SYMS-NEXT: Index: [[#INDX+10]] +; SYMS-NEXT: Name: const_dvar +; SYMS-NEXT: Value (RelocatableAddress): 0x18 +; SYMS-NEXT: Section: .text +; SYMS-NEXT: Type: 0x0 +; SYMS-NEXT: StorageClass: C_EXT (0x2) +; SYMS-NEXT: NumberOfAuxEntries: 1 +; SYMS-NEXT: CSECT Auxiliary Entry { +; SYMS-NEXT: Index: [[#INDX+11]] +; SYMS-NEXT: ContainingCsectSymbolIndex: 2 +; SYMS-NEXT: ParameterHashIndex: 0x0 +; SYMS-NEXT: TypeChkSectNum: 0x0 +; SYMS-NEXT: SymbolAlignmentLog2: 0 +; SYMS-NEXT: SymbolType: XTY_LD (0x2) +; SYMS-NEXT: StorageMappingClass: XMC_RO (0x1) +; SYMS-NEXT: StabInfoIndex: 0x0 +; SYMS-NEXT: StabSectNum: 0x0 +; SYMS-NEXT: } +; SYMS-NEXT: } + +; SYMS: Symbol { +; SYMS-NEXT: Index: [[#INDX+12]] +; SYMS-NEXT: Name: const_over_aligned +; SYMS-NEXT: Value (RelocatableAddress): 0x20 +; SYMS-NEXT: Section: .text +; SYMS-NEXT: Type: 0x0 +; SYMS-NEXT: StorageClass: C_EXT (0x2) +; SYMS-NEXT: NumberOfAuxEntries: 1 +; SYMS-NEXT: CSECT Auxiliary Entry { +; SYMS-NEXT: Index: [[#INDX+13]] +; SYMS-NEXT: ContainingCsectSymbolIndex: 2 +; SYMS-NEXT: ParameterHashIndex: 0x0 +; SYMS-NEXT: TypeChkSectNum: 0x0 +; SYMS-NEXT: SymbolAlignmentLog2: 0 +; SYMS-NEXT: SymbolType: XTY_LD (0x2) +; SYMS-NEXT: StorageMappingClass: XMC_RO (0x1) +; SYMS-NEXT: StabInfoIndex: 0x0 +; SYMS-NEXT: StabSectNum: 0x0 +; SYMS-NEXT: } +; SYMS-NEXT: } + +; SYMS: Symbol { +; SYMS-NEXT: Index: [[#INDX+14]] +; SYMS-NEXT: Name: const_chrarray +; SYMS-NEXT: Value (RelocatableAddress): 0x28 +; SYMS-NEXT: Section: .text +; SYMS-NEXT: Type: 0x0 +; SYMS-NEXT: StorageClass: C_EXT (0x2) +; SYMS-NEXT: NumberOfAuxEntries: 1 +; SYMS-NEXT: CSECT Auxiliary Entry { +; SYMS-NEXT: Index: [[#INDX+15]] +; SYMS-NEXT: ContainingCsectSymbolIndex: 2 +; SYMS-NEXT: ParameterHashIndex: 0x0 +; SYMS-NEXT: TypeChkSectNum: 0x0 +; SYMS-NEXT: SymbolAlignmentLog2: 0 +; SYMS-NEXT: SymbolType: XTY_LD (0x2) +; SYMS-NEXT: StorageMappingClass: XMC_RO (0x1) +; SYMS-NEXT: StabInfoIndex: 0x0 +; SYMS-NEXT: StabSectNum: 0x0 +; SYMS-NEXT: } +; SYMS-NEXT: } + +; SYMS: Symbol { +; SYMS-NEXT: Index: [[#INDX+16]] +; SYMS-NEXT: Name: const_dblarr +; SYMS-NEXT: Value (RelocatableAddress): 0x30 +; SYMS-NEXT: Section: .text +; SYMS-NEXT: Type: 0x0 +; SYMS-NEXT: StorageClass: C_EXT (0x2) +; SYMS-NEXT: NumberOfAuxEntries: 1 +; SYMS-NEXT: CSECT Auxiliary Entry { +; SYMS-NEXT: Index: [[#INDX+17]] +; SYMS-NEXT: ContainingCsectSymbolIndex: 2 +; SYMS-NEXT: ParameterHashIndex: 0x0 +; SYMS-NEXT: TypeChkSectNum: 0x0 +; SYMS-NEXT: SymbolAlignmentLog2: 0 +; SYMS-NEXT: SymbolType: XTY_LD (0x2) +; SYMS-NEXT: StorageMappingClass: XMC_RO (0x1) +; SYMS-NEXT: StabInfoIndex: 0x0 +; SYMS-NEXT: StabSectNum: 0x0 +; SYMS-NEXT: } +; SYMS-NEXT: } +; SYMS: ]