diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -661,7 +661,7 @@ /// This emits linkage information about \p GVSym based on \p GV, if this is /// supported by the target. - void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const; + virtual void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const; /// Return the alignment for the specified \p GV. static Align getGVAlignment(const GlobalValue *GV, const DataLayout &DL, 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,8 @@ static XCOFF::StorageClass getStorageClassForGlobal(const GlobalObject *GO); - MCSection *getSectionForFunctionDescriptor(const MCSymbol *) const override; + MCSection *getSectionForFunctionDescriptor(const GlobalObject *GO, + const MCSymbol *) 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,8 @@ /// 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 GlobalObject *GO, + const MCSymbol *S) const { return nullptr; } 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,10 @@ } MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor( - const MCSymbol *FuncSym) const { - return getContext().getXCOFFSection(FuncSym->getName(), XCOFF::XMC_DS, - XCOFF::XTY_SD, XCOFF::C_HIDEXT, - SectionKind::getData()); + const GlobalObject *GO, const MCSymbol *FuncSym) const { + return getContext().getXCOFFSection( + FuncSym->getName(), XCOFF::XMC_DS, XCOFF::XTY_SD, + getStorageClassForGlobal(GO), 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 @@ -168,6 +168,8 @@ void emitFunctionDescriptor() override; void emitEndOfAsmFile(Module &) override; + + void emitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const override; }; } // end anonymous namespace @@ -1539,12 +1541,29 @@ } } +void PPCAIXAsmPrinter::emitLinkage(const GlobalValue *GV, + MCSymbol *GVSym) const { + + MCSymbolXCOFF *XCOFFSym = cast(GVSym); + + if (XCOFFSym->hasContainingCsect()) { + MCSymbolXCOFF *QualName = + XCOFFSym->getContainingCsect()->getQualNameSymbol(); + if (GVSym->getName() == QualName->getUnqualifiedName() && + XCOFFSym->getContainingCsect()->getMappingClass() != XCOFF::XMC_PR) + GVSym = QualName; + } + + AsmPrinter::emitLinkage(GV, GVSym); +} + 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)); + MCSectionXCOFF *FnDescSec = + cast(getObjFileLowering().getSectionForFunctionDescriptor( + &MF.getFunction(), CurrentFnDescSym)); FnDescSec->setAlignment(Align(Subtarget->isPPC64() ? 8 : 4)); cast(CurrentFnDescSym)->setContainingCsect(FnDescSec); @@ -1570,7 +1589,7 @@ MCSectionXCOFF *Csect = cast( F->isDeclaration() ? getObjFileLowering().getSectionForExternalReference(F, TM) - : getObjFileLowering().getSectionForFunctionDescriptor(FSym)); + : getObjFileLowering().getSectionForFunctionDescriptor(F, FSym)); FSym->setContainingCsect(Csect); } return MCSymbolRefExpr::create( @@ -1654,7 +1673,6 @@ // Emit function descriptor. OutStreamer->SwitchSection( cast(CurrentFnDescSym)->getContainingCsect()); - OutStreamer->emitLabel(CurrentFnDescSym); // Emit function entry point address. OutStreamer->emitValue(MCSymbolRefExpr::create(CurrentFnSym, OutContext), PointerSize); @@ -1740,7 +1758,7 @@ // 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(GO, XSym)) ->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 @@ -30,7 +30,6 @@ ; CHECK: .globl foo ; CHECK: .globl .foo ; CHECK: .csect foo[DS] -; CHECK-NEXT: foo: ; 32BIT: .long .foo ; 32BIT-NEXT: .long TOC[TC0] ; 32BIT-NEXT: .long 0 @@ -43,7 +42,6 @@ ; CHECK: .globl main ; 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