aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCObjectFileInfo.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2023-06-16 23:46:36 -0700
committerFangrui Song <i@maskray.me>2023-06-16 23:46:36 -0700
commit62d861422317b3e94a97706f07e8f1abce9a8135 (patch)
tree3cad175d8012b6f0acbadbb506d3d7a7179e9ebf /llvm/lib/MC/MCObjectFileInfo.cpp
parent01b512882d75c5fd64ca0e78f28acd3f0e2254d8 (diff)
downloadllvm-62d861422317b3e94a97706f07e8f1abce9a8135.zip
llvm-62d861422317b3e94a97706f07e8f1abce9a8135.tar.gz
llvm-62d861422317b3e94a97706f07e8f1abce9a8135.tar.bz2
[Pseudo Probe] Make .pseudo_probe GC-able
* Add the SHF_LINK_ORDER flag so that the .pseudo_probe section is discarded when the associated text section is discarded. * Add unique ID so that with `clang -ffunction-sections -fno-unique-section-names`, there is one separate .pseudo_probe for each text section (disambiguated by `.section ....,unique,id` in assembly) The changes allow .pseudo_probe GC even if we don't place instrumented functions in an IR comdat (see `getOrCreateFunctionComdat` in SampleProfileProbe.cpp). Reviewed By: hoy Differential Revision: https://reviews.llvm.org/D153189
Diffstat (limited to 'llvm/lib/MC/MCObjectFileInfo.cpp')
-rw-r--r--llvm/lib/MC/MCObjectFileInfo.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/llvm/lib/MC/MCObjectFileInfo.cpp b/llvm/lib/MC/MCObjectFileInfo.cpp
index c910bd8..d3b9fa45 100644
--- a/llvm/lib/MC/MCObjectFileInfo.cpp
+++ b/llvm/lib/MC/MCObjectFileInfo.cpp
@@ -1165,18 +1165,20 @@ MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const {
MCSection *
MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const {
- if (Ctx->getObjectFileType() == MCContext::IsELF) {
- const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
- // Create a separate section for probes that comes with a comdat function.
- if (const MCSymbol *Group = ElfSec.getGroup()) {
- auto *S = static_cast<MCSectionELF *>(PseudoProbeSection);
- auto Flags = S->getFlags() | ELF::SHF_GROUP;
- return Ctx->getELFSection(S->getName(), S->getType(), Flags,
- S->getEntrySize(), Group->getName(),
- /*IsComdat=*/true);
- }
+ if (Ctx->getObjectFileType() != MCContext::IsELF)
+ return PseudoProbeSection;
+
+ const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);
+ unsigned Flags = ELF::SHF_LINK_ORDER;
+ StringRef GroupName;
+ if (const MCSymbol *Group = ElfSec.getGroup()) {
+ GroupName = Group->getName();
+ Flags |= ELF::SHF_GROUP;
}
- return PseudoProbeSection;
+
+ return Ctx->getELFSection(PseudoProbeSection->getName(), ELF::SHT_PROGBITS,
+ Flags, 0, GroupName, true, ElfSec.getUniqueID(),
+ cast<MCSymbolELF>(TextSec.getBeginSymbol()));
}
MCSection *