Page MenuHomePhabricator

[Inline] prevent inlining on noprofile mismatch

Authored by nickdesaulniers on Jun 23 2021, 12:52 PM.



Similar to
commit bc044a88ee3c ("[Inline] prevent inlining on stack protector mismatch")

The noprofile function attribute is meant to prevent compiler
instrumentation from being inserted into a function. Inlining may defeat
the developer's intent. If the caller and callee don't either BOTH have
the attribute or BOTH lack the attribute, suppress inline substitution.

This matches behavior being proposed in GCC:

Add LangRef entry for noprofile fn attr, similar to text added in D93422
and D104944.

Diff Detail

Event Timeline

nickdesaulniers requested review of this revision.Jun 23 2021, 12:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2021, 12:52 PM
nickdesaulniers planned changes to this revision.Jun 23 2021, 12:56 PM
nickdesaulniers requested review of this revision.Jun 24 2021, 12:21 PM
nickdesaulniers edited the summary of this revision. (Show Details)
nickdesaulniers removed a subscriber: jdoerfert.
MaskRay added a comment.EditedJun 24 2021, 12:38 PM


The contract is that the annotated code region, even if inlined or cloned, does not get instrumentation.
I think suppressing inlining a NoProfileAttr callee into a caller without the attr is the only practical approach here,
because a fine-grained per-instruction attribute is obviously cumbersome and likely over-engineering.
For example, a smart inliner could still inline a noprofile callee, just filtering out the instrumentation instructions.
But this is definitely over-engineering.

Users (mainly the Linux kernel developers) should be aware that noprofile does not imply noinline.
It just behaves like noinline in many use cases.

Add @wmi for test coverage suggestions from the experience of D79959 "use-sample-profile".

Similar to bc044a88ee3c, I should probably add a test for alwaysinline.

Similar to D93422, I should update the LangRef for noprofile.

nickdesaulniers planned changes to this revision.Jun 25 2021, 2:36 PM
nickdesaulniers edited the summary of this revision. (Show Details)
  • langref addition for noprofile, test alwaysinline callsite
MaskRay added inline comments.Jun 28 2021, 12:54 PM

My only problem is with (too strong) guarantee. I think we can only say the instructions will not instrumentation even inlined.

  • relax specifics regarding inlining noprofile in LangRef
nickdesaulniers marked an inline comment as done.Jun 28 2021, 1:39 PM
MaskRay accepted this revision.Jun 28 2021, 1:42 PM
MaskRay added inline comments.

For alwaysinline, I think the effect may be hazy. Dropping instrumentation is ok. To make alwaysinline take preference (the behavior of many other binary attributes), retaining instrumentation also looks ok.

This revision is now accepted and ready to land.Jun 28 2021, 1:42 PM
melver accepted this revision.Jun 29 2021, 5:06 AM
phosek accepted this revision.Jun 29 2021, 10:05 AM


This revision was automatically updated to reflect the committed changes.