diff --git a/llvm/include/llvm/MC/MCObjectFileInfo.h b/llvm/include/llvm/MC/MCObjectFileInfo.h --- a/llvm/include/llvm/MC/MCObjectFileInfo.h +++ b/llvm/include/llvm/MC/MCObjectFileInfo.h @@ -363,6 +363,8 @@ MCSection *getPseudoProbeDescSection(StringRef FuncName) const; + MCSection *getPCSection(StringRef Name, const MCSection *TextSec) const; + // ELF specific sections. MCSection *getDataRelROSection() const { return DataRelROSection; } const MCSection *getMergeableConst4Section() const { diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp --- a/llvm/lib/MC/MCObjectFileInfo.cpp +++ b/llvm/lib/MC/MCObjectFileInfo.cpp @@ -1179,3 +1179,25 @@ } return PseudoProbeDescSection; } + +MCSection *MCObjectFileInfo::getPCSection(StringRef Name, + const MCSection *TextSec) const { + if (Ctx->getObjectFileType() != MCContext::IsELF) + return nullptr; + + // SHF_WRITE for relocations, and let user post-process data in-place. + unsigned Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER; + + if (!TextSec) + TextSec = getTextSection(); + + StringRef GroupName; + const auto &ElfSec = static_cast(*TextSec); + if (const MCSymbol *Group = ElfSec.getGroup()) { + GroupName = Group->getName(); + Flags |= ELF::SHF_GROUP; + } + return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true, + ElfSec.getUniqueID(), + cast(TextSec->getBeginSymbol())); +}