Index: llvm/lib/MC/MCXCOFFStreamer.cpp =================================================================== --- llvm/lib/MC/MCXCOFFStreamer.cpp +++ llvm/lib/MC/MCXCOFFStreamer.cpp @@ -50,12 +50,6 @@ XCOFF::C_HIDEXT); Symbol->setCommon(Size, ByteAlignment); - // Need to add this symbol to the current Fragment which will belong to the - // containing CSECT. - auto *F = dyn_cast_or_null(getCurrentFragment()); - assert(F && "Expected a valid section with a fragment set."); - Symbol->setFragment(F); - // Emit the alignment and storage for the variable to the section. EmitValueToAlignment(ByteAlignment); EmitZeros(Size); Index: llvm/lib/MC/XCOFFObjectWriter.cpp =================================================================== --- llvm/lib/MC/XCOFFObjectWriter.cpp +++ llvm/lib/MC/XCOFFObjectWriter.cpp @@ -275,6 +275,12 @@ "We should have only one TOC-base, and it should be the first csect " "in this CsectGroup."); return TOCCsects; + case XCOFF::XMC_TC: + assert(XCOFF::XTY_SD == MCSec->getCSectType() && + "Only an initialized csect can contain TC entry."); + assert(!TOCCsects.empty() && + "We should at least have a TOC-base in this CsectGroup."); + return TOCCsects; default: report_fatal_error("Unhandled mapping of csect to section."); } Index: llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp =================================================================== --- llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp +++ llvm/lib/Target/PowerPC/MCTargetDesc/PPCMCTargetDesc.cpp @@ -243,11 +243,17 @@ }; class PPCTargetXCOFFStreamer : public PPCTargetStreamer { +private: + bool Is64Bit; + public: - PPCTargetXCOFFStreamer(MCStreamer &S) : PPCTargetStreamer(S) {} + PPCTargetXCOFFStreamer(MCStreamer &S, bool Is64Bit) + : PPCTargetStreamer(S), Is64Bit(Is64Bit) {} void emitTCEntry(const MCSymbol &S) override { - // Object writing TOC entries not supported yet. + unsigned PointerSize = Is64Bit ? 8 : 4; + Streamer.EmitValueToAlignment(PointerSize); + Streamer.EmitSymbolValue(&S, PointerSize); } void emitMachine(StringRef CPU) override { @@ -278,7 +284,7 @@ if (TT.isOSBinFormatELF()) return new PPCTargetELFStreamer(S); if (TT.isOSBinFormatXCOFF()) - return new PPCTargetXCOFFStreamer(S); + return new PPCTargetXCOFFStreamer(S, TT.isArch64Bit()); return new PPCTargetMachOStreamer(S); } Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp =================================================================== --- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1839,6 +1839,8 @@ MCSectionXCOFF *TOCBaseSection = OutStreamer->getContext().getXCOFFSection( StringRef("TOC"), XCOFF::XMC_TC0, XCOFF::XTY_SD, XCOFF::C_HIDEXT, SectionKind::getData()); + // TOC-base always have 0 size, but 4 byte alignment. + TOCBaseSection->setAlignment(Align(4)); // Switch to section to emit TOC base. OutStreamer->SwitchSection(TOCBaseSection); Index: llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll =================================================================== --- llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll +++ llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll @@ -103,7 +103,7 @@ ; CHECK-NEXT: SectionLen: 0 ; CHECK-NEXT: ParameterHashIndex: 0x0 ; CHECK-NEXT: TypeChkSectNum: 0x0 -; CHECK-NEXT: SymbolAlignmentLog2: 0 +; CHECK-NEXT: SymbolAlignmentLog2: 2 ; CHECK-NEXT: SymbolType: XTY_SD (0x1) ; CHECK-NEXT: StorageMappingClass: XMC_TC0 (0xF) ; CHECK-NEXT: StabInfoIndex: 0x0 Index: llvm/test/CodeGen/PowerPC/aix-xcoff-data-only-notoc.ll =================================================================== --- llvm/test/CodeGen/PowerPC/aix-xcoff-data-only-notoc.ll +++ llvm/test/CodeGen/PowerPC/aix-xcoff-data-only-notoc.ll @@ -1,6 +1,13 @@ ; RUN: llc -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck %s ; RUN: llc -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck %s +; RUN: llc -mtriple powerpc-ibm-aix-xcoff -filetype=obj -o %t.o < %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=OBJ64 %s +; OBJ64: LLVM ERROR: 64-bit XCOFF object files are not supported yet. + @a = external global i32, align 4 @b = external global i64, align 8 @c = external global i16, align 2 @@ -9,4 +16,4 @@ @ptr = internal global void (...)* null, align 4 ; CHECK-NOT: .toc - +; SYMS-NOT: Name: TOC Index: llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll =================================================================== --- llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll +++ llvm/test/CodeGen/PowerPC/aix-xcoff-toc.ll @@ -1,6 +1,13 @@ ; RUN: llc -verify-machineinstrs -mcpu=pwr7 -mtriple powerpc-ibm-aix-xcoff < %s | FileCheck --check-prefixes CHECK,CHECK32 %s ; RUN: llc -verify-machineinstrs -mcpu=pwr7 -mtriple powerpc64-ibm-aix-xcoff < %s 2>&1 | FileCheck --check-prefixes CHECK,CHECK64 %s +; RUN: llc -verify-machineinstrs -mcpu=pwr7 -mtriple powerpc-ibm-aix-xcoff -filetype=obj -o %t.o < %s +; RUN: llvm-readobj --syms %t.o | FileCheck --check-prefix=SYM %s + +; RUN: not llc -verify-machineinstrs -mcpu=pwr7 -mtriple powerpc64-ibm-aix-xcoff -filetype=obj -o %t.o 2>&1 \ +; RUN: < %s | FileCheck --check-prefix=XCOFF64 %s +; XCOFF64: LLVM ERROR: 64-bit XCOFF object files are not supported yet. + @a = external global i32, align 4 @b = external global i64, align 8 @c = external global i16, align 2 @@ -46,3 +53,162 @@ ; CHECK-NEXT: LC6: ; CHECK-NEXT: .tc foo[TC],foo[DS] +; SYM: File: {{.*}}aix-xcoff-toc.ll.tmp.o +; SYM: Symbol {{[{][[:space:]] *}}Index: [[#INDX:]]{{[[:space:]] *}}Name: TOC +; SYM-NEXT: Value (RelocatableAddress): 0x54 +; SYM-NEXT: Section: .data +; SYM-NEXT: Type: 0x0 +; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM-NEXT: NumberOfAuxEntries: 1 +; SYM-NEXT: CSECT Auxiliary Entry { +; SYM-NEXT: Index: [[#INDX+1]] +; SYM-NEXT: SectionLen: 0 +; SYM-NEXT: ParameterHashIndex: 0x0 +; SYM-NEXT: TypeChkSectNum: 0x0 +; SYM-NEXT: SymbolAlignmentLog2: 2 +; SYM-NEXT: SymbolType: XTY_SD (0x1) +; SYM-NEXT: StorageMappingClass: XMC_TC0 (0xF) +; SYM-NEXT: StabInfoIndex: 0x0 +; SYM-NEXT: StabSectNum: 0x0 +; SYM-NEXT: } +; SYM-NEXT: } +; SYM-NEXT: Symbol { +; SYM-NEXT: Index: [[#INDX+2]] +; SYM-NEXT: Name: a +; SYM-NEXT: Value (RelocatableAddress): 0x54 +; SYM-NEXT: Section: .data +; SYM-NEXT: Type: 0x0 +; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM-NEXT: NumberOfAuxEntries: 1 +; SYM-NEXT: CSECT Auxiliary Entry { +; SYM-NEXT: Index: [[#INDX+3]] +; SYM-NEXT: SectionLen: 4 +; SYM-NEXT: ParameterHashIndex: 0x0 +; SYM-NEXT: TypeChkSectNum: 0x0 +; SYM-NEXT: SymbolAlignmentLog2: 2 +; SYM-NEXT: SymbolType: XTY_SD (0x1) +; SYM-NEXT: StorageMappingClass: XMC_TC (0x3) +; SYM-NEXT: StabInfoIndex: 0x0 +; SYM-NEXT: StabSectNum: 0x0 +; SYM-NEXT: } +; SYM-NEXT: } +; SYM-NEXT: Symbol { +; SYM-NEXT: Index: [[#INDX+4]] +; SYM-NEXT: Name: b +; SYM-NEXT: Value (RelocatableAddress): 0x58 +; SYM-NEXT: Section: .data +; SYM-NEXT: Type: 0x0 +; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM-NEXT: NumberOfAuxEntries: 1 +; SYM-NEXT: CSECT Auxiliary Entry { +; SYM-NEXT: Index: [[#INDX+5]] +; SYM-NEXT: SectionLen: 4 +; SYM-NEXT: ParameterHashIndex: 0x0 +; SYM-NEXT: TypeChkSectNum: 0x0 +; SYM-NEXT: SymbolAlignmentLog2: 2 +; SYM-NEXT: SymbolType: XTY_SD (0x1) +; SYM-NEXT: StorageMappingClass: XMC_TC (0x3) +; SYM-NEXT: StabInfoIndex: 0x0 +; SYM-NEXT: StabSectNum: 0x0 +; SYM-NEXT: } +; SYM-NEXT: } +; SYM-NEXT: Symbol { +; SYM-NEXT: Index: [[#INDX+6]] +; SYM-NEXT: Name: c +; SYM-NEXT: Value (RelocatableAddress): 0x5C +; SYM-NEXT: Section: .data +; SYM-NEXT: Type: 0x0 +; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM-NEXT: NumberOfAuxEntries: 1 +; SYM-NEXT: CSECT Auxiliary Entry { +; SYM-NEXT: Index: [[#INDX+7]] +; SYM-NEXT: SectionLen: 4 +; SYM-NEXT: ParameterHashIndex: 0x0 +; SYM-NEXT: TypeChkSectNum: 0x0 +; SYM-NEXT: SymbolAlignmentLog2: 2 +; SYM-NEXT: SymbolType: XTY_SD (0x1) +; SYM-NEXT: StorageMappingClass: XMC_TC (0x3) +; SYM-NEXT: StabInfoIndex: 0x0 +; SYM-NEXT: StabSectNum: 0x0 +; SYM-NEXT: } +; SYM-NEXT: } +; SYM-NEXT: Symbol { +; SYM-NEXT: Index: [[#INDX+8]] +; SYM-NEXT: Name: globa +; SYM-NEXT: Value (RelocatableAddress): 0x60 +; SYM-NEXT: Section: .data +; SYM-NEXT: Type: 0x0 +; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM-NEXT: NumberOfAuxEntries: 1 +; SYM-NEXT: CSECT Auxiliary Entry { +; SYM-NEXT: Index: [[#INDX+9]] +; SYM-NEXT: SectionLen: 4 +; SYM-NEXT: ParameterHashIndex: 0x0 +; SYM-NEXT: TypeChkSectNum: 0x0 +; SYM-NEXT: SymbolAlignmentLog2: 2 +; SYM-NEXT: SymbolType: XTY_SD (0x1) +; SYM-NEXT: StorageMappingClass: XMC_TC (0x3) +; SYM-NEXT: StabInfoIndex: 0x0 +; SYM-NEXT: StabSectNum: 0x0 +; SYM-NEXT: } +; SYM-NEXT: } +; SYM-NEXT: Symbol { +; SYM-NEXT: Index: [[#INDX+10]] +; SYM-NEXT: Name: ptr +; SYM-NEXT: Value (RelocatableAddress): 0x64 +; SYM-NEXT: Section: .data +; SYM-NEXT: Type: 0x0 +; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM-NEXT: NumberOfAuxEntries: 1 +; SYM-NEXT: CSECT Auxiliary Entry { +; SYM-NEXT: Index: [[#INDX+11]] +; SYM-NEXT: SectionLen: 4 +; SYM-NEXT: ParameterHashIndex: 0x0 +; SYM-NEXT: TypeChkSectNum: 0x0 +; SYM-NEXT: SymbolAlignmentLog2: 2 +; SYM-NEXT: SymbolType: XTY_SD (0x1) +; SYM-NEXT: StorageMappingClass: XMC_TC (0x3) +; SYM-NEXT: StabInfoIndex: 0x0 +; SYM-NEXT: StabSectNum: 0x0 +; SYM-NEXT: } +; SYM-NEXT: } +; SYM-NEXT: Symbol { +; SYM-NEXT: Index: [[#INDX+12]] +; SYM-NEXT: Name: bar +; SYM-NEXT: Value (RelocatableAddress): 0x68 +; SYM-NEXT: Section: .data +; SYM-NEXT: Type: 0x0 +; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM-NEXT: NumberOfAuxEntries: 1 +; SYM-NEXT: CSECT Auxiliary Entry { +; SYM-NEXT: Index: [[#INDX+13]] +; SYM-NEXT: SectionLen: 4 +; SYM-NEXT: ParameterHashIndex: 0x0 +; SYM-NEXT: TypeChkSectNum: 0x0 +; SYM-NEXT: SymbolAlignmentLog2: 2 +; SYM-NEXT: SymbolType: XTY_SD (0x1) +; SYM-NEXT: StorageMappingClass: XMC_TC (0x3) +; SYM-NEXT: StabInfoIndex: 0x0 +; SYM-NEXT: StabSectNum: 0x0 +; SYM-NEXT: } +; SYM-NEXT: } +; SYM-NEXT: Symbol { +; SYM-NEXT: Index: [[#INDX+14]] +; SYM-NEXT: Name: foo +; SYM-NEXT: Value (RelocatableAddress): 0x6C +; SYM-NEXT: Section: .data +; SYM-NEXT: Type: 0x0 +; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM-NEXT: NumberOfAuxEntries: 1 +; SYM-NEXT: CSECT Auxiliary Entry { +; SYM-NEXT: Index: [[#INDX+15]] +; SYM-NEXT: SectionLen: 4 +; SYM-NEXT: ParameterHashIndex: 0x0 +; SYM-NEXT: TypeChkSectNum: 0x0 +; SYM-NEXT: SymbolAlignmentLog2: 2 +; SYM-NEXT: SymbolType: XTY_SD (0x1) +; SYM-NEXT: StorageMappingClass: XMC_TC (0x3) +; SYM-NEXT: StabInfoIndex: 0x0 +; SYM-NEXT: StabSectNum: 0x0 +; SYM-NEXT: } +; SYM-NEXT: }