Skip to content

Implement RFC 3917 for instrumented functions#153742

Draft
pmur wants to merge 7 commits intorust-lang:mainfrom
pmur:murp/instrument-function-rfc
Draft

Implement RFC 3917 for instrumented functions#153742
pmur wants to merge 7 commits intorust-lang:mainfrom
pmur:murp/instrument-function-rfc

Conversation

@pmur
Copy link
Copy Markdown
Contributor

@pmur pmur commented Mar 11, 2026

This adds:

  • The -Zinstrument-function={mcount,fentry,xray,none} option
  • Support for fentry (only supported on x86 and s390x, advanced options only supported on s390x).
  • The -Zinstrument-fentry-opts=.... This is probably only needed for linux.
  • -Zinstrument-xray is renamed to -Zinstrument-xray-opts and the yes/no/implicit option are removed.
  • #[instrument_fn="on|off"] attribute for toggling instrumentation on select functions.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 11, 2026
@rust-log-analyzer

This comment has been minimized.

pmur added 3 commits March 12, 2026 15:11
This attribute enables or disables function instrumentation
when using `-Zinstrument-xray` or `-Zinstrument-mcount`.

It supports the following usage:

`#[instrument_fn = "on|off"]`

For XRay, "on" is equivalent to always instrument, and "off" is
equivalent to never instrumenting.

For mcount, "on" has no effect. "off" disables instrumentation
of the function.
The behavior is very similar to `-Zinstrument-mcount`, except this
option has no frame-pointer requirements, and is called before the
call frame is set up.

This only works on x86, x86-64, and s390x targets.
This facilitates support for inserting nop's and/or recording the
location of each mcount call in a special section named `__mcount_loc`.
@pmur pmur force-pushed the murp/instrument-function-rfc branch from 1d0e673 to c12fc8d Compare March 12, 2026 20:19
@rust-log-analyzer

This comment has been minimized.

pmur added 3 commits March 12, 2026 16:10
Convert these into `-Zinstrument-function={none|fentry|xray}`.

`-Zinstrument-xray` is split into `-Zinstrument-function=xray` and
`-Zinstrument-xray-opts=...`.

Also, rename `-Zinstrument-mcount-opts` to `-Zinstrument-fentry-opts` to
reflect it is only usable with fentry. In theory, it could work with
both (as it does on gcc), in practice the llvm support is limited to
s390x/fentry as of llvm 22.
This is maybe gated by some sort of agreement on RFC 3917?
@pmur pmur force-pushed the murp/instrument-function-rfc branch from c12fc8d to d89e115 Compare March 12, 2026 21:11
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 28, 2026

☔ The latest upstream changes (presumably #154466) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 28, 2026

☔ The latest upstream changes (presumably #154503) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants