This is an archive of the discontinued LLVM Phabricator instance.

[Pseudo Probe] Make .pseudo_probe GC-able
ClosedPublic

Authored by MaskRay on Jun 16 2023, 6:45 PM.

Details

Summary
  • 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).

Diff Detail

Event Timeline

MaskRay created this revision.Jun 16 2023, 6:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 6:45 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
MaskRay requested review of this revision.Jun 16 2023, 6:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 6:45 PM
hoy added a comment.Jun 16 2023, 10:42 PM

Thanks for working on this! It looks better than using function name for deduplication and gc.

llvm/lib/MC/MCObjectFileInfo.cpp
1179

I think the type should inherit the type of PseudoProbeSection.

1180

Should the pseudo probe section be a comdat only if the text section is a comdat?

MaskRay marked 2 inline comments as done.Jun 16 2023, 10:56 PM

Thanks for the quick review!

llvm/lib/MC/MCObjectFileInfo.cpp
1179

getSection is a MCELFSection method. We'd need cast<MCELFSection>(PseudoProbeSection)->getType() which is a bit too complex. Generally SHT_PROGBITS is the most common ELF section type and the type is checked by pseudo-probe-emit.ll. I hope that writing the type verbatim isn't too bad...

1180

The const MCSymbol *Group = ElfSec.getGroup() condition ensures that the .pseudo_probe section is in a section group only when the text section is in a section group. When GroupName is empty, getELFSection does not use a section group.

hoy added inline comments.Jun 16 2023, 11:09 PM
llvm/lib/MC/MCObjectFileInfo.cpp
1180

So IIUC, when GroupName is empty, IsComdat=true doesn't really make a difference right?

MaskRay marked 2 inline comments as done.Jun 16 2023, 11:15 PM
MaskRay added inline comments.
llvm/lib/MC/MCObjectFileInfo.cpp
1180

Right. ELF has the concept of section groups. GRP_COMDAT is a special/mostly common section group.

Actually, in our use cases IsComdat is a no-op. We always create text sections before these metadata sections. If the text section has created a section group with the GRP_COMDAT flag, new getELFSection calls, whether or not IsComdat, does not change the fact.

hoy accepted this revision.Jun 16 2023, 11:20 PM

LGTM, thanks.

This revision is now accepted and ready to land.Jun 16 2023, 11:20 PM
MaskRay retitled this revision from [MC] Make .pseudo_probe GC-able to [Pseudo Probe] Make .pseudo_probe GC-able.Jun 16 2023, 11:25 PM
MaskRay edited the summary of this revision. (Show Details)
MaskRay edited the summary of this revision. (Show Details)Jun 16 2023, 11:44 PM
This revision was automatically updated to reflect the committed changes.