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 @@ -262,6 +262,9 @@ /// For functions, this will always return a function descriptor symbol. MCSymbol *getTargetSymbol(const GlobalValue *GV, const TargetMachine &TM) const override; + + MCSymbol *getFunctionEntryPointSymbol(const Function *F, + const TargetMachine &TM) const override; }; } // end namespace llvm 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 @@ -245,6 +245,13 @@ return nullptr; } + /// If supported, return the function entry point symbol. + /// Otherwise, returns nulltpr. + virtual MCSymbol *getFunctionEntryPointSymbol(const Function *F, + const TargetMachine &TM) const { + return nullptr; + } + protected: virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, 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 @@ -1503,6 +1503,8 @@ // Emit remaining GOT equivalent globals. emitGlobalGOTEquivs(); + const TargetLoweringObjectFile &TLOF = getObjFileLowering(); + // Emit linkage(XCOFF) and visibility info for declarations for (const Function &F : M) { if (!F.isDeclarationForLinker()) @@ -1513,8 +1515,7 @@ if (TM.getTargetTriple().isOSBinFormatXCOFF() && !F.isIntrinsic()) { // Get the function entry point symbol. - MCSymbol *FnEntryPointSym = OutContext.getOrCreateSymbol( - "." + cast(Name)->getUnqualifiedName()); + MCSymbol *FnEntryPointSym = TLOF.getFunctionEntryPointSymbol(&F, TM); if (cast(FnEntryPointSym)->hasRepresentedCsectSet()) // Emit linkage for the function entry point. emitLinkage(&F, FnEntryPointSym); @@ -1536,8 +1537,6 @@ if (remarks::RemarkStreamer *RS = M.getContext().getMainRemarkStreamer()) emitRemarksSection(*RS); - const TargetLoweringObjectFile &TLOF = getObjFileLowering(); - TLOF.emitModuleMetadata(*OutStreamer, M); if (TM.getTargetTriple().isOSBinFormatELF()) { @@ -1786,8 +1785,7 @@ " initalized first."); // Get the function entry point symbol. - CurrentFnSym = OutContext.getOrCreateSymbol( - "." + cast(CurrentFnDescSym)->getUnqualifiedName()); + CurrentFnSym = getObjFileLowering().getFunctionEntryPointSymbol(&F, TM); } CurrentFnSymForSize = CurrentFnSym; 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 @@ -2150,6 +2150,14 @@ llvm_unreachable("Unknown linkage type!"); } +MCSymbol *TargetLoweringObjectFileXCOFF::getFunctionEntryPointSymbol( + const Function *F, const TargetMachine &TM) const { + SmallString<128> NameStr; + NameStr.push_back('.'); + getNameWithPrefix(NameStr, F, TM); + return getContext().getOrCreateSymbol(NameStr); +} + MCSection *TargetLoweringObjectFileXCOFF::getSectionForFunctionDescriptor( const Function *F, const TargetMachine &TM) const { SmallString<128> NameStr;