Skip to content

Implement RFC 3917 for instrumented functions#153742

Draft
pmur wants to merge 6 commits into
rust-lang:mainfrom
pmur:murp/instrument-function-rfc
Draft

Implement RFC 3917 for instrumented functions#153742
pmur wants to merge 6 commits into
rust-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.

@rust-log-analyzer

This comment has been minimized.

@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

This comment has been minimized.

@rust-bors

This comment has been minimized.

@pmur pmur force-pushed the murp/instrument-function-rfc branch from c890f21 to ac21506 Compare April 7, 2026 21:30
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@pmur pmur force-pushed the murp/instrument-function-rfc branch 2 times, most recently from 85d675c to f5445b2 Compare April 8, 2026 20:21
@rust-log-analyzer

This comment has been minimized.

@pmur pmur force-pushed the murp/instrument-function-rfc branch from f5445b2 to d1dbe5f Compare April 8, 2026 21:29
@rustbot rustbot added the A-run-make Area: port run-make Makefiles to rmake.rs label Apr 8, 2026
@rust-bors

This comment has been minimized.

pmur added 6 commits May 13, 2026 10:16
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.

TODO: make and update tracking issue
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`.
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.
@pmur pmur force-pushed the murp/instrument-function-rfc branch from d1dbe5f to 599f2e6 Compare May 13, 2026 15:45
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. A-run-make Area: port run-make Makefiles to rmake.rs 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