diff --git a/llvm/include/llvm/ProfileData/ProfileCommon.h b/llvm/include/llvm/ProfileData/ProfileCommon.h --- a/llvm/include/llvm/ProfileData/ProfileCommon.h +++ b/llvm/include/llvm/ProfileData/ProfileCommon.h @@ -33,8 +33,8 @@ } // end namespace sampleprof -inline const char *getHotSectionPrefix() { return ".hot"; } -inline const char *getUnlikelySectionPrefix() { return ".unlikely"; } +inline const char *getHotSectionPrefix() { return "hot"; } +inline const char *getUnlikelySectionPrefix() { return "unlikely"; } class ProfileSummaryBuilder { private: diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -473,12 +473,12 @@ OptSize = F.hasOptSize(); if (ProfileGuidedSectionPrefix) { if (PSI->isFunctionHotInCallGraph(&F, *BFI)) - F.setSectionPrefix(".hot"); + F.setSectionPrefix("hot"); else if (PSI->isFunctionColdInCallGraph(&F, *BFI)) - F.setSectionPrefix(".unlikely"); + F.setSectionPrefix("unlikely"); else if (ProfileUnknownInSpecialSection && PSI->hasPartialSampleProfile() && PSI->isFunctionHotnessUnknown(F)) - F.setSectionPrefix(".unknown"); + F.setSectionPrefix("unknown"); } /// This optimization identifies DIV instructions that can be diff --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp --- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp +++ b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp @@ -107,8 +107,8 @@ // or functions of unknown hotness. Lukewarm functions have no prefix. Optional SectionPrefix = MF.getFunction().getSectionPrefix(); if (SectionPrefix.hasValue() && - (SectionPrefix.getValue().equals(".unlikely") || - SectionPrefix.getValue().equals(".unknown"))) { + (SectionPrefix.getValue().equals("unlikely") || + SectionPrefix.getValue().equals("unknown"))) { return false; } 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 @@ -621,7 +621,7 @@ bool HasPrefix = false; if (const auto *F = dyn_cast(GO)) { if (Optional Prefix = F->getSectionPrefix()) { - Name += *Prefix; + raw_svector_ostream(Name) << '.' << *Prefix; HasPrefix = true; } } @@ -1573,6 +1573,10 @@ MCSymbol *Sym = TM.getSymbol(ComdatGV); StringRef COMDATSymName = Sym->getName(); + if (const auto *F = dyn_cast(GO)) + if (Optional Prefix = F->getSectionPrefix()) + raw_svector_ostream(Name) << '$' << *Prefix; + // Append "$symbol" to the section name *before* IR-level mangling is // applied when targetting mingw. This is what GCC does, and the ld.bfd // COFF linker will not properly handle comdats otherwise. @@ -2020,7 +2024,7 @@ if (const auto *F = dyn_cast(GO)) { const auto &OptionalPrefix = F->getSectionPrefix(); if (OptionalPrefix) - Name += *OptionalPrefix; + raw_svector_ostream(Name) << '.' << *OptionalPrefix; } if (EmitUniqueSection && UniqueSectionNames) { diff --git a/llvm/test/CodeGen/X86/text-section-prefix.ll b/llvm/test/CodeGen/X86/text-section-prefix.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/text-section-prefix.ll @@ -0,0 +1,13 @@ +; RUN: llc -function-sections < %s + +define void @foo0(i1 zeroext %0) nounwind !section_prefix !0 { + ret void +} + +define void @foo1(i1 zeroext %0) nounwind !section_prefix !1 { + ret void +} + +!0 = !{!"function_section_prefix", !"hot"} +!1 = !{!"function_section_prefix", !"unlikely"} +