diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h --- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -244,7 +244,7 @@ static XCOFF::StorageClass getStorageClassForGlobal(const GlobalObject *GO); - MCSection *getSectionForFunctionDescriptor(const MCSymbol *) const override; + MCSection *getSectionForFunctionDescriptor(const Function *F) const override; MCSection *getSectionForTOCEntry(const MCSymbol *Sym) const override; /// For external functions, this will always return a function descriptor diff --git a/llvm/include/llvm/Target/TargetLoweringObjectFile.h b/llvm/include/llvm/Target/TargetLoweringObjectFile.h --- a/llvm/include/llvm/Target/TargetLoweringObjectFile.h +++ b/llvm/include/llvm/Target/TargetLoweringObjectFile.h @@ -214,7 +214,7 @@ /// On targets that use separate function descriptor symbols, return a section /// for the descriptor given its symbol. Use only with defined functions. - virtual MCSection *getSectionForFunctionDescriptor(const MCSymbol *S) const { + virtual MCSection *getSectionForFunctionDescriptor(const Function *F) const { return nullptr; } diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1718,8 +1718,8 @@ " initalized first."); // Get the function entry point symbol. - CurrentFnSym = - OutContext.getOrCreateSymbol("." + CurrentFnDescSym->getName()); + CurrentFnSym = OutContext.getOrCreateSymbol( + "." + cast(CurrentFnDescSym)->getUnqualifiedName()); // Set the containing csect. MCSectionXCOFF *FnEntryPointSec = diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1969,10 +1969,12 @@ } MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor( - const MCSymbol *FuncSym) const { - return getContext().getXCOFFSection(FuncSym->getName(), XCOFF::XMC_DS, - XCOFF::XTY_SD, XCOFF::C_HIDEXT, - SectionKind::getData()); + const Function *F) const { + SmallString<128> NameStr; + getMangler().getNameWithPrefix(NameStr, F, /*CannotUsePrivateLabel=*/false); + return getContext().getXCOFFSection( + NameStr.str(), XCOFF::XMC_DS, XCOFF::XTY_SD, getStorageClassForGlobal(F), + SectionKind::getData()); } MCSection *TargetLoweringObjectFileXCOFF::getSectionForTOCEntry( diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1540,11 +1540,10 @@ } void PPCAIXAsmPrinter::SetupMachineFunction(MachineFunction &MF) { - // Get the function descriptor symbol. - CurrentFnDescSym = getSymbol(&MF.getFunction()); // Set the alignment and the containing csect. MCSectionXCOFF *FnDescSec = cast( - getObjFileLowering().getSectionForFunctionDescriptor(CurrentFnDescSym)); + getObjFileLowering().getSectionForFunctionDescriptor(&MF.getFunction())); + CurrentFnDescSym = FnDescSec->getQualNameSymbol(); FnDescSec->setAlignment(Align(Subtarget->isPPC64() ? 8 : 4)); cast(CurrentFnDescSym)->setContainingCsect(FnDescSec); @@ -1570,7 +1569,7 @@ MCSectionXCOFF *Csect = cast( F->isDeclaration() ? getObjFileLowering().getSectionForExternalReference(F, TM) - : getObjFileLowering().getSectionForFunctionDescriptor(FSym)); + : getObjFileLowering().getSectionForFunctionDescriptor(F)); FSym->setContainingCsect(Csect); } return MCSymbolRefExpr::create( @@ -1654,7 +1653,6 @@ // Emit function descriptor. OutStreamer->SwitchSection( cast(CurrentFnDescSym)->getContainingCsect()); - OutStreamer->emitLabel(CurrentFnDescSym); // Emit function entry point address. OutStreamer->emitValue(MCSymbolRefExpr::create(CurrentFnSym, OutContext), PointerSize); @@ -1721,8 +1719,6 @@ ValidateGV(GV); } - MCSymbolXCOFF *XSym = cast(getSymbol(GO)); - // If the global object is a global variable without initializer or is a // declaration of a function, then XSym is an external referenced symbol. // Hence we may need to explictly create a MCSectionXCOFF for it so that we @@ -1740,7 +1736,8 @@ // If the MO is a function, we want to make sure to refer to the function // descriptor csect. return cast( - getObjFileLowering().getSectionForFunctionDescriptor(XSym)) + getObjFileLowering().getSectionForFunctionDescriptor( + dyn_cast(GO))) ->getQualNameSymbol(); } else if (GOKind.isCommon() || GOKind.isBSSLocal()) { // If the operand is a common then we should refer to the csect symbol. diff --git a/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll b/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll --- a/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll +++ b/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll @@ -56,7 +56,7 @@ ; CHECK-NEXT: Value (RelocatableAddress): 0x4 ; CHECK-NEXT: Section: .data ; CHECK-NEXT: Type: 0x0 -; CHECK-NEXT: StorageClass: C_HIDEXT (0x6B) +; CHECK-NEXT: StorageClass: C_EXT (0x2) ; CHECK-NEXT: NumberOfAuxEntries: 1 ; CHECK-NEXT: CSECT Auxiliary Entry { ; CHECK-NEXT: Index: [[#Index+5]] @@ -72,26 +72,6 @@ ; CHECK-NEXT: } ; CHECK-NEXT: Symbol { ; CHECK-NEXT: Index: [[#Index+6]] -; CHECK-NEXT: Name: foo -; CHECK-NEXT: Value (RelocatableAddress): 0x4 -; CHECK-NEXT: Section: .data -; CHECK-NEXT: Type: 0x0 -; CHECK-NEXT: StorageClass: C_EXT (0x2) -; CHECK-NEXT: NumberOfAuxEntries: 1 -; CHECK-NEXT: CSECT Auxiliary Entry { -; CHECK-NEXT: Index: [[#Index+7]] -; CHECK-NEXT: ContainingCsectSymbolIndex: [[#Index+4]] -; CHECK-NEXT: ParameterHashIndex: 0x0 -; CHECK-NEXT: TypeChkSectNum: 0x0 -; CHECK-NEXT: SymbolAlignmentLog2: 0 -; CHECK-NEXT: SymbolType: XTY_LD (0x2) -; CHECK-NEXT: StorageMappingClass: XMC_DS (0xA) -; CHECK-NEXT: StabInfoIndex: 0x0 -; CHECK-NEXT: StabSectNum: 0x0 -; CHECK-NEXT: } -; CHECK-NEXT: } -; CHECK-NEXT: Symbol { -; CHECK-NEXT: Index: [[#Index+8]] ; CHECK-NEXT: Name: TOC ; CHECK-NEXT: Value (RelocatableAddress): 0x10 ; CHECK-NEXT: Section: .data @@ -99,7 +79,7 @@ ; CHECK-NEXT: StorageClass: C_HIDEXT (0x6B) ; CHECK-NEXT: NumberOfAuxEntries: 1 ; CHECK-NEXT: CSECT Auxiliary Entry { -; CHECK-NEXT: Index: [[#Index+9]] +; CHECK-NEXT: Index: [[#Index+7]] ; CHECK-NEXT: SectionLen: 0 ; CHECK-NEXT: ParameterHashIndex: 0x0 ; CHECK-NEXT: TypeChkSectNum: 0x0 diff --git a/llvm/test/CodeGen/PowerPC/aix-user-defined-memcpy.ll b/llvm/test/CodeGen/PowerPC/aix-user-defined-memcpy.ll --- a/llvm/test/CodeGen/PowerPC/aix-user-defined-memcpy.ll +++ b/llvm/test/CodeGen/PowerPC/aix-user-defined-memcpy.ll @@ -68,7 +68,7 @@ ; 32-REL-NEXT: } ; 32-REL-NEXT: Relocation { ; 32-REL-NEXT: Virtual Address: 0x38 -; 32-REL-NEXT: Symbol: TOC (14) +; 32-REL-NEXT: Symbol: TOC (10) ; 32-REL-NEXT: IsSigned: No ; 32-REL-NEXT: FixupBitValue: 0 ; 32-REL-NEXT: Length: 32 @@ -84,7 +84,7 @@ ; 32-REL-NEXT: } ; 32-REL-NEXT: Relocation { ; 32-REL-NEXT: Virtual Address: 0x44 -; 32-REL-NEXT: Symbol: TOC (14) +; 32-REL-NEXT: Symbol: TOC (10) ; 32-REL-NEXT: IsSigned: No ; 32-REL-NEXT: FixupBitValue: 0 ; 32-REL-NEXT: Length: 32 diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll --- a/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll +++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll @@ -35,7 +35,7 @@ ; OBJ-NEXT: NumberOfSections: 2 ; OBJ-NEXT: TimeStamp: None (0x0) ; OBJ-NEXT: SymbolTableOffset: 0x13C -; OBJ-NEXT: SymbolTableEntries: 26 +; OBJ-NEXT: SymbolTableEntries: 24 ; OBJ-NEXT: OptionalHeaderSize: 0x0 ; OBJ-NEXT: Flags: 0x0 ; OBJ-NEXT: } @@ -85,7 +85,7 @@ ; RELOC-NEXT: } ; RELOC-NEXT: Relocation { ; RELOC-NEXT: Virtual Address: 0x1A -; RELOC-NEXT: Symbol: globalA (22) +; RELOC-NEXT: Symbol: globalA (20) ; RELOC-NEXT: IsSigned: No ; RELOC-NEXT: FixupBitValue: 0 ; RELOC-NEXT: Length: 16 @@ -93,7 +93,7 @@ ; RELOC-NEXT: } ; RELOC-NEXT: Relocation { ; RELOC-NEXT: Virtual Address: 0x1E -; RELOC-NEXT: Symbol: globalB (24) +; RELOC-NEXT: Symbol: globalB (22) ; RELOC-NEXT: IsSigned: No ; RELOC-NEXT: FixupBitValue: 0 ; RELOC-NEXT: Length: 16 @@ -119,7 +119,7 @@ ; RELOC-NEXT: } ; RELOC-NEXT: Relocation { ; RELOC-NEXT: Virtual Address: 0x78 -; RELOC-NEXT: Symbol: TOC (20) +; RELOC-NEXT: Symbol: TOC (18) ; RELOC-NEXT: IsSigned: No ; RELOC-NEXT: FixupBitValue: 0 ; RELOC-NEXT: Length: 32 @@ -311,7 +311,7 @@ ; SYM-NEXT: Value (RelocatableAddress): 0x74 ; SYM-NEXT: Section: .data ; SYM-NEXT: Type: 0x0 -; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) +; SYM-NEXT: StorageClass: C_EXT (0x2) ; SYM-NEXT: NumberOfAuxEntries: 1 ; SYM-NEXT: CSECT Auxiliary Entry { ; SYM-NEXT: Index: 17 @@ -327,26 +327,6 @@ ; SYM-NEXT: } ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: 18 -; SYM-NEXT: Name: foo -; SYM-NEXT: Value (RelocatableAddress): 0x74 -; SYM-NEXT: Section: .data -; SYM-NEXT: Type: 0x0 -; SYM-NEXT: StorageClass: C_EXT (0x2) -; SYM-NEXT: NumberOfAuxEntries: 1 -; SYM-NEXT: CSECT Auxiliary Entry { -; SYM-NEXT: Index: 19 -; SYM-NEXT: ContainingCsectSymbolIndex: 16 -; SYM-NEXT: ParameterHashIndex: 0x0 -; SYM-NEXT: TypeChkSectNum: 0x0 -; SYM-NEXT: SymbolAlignmentLog2: 0 -; SYM-NEXT: SymbolType: XTY_LD (0x2) -; SYM-NEXT: StorageMappingClass: XMC_DS (0xA) -; SYM-NEXT: StabInfoIndex: 0x0 -; SYM-NEXT: StabSectNum: 0x0 -; SYM-NEXT: } -; SYM-NEXT: } -; SYM-NEXT: Symbol { -; SYM-NEXT: Index: 20 ; SYM-NEXT: Name: TOC ; SYM-NEXT: Value (RelocatableAddress): 0x80 ; SYM-NEXT: Section: .data @@ -354,7 +334,7 @@ ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) ; SYM-NEXT: NumberOfAuxEntries: 1 ; SYM-NEXT: CSECT Auxiliary Entry { -; SYM-NEXT: Index: 21 +; SYM-NEXT: Index: 19 ; SYM-NEXT: SectionLen: 0 ; SYM-NEXT: ParameterHashIndex: 0x0 ; SYM-NEXT: TypeChkSectNum: 0x0 @@ -366,7 +346,7 @@ ; SYM-NEXT: } ; SYM-NEXT: } ; SYM-NEXT: Symbol { -; SYM-NEXT: Index: 22 +; SYM-NEXT: Index: 20 ; SYM-NEXT: Name: globalA ; SYM-NEXT: Value (RelocatableAddress): 0x80 ; SYM-NEXT: Section: .data @@ -374,7 +354,7 @@ ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) ; SYM-NEXT: NumberOfAuxEntries: 1 ; SYM-NEXT: CSECT Auxiliary Entry { -; SYM-NEXT: Index: 23 +; SYM-NEXT: Index: 21 ; SYM-NEXT: SectionLen: 4 ; SYM-NEXT: ParameterHashIndex: 0x0 ; SYM-NEXT: TypeChkSectNum: 0x0 @@ -386,7 +366,7 @@ ; SYM-NEXT: } ; SYM-NEXT: } ; SYM-NEXT: Symbol { -; SYM-NEXT: Index: 24 +; SYM-NEXT: Index: 22 ; SYM-NEXT: Name: globalB ; SYM-NEXT: Value (RelocatableAddress): 0x84 ; SYM-NEXT: Section: .data @@ -394,7 +374,7 @@ ; SYM-NEXT: StorageClass: C_HIDEXT (0x6B) ; SYM-NEXT: NumberOfAuxEntries: 1 ; SYM-NEXT: CSECT Auxiliary Entry { -; SYM-NEXT: Index: 25 +; SYM-NEXT: Index: 23 ; SYM-NEXT: SectionLen: 4 ; SYM-NEXT: ParameterHashIndex: 0x0 ; SYM-NEXT: TypeChkSectNum: 0x0 diff --git a/llvm/test/CodeGen/PowerPC/test_func_desc.ll b/llvm/test/CodeGen/PowerPC/test_func_desc.ll --- a/llvm/test/CodeGen/PowerPC/test_func_desc.ll +++ b/llvm/test/CodeGen/PowerPC/test_func_desc.ll @@ -27,10 +27,9 @@ ret i32 3 } -; CHECK: .globl foo +; CHECK: .globl foo[DS] ; CHECK: .globl .foo ; CHECK: .csect foo[DS] -; CHECK-NEXT: foo: ; 32BIT: .long .foo ; 32BIT-NEXT: .long TOC[TC0] ; 32BIT-NEXT: .long 0 @@ -40,10 +39,9 @@ ; CHECK-NEXT: .csect .text[PR] ; CHECK-LABEL: .foo: -; CHECK: .globl main +; CHECK: .globl main[DS] ; CHECK: .globl .main ; CHECK: .csect main[DS] -; CHECK-NEXT: main: ; 32BIT: .long .main ; 32BIT-NEXT: .long TOC[TC0] ; 32BIT-NEXT: .long 0 @@ -58,7 +56,6 @@ ; CHECK: .lglobl .static_foo ; CHECK: .csect static_foo[DS] -; CHECK-NEXT: static_foo: ; 32BIT: .long .static_foo ; 32BIT-NEXT: .long TOC[TC0] ; 32BIT-NEXT: .long 0