From 77618cc237a9b2923b032a7f669f35148cb95c0a Mon Sep 17 00:00:00 2001 From: jasonliu Date: Thu, 16 Apr 2020 19:52:34 +0000 Subject: [XCOFF][AIX] Fix getSymbol to return the correct qualname when necessary Summary: AIX symbol have qualname and unqualified name. The stock getSymbol could only return unqualified name, which leads us to patch many caller side(lowerConstant, getMCSymbolForTOCPseudoMO). So we should try to address this problem in the callee side(getSymbol) and clean up the caller side instead. Note: this is a "mostly" NFC patch, with a fix for the original lowerConstant behavior. Differential Revision: https://reviews.llvm.org/D78045 --- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp') diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index a5f380168c10..8ed3e8673a84 100644 --- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -1966,6 +1966,40 @@ MCSection *TargetLoweringObjectFileWasm::getStaticDtorSection( //===----------------------------------------------------------------------===// // XCOFF //===----------------------------------------------------------------------===// +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. + // 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 + // here. + if (const GlobalObject *GO = dyn_cast(GV)) { + if (GO->isDeclaration()) + return cast(getSectionForExternalReference(GO, TM)) + ->getQualNameSymbol(); + + SectionKind GOKind = getKindForGlobal(GO, TM); + if (GOKind.isText()) + return cast( + getSectionForFunctionDescriptor(cast(GO), TM)) + ->getQualNameSymbol(); + if (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; +} + MCSection *TargetLoweringObjectFileXCOFF::getExplicitSectionGlobal( const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const { report_fatal_error("XCOFF explicit sections not yet implemented."); -- cgit v1.2.3