Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1971,11 +1971,10 @@ MCSymbol * TargetLoweringObjectFileXCOFF::getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const { - if (TM.getDataSections()) - report_fatal_error("XCOFF unique data sections not yet implemented"); - // We always use a qualname symbol for a GV that represents // a declaration, a function descriptor, or a common symbol. + // If a GV represents a GlobalVariable and -fdata-sections is enabled, we + // also return a qualname so that a label symbol could be avoided. // It is inherently ambiguous when the GO represents the address of a // function, as the GO could either represent a function descriptor or a // function entry point. We choose to always return a function descriptor @@ -1990,15 +1989,12 @@ return cast( getSectionForFunctionDescriptor(cast(GO), TM)) ->getQualNameSymbol(); - if (GOKind.isCommon() || GOKind.isBSSLocal()) + if (TM.getDataSections() || GOKind.isCommon() || GOKind.isBSSLocal()) return cast(SectionForGlobal(GO, GOKind, TM)) ->getQualNameSymbol(); } // For all other cases, fall back to getSymbol to return the unqualified name. - // This could change for a GV that is a GlobalVariable when we decide to - // support -fdata-sections since we could avoid having label symbols if the - // linkage name is applied to the csect symbol. return nullptr; } @@ -2023,9 +2019,6 @@ MCSection *TargetLoweringObjectFileXCOFF::SelectSectionForGlobal( const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { - assert(!TM.getDataSections() && - "XCOFF unique data sections not yet implemented."); - // Common symbols go into a csect with matching name which will get mapped // into the .bss section. if (Kind.isBSSLocal() || Kind.isCommon()) { @@ -2045,6 +2038,9 @@ SmallString<128> Name; Name = SizeSpec + utostr(Alignment.value()); + if (TM.getDataSections()) + getNameWithPrefix(Name, GO, TM); + return getContext().getXCOFFSection(Name, XCOFF::XMC_RO, XCOFF::XTY_SD, Kind, /*BeginSymbolName*/ nullptr); } @@ -2057,20 +2053,32 @@ return TextSection; } - if (Kind.isData() || Kind.isReadOnlyWithRel()) - // TODO: We may put this under option control, because user may want to - // have read-only data with relocations placed into a read-only section by - // the compiler. - return DataSection; - - // Zero initialized data must be emitted to the .data section because external - // linkage control sections that get mapped to the .bss section will be linked - // as tentative defintions, which is only appropriate for SectionKind::Common. - if (Kind.isBSS()) + // TODO: We may put Kind.isReadOnlyWithRel() under option control, because + // user may want to have read-only data with relocations placed into a + // read-only section by the compiler. + // For BSS kind, zero initialized data must be emitted to the .data section + // because external linkage control sections that get mapped to the .bss + // section will be linked as tentative defintions, which is only appropriate + // for SectionKind::Common. + if (Kind.isData() || Kind.isReadOnlyWithRel() || Kind.isBSS()) { + if (TM.getDataSections()) { + SmallString<128> Name; + getNameWithPrefix(Name, GO, TM); + return getContext().getXCOFFSection(Name, XCOFF::XMC_RW, XCOFF::XTY_SD, + SectionKind::getData()); + } return DataSection; + } - if (Kind.isReadOnly()) + if (Kind.isReadOnly()) { + if (TM.getDataSections()) { + SmallString<128> Name; + getNameWithPrefix(Name, GO, TM); + return getContext().getXCOFFSection(Name, XCOFF::XMC_RO, XCOFF::XTY_SD, + SectionKind::getReadOnly()); + } return ReadOnlySection; + } report_fatal_error("XCOFF other section types not yet implemented."); } Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1793,11 +1793,16 @@ MCSymbol *EmittedInitSym = GVSym; emitLinkage(GV, EmittedInitSym); emitAlignment(getGVAlignment(GV, DL), GV); - OutStreamer->emitLabel(EmittedInitSym); + // When -fdata-sections is enabled, every GlobalVariable will + // be put into its own csect; therefore, label is not necessary here. + if (!TM.getDataSections()) + OutStreamer->emitLabel(EmittedInitSym); + // Emit aliasing label for global variable. llvm::for_each(GOAliasMap[GV], [this](const GlobalAlias *Alias) { OutStreamer->emitLabel(getSymbol(Alias)); }); + emitGlobalConstant(GV->getParent()->getDataLayout(), GV->getInitializer()); } Index: llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/PowerPC/aix-xcoff-data-sections.ll @@ -0,0 +1,317 @@ +; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mtriple powerpc-ibm-aix-xcoff -data-sections < %s | FileCheck --check-prefixes=CHECK %s +; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mtriple powerpc64-ibm-aix-xcoff -data-sections < %s | FileCheck --check-prefixes=CHECK %s +; RUN: llc -verify-machineinstrs -mcpu=pwr4 -mtriple powerpc-ibm-aix-xcoff -filetype=obj -data-sections -o %t.o < %s +; RUN: llvm-objdump -D %t.o | FileCheck --check-prefix=CHECKOBJ %s +; RUN: llvm-readobj -syms %t.o | FileCheck --check-prefix=CHECKSYM %s + +@ivar = local_unnamed_addr global i32 35, align 4 +@const_ivar = constant i32 35, align 4 + +@a = common global i32 0, align 4 +@f = common local_unnamed_addr global i32 0, align 4 + +@.str = private unnamed_addr constant [9 x i8] c"abcdefgh\00", align 1 +@p = global i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i32 0, i32 0), align 4 + +define i8 @foo() { +entry: + %0 = load i8*, i8** @p, align 4 + %1 = load i8, i8* %0, align 1 + ret i8 %1 +} + +define i32 @bar() { +entry: + %0 = load i32, i32* @ivar, align 4 + %1 = load i32, i32* @const_ivar, align 4 + %add = add nsw i32 %0, %1 + %2 = load i32, i32* @a, align 4 + %add1 = add nsw i32 %add, %2 + %3 = load i32, i32* @f, align 4 + %add2 = add nsw i32 %add1, %3 + ret i32 %add2 +} + + +; CHECK: .csect ivar[RW],2 +; CHECK-NEXT: .globl ivar[RW] +; CHECK-NEXT: .align 2 +; CHECK-NEXT: .vbyte 4, 35 # 0x23 +; CHECK-NEXT: .csect const_ivar[RO],2 +; CHECK-NEXT: .globl const_ivar[RO] +; CHECK-NEXT: .align 2 +; CHECK-NEXT: .vbyte 4, 35 # 0x23 +; CHECK-NEXT: .comm a[RW],4,2 +; CHECK-NEXT: .comm f[RW],4,2 +; CHECK-NEXT: .csect .rodata.str1.1L...str[RO],2 +; CHECK-NEXT: .byte 97 +; CHECK-NEXT: .byte 98 +; CHECK-NEXT: .byte 99 +; CHECK-NEXT: .byte 100 +; CHECK-NEXT: .byte 101 +; CHECK-NEXT: .byte 102 +; CHECK-NEXT: .byte 103 +; CHECK-NEXT: .byte 104 +; CHECK-NEXT: .byte 0 +; CHECK32: .csect p[RW],2 +; CHECK32-NEXT: .globl p[RW] +; CHECK32-NEXT: .align 2 +; CHECK32-NEXT: .vbyte 4, .rodata.str1.1L...str[RO] +; CHECK64: .csect p[RW],3 +; CHECK64-NEXT: .globl p[RW] +; CHECK64-NEXT: .align 3 +; CHECK64-NEXT: .vbyte 8, .rodata.str1.1L...str[RO] +; CHECK: .toc +; CHECK-NEXT: L..C0: +; CHECK-NEXT: .tc p[TC],p[RW] +; CHECK-NEXT: L..C1: +; CHECK-NEXT: .tc ivar[TC],ivar[RW] +; CHECK-NEXT: L..C2: +; CHECK-NEXT: .tc a[TC],a[RW] +; CHECK-NEXT: L..C3: +; CHECK-NEXT: .tc f[TC],f[RW] + +; CHECKOBJ: 00000038 : +; CHECKOBJ-NEXT: 38: 00 00 00 23 +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 0000003c <.rodata.str1.1L...str>: +; CHECKOBJ-NEXT: 3c: 61 62 63 64 ori 2, 11, 25444 +; CHECKOBJ-NEXT: 40: 65 66 67 68 oris 6, 11, 26472 +; CHECKOBJ-NEXT: 44: 00 00 00 00 +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: Disassembly of section .data: +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 00000048 : +; CHECKOBJ-NEXT: 48: 00 00 00 23 +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 0000004c

: +; CHECKOBJ-NEXT: 4c: 00 00 00 3c +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 00000050 : +; CHECKOBJ-NEXT: 50: 00 00 00 00 +; CHECKOBJ-NEXT: 54: 00 00 00 68 +; CHECKOBJ-NEXT: 58: 00 00 00 00 +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 0000005c : +; CHECKOBJ-NEXT: 5c: 00 00 00 10 +; CHECKOBJ-NEXT: 60: 00 00 00 68 +; CHECKOBJ-NEXT: 64: 00 00 00 00 +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 00000068

: +; CHECKOBJ-NEXT: 68: 00 00 00 4c +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 0000006c : +; CHECKOBJ-NEXT: 6c: 00 00 00 48 +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 00000070 : +; CHECKOBJ-NEXT: 70: 00 00 00 78 +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 00000074 : +; CHECKOBJ-NEXT: 74: 00 00 00 7c +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: Disassembly of section .bss: +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 00000078 : +; CHECKOBJ-NEXT: ... +; CHECKOBJ-EMPTY: +; CHECKOBJ-NEXT: 0000007c : +; CHECKOBJ-NEXT: ... + +; CHECKSYM: Symbol { +; CHECKSYM: Name: const_ivar +; CHECKSYM: Value (RelocatableAddress): 0x38 +; CHECKSYM: Section: .text +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_EXT (0x2) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 4 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_SD (0x1) +; CHECKSYM: StorageMappingClass: XMC_RO (0x1) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: .rodata.str1.1L...str +; CHECKSYM: Value (RelocatableAddress): 0x3C +; CHECKSYM: Section: .text +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_HIDEXT (0x6B) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 9 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_SD (0x1) +; CHECKSYM: StorageMappingClass: XMC_RO (0x1) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: ivar +; CHECKSYM: Value (RelocatableAddress): 0x48 +; CHECKSYM: Section: .data +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_EXT (0x2) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 4 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_SD (0x1) +; CHECKSYM: StorageMappingClass: XMC_RW (0x5) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: p +; CHECKSYM: Value (RelocatableAddress): 0x4C +; CHECKSYM: Section: .data +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_EXT (0x2) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 4 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_SD (0x1) +; CHECKSYM: StorageMappingClass: XMC_RW (0x5) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: TOC +; CHECKSYM: Value (RelocatableAddress): 0x68 +; CHECKSYM: Section: .data +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_HIDEXT (0x6B) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 0 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_SD (0x1) +; CHECKSYM: StorageMappingClass: XMC_TC0 (0xF) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: p +; CHECKSYM: Value (RelocatableAddress): 0x68 +; CHECKSYM: Section: .data +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_HIDEXT (0x6B) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 4 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_SD (0x1) +; CHECKSYM: StorageMappingClass: XMC_TC (0x3) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: ivar +; CHECKSYM: Value (RelocatableAddress): 0x6C +; CHECKSYM: Section: .data +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_HIDEXT (0x6B) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 4 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_SD (0x1) +; CHECKSYM: StorageMappingClass: XMC_TC (0x3) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: a +; CHECKSYM: Value (RelocatableAddress): 0x70 +; CHECKSYM: Section: .data +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_HIDEXT (0x6B) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 4 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_SD (0x1) +; CHECKSYM: StorageMappingClass: XMC_TC (0x3) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: f +; CHECKSYM: Value (RelocatableAddress): 0x74 +; CHECKSYM: Section: .data +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_HIDEXT (0x6B) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 4 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_SD (0x1) +; CHECKSYM: StorageMappingClass: XMC_TC (0x3) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: a +; CHECKSYM: Value (RelocatableAddress): 0x78 +; CHECKSYM: Section: .bss +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_EXT (0x2) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 4 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_CM (0x3) +; CHECKSYM: StorageMappingClass: XMC_RW (0x5) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: } +; CHECKSYM: Symbol { +; CHECKSYM: Name: f +; CHECKSYM: Value (RelocatableAddress): 0x7C +; CHECKSYM: Section: .bss +; CHECKSYM: Type: 0x0 +; CHECKSYM: StorageClass: C_EXT (0x2) +; CHECKSYM: NumberOfAuxEntries: 1 +; CHECKSYM: CSECT Auxiliary Entry { +; CHECKSYM: SectionLen: 4 +; CHECKSYM: ParameterHashIndex: 0x0 +; CHECKSYM: TypeChkSectNum: 0x0 +; CHECKSYM: SymbolAlignmentLog2: 2 +; CHECKSYM: SymbolType: XTY_CM (0x3) +; CHECKSYM: StorageMappingClass: XMC_RW (0x5) +; CHECKSYM: StabInfoIndex: 0x0 +; CHECKSYM: StabSectNum: 0x0 +; CHECKSYM: } +; CHECKSYM: }