1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[AIX] discard the label in the csect of function description and use qualname for linkage

SUMMARY:

SUMMARY
for a source file  "test.c"

void foo() {};

llc will generate assembly code as (assembly patch)
     .globl  foo
     .globl  .foo
     .csect foo[DS]
foo:

        .long   .foo
        .long   TOC[TC0]
        .long   0

   and symbol table as (xcoff object file)
   [4]     m   0x00000004     .data     1  unamex                    foo
   [5]     a4  0x0000000c       0    0     SD       DS    0    0
   [6]     m   0x00000004     .data     1  extern                    foo
   [7]     a4  0x00000004       0    0     LD       DS    0    0

   After first patch, the assembly will be as

        .globl  foo[DS]                 # -- Begin function foo
        .globl  .foo
        .align  2
        .csect foo[DS]
        .long   .foo
        .long   TOC[TC0]
        .long   0

    and symbol table will as
   [6]     m   0x00000004     .data     1  extern                    foo
   [7]     a4  0x00000004       0    0     DS      DS    0    0
Change the code for the assembly path and xcoff objectfile patch for llc.

Reviewers: Jason Liu
Subscribers: wuzish, nemanjai, hiraditya

Differential Revision: https://reviews.llvm.org/D76162
This commit is contained in:
diggerlin 2020-03-26 15:46:52 -04:00
parent 58a5965510
commit fd7184191d
9 changed files with 40 additions and 83 deletions

View File

@ -253,7 +253,9 @@ public:
static XCOFF::StorageClass getStorageClassForGlobal(const GlobalObject *GO);
MCSection *getSectionForFunctionDescriptor(const MCSymbol *) const override;
MCSection *
getSectionForFunctionDescriptor(const Function *F,
const TargetMachine &TM) const override;
MCSection *getSectionForTOCEntry(const MCSymbol *Sym) const override;
/// For external functions, this will always return a function descriptor

View File

@ -221,7 +221,9 @@ public:
/// 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 TargetMachine &TM) const {
return nullptr;
}

View File

@ -1747,8 +1747,8 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
" initalized first.");
// Get the function entry point symbol.
CurrentFnSym =
OutContext.getOrCreateSymbol("." + CurrentFnDescSym->getName());
CurrentFnSym = OutContext.getOrCreateSymbol(
"." + cast<MCSymbolXCOFF>(CurrentFnDescSym)->getUnqualifiedName());
// Set the containing csect.
MCSectionXCOFF *FnEntryPointSec =

View File

@ -2022,9 +2022,11 @@ XCOFF::StorageClass TargetLoweringObjectFileXCOFF::getStorageClassForGlobal(
}
MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor(
const MCSymbol *FuncSym) const {
return getContext().getXCOFFSection(FuncSym->getName(), XCOFF::XMC_DS,
XCOFF::XTY_SD, XCOFF::C_HIDEXT,
const Function *F, const TargetMachine &TM) const {
SmallString<128> NameStr;
getNameWithPrefix(NameStr, F, TM);
return getContext().getXCOFFSection(NameStr, XCOFF::XMC_DS, XCOFF::XTY_SD,
getStorageClassForGlobal(F),
SectionKind::getData());
}

View File

@ -1540,13 +1540,13 @@ void PPCLinuxAsmPrinter::emitFunctionBodyEnd() {
}
void PPCAIXAsmPrinter::SetupMachineFunction(MachineFunction &MF) {
// Get the function descriptor symbol.
CurrentFnDescSym = getSymbol(&MF.getFunction());
// Set the alignment and the containing csect.
MCSectionXCOFF *FnDescSec = cast<MCSectionXCOFF>(
getObjFileLowering().getSectionForFunctionDescriptor(CurrentFnDescSym));
// Setup CurrentFnDescSym and its containing csect.
MCSectionXCOFF *FnDescSec =
cast<MCSectionXCOFF>(getObjFileLowering().getSectionForFunctionDescriptor(
&MF.getFunction(), TM));
FnDescSec->setAlignment(Align(Subtarget->isPPC64() ? 8 : 4));
cast<MCSymbolXCOFF>(CurrentFnDescSym)->setContainingCsect(FnDescSec);
CurrentFnDescSym = FnDescSec->getQualNameSymbol();
return AsmPrinter::SetupMachineFunction(MF);
}
@ -1565,16 +1565,12 @@ void PPCAIXAsmPrinter::ValidateGV(const GlobalVariable *GV) {
const MCExpr *PPCAIXAsmPrinter::lowerConstant(const Constant *CV) {
if (const Function *F = dyn_cast<Function>(CV)) {
MCSymbolXCOFF *FSym = cast<MCSymbolXCOFF>(getSymbol(F));
if (!FSym->hasContainingCsect()) {
MCSectionXCOFF *Csect = cast<MCSectionXCOFF>(
F->isDeclaration()
? getObjFileLowering().getSectionForExternalReference(F, TM)
: getObjFileLowering().getSectionForFunctionDescriptor(FSym));
FSym->setContainingCsect(Csect);
}
return MCSymbolRefExpr::create(
FSym->getContainingCsect()->getQualNameSymbol(), OutContext);
: getObjFileLowering().getSectionForFunctionDescriptor(F, TM));
return MCSymbolRefExpr::create(Csect->getQualNameSymbol(), OutContext);
}
return PPCAsmPrinter::lowerConstant(CV);
}
@ -1654,7 +1650,6 @@ void PPCAIXAsmPrinter::emitFunctionDescriptor() {
// Emit function descriptor.
OutStreamer->SwitchSection(
cast<MCSymbolXCOFF>(CurrentFnDescSym)->getContainingCsect());
OutStreamer->emitLabel(CurrentFnDescSym);
// Emit function entry point address.
OutStreamer->emitValue(MCSymbolRefExpr::create(CurrentFnSym, OutContext),
PointerSize);
@ -1721,8 +1716,6 @@ PPCAIXAsmPrinter::getMCSymbolForTOCPseudoMO(const MachineOperand &MO) {
ValidateGV(GV);
}
MCSymbolXCOFF *XSym = cast<MCSymbolXCOFF>(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 +1733,8 @@ PPCAIXAsmPrinter::getMCSymbolForTOCPseudoMO(const MachineOperand &MO) {
// If the MO is a function, we want to make sure to refer to the function
// descriptor csect.
return cast<MCSectionXCOFF>(
getObjFileLowering().getSectionForFunctionDescriptor(XSym))
getObjFileLowering().getSectionForFunctionDescriptor(
cast<const Function>(GO), TM))
->getQualNameSymbol();
} else if (GOKind.isCommon() || GOKind.isBSSLocal()) {
// If the operand is a common then we should refer to the csect symbol.

View File

@ -56,7 +56,7 @@ entry:
; 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 @@ entry:
; 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 @@ entry:
; 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

View File

@ -68,7 +68,7 @@ declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture r
; 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 @@ declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture writeonly, i8* nocapture r
; 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

View File

@ -35,7 +35,7 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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 @@ declare i32 @bar(i32)
; 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

View File

@ -27,10 +27,9 @@ entry:
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 @@ entry:
; 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 @@ entry:
; 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