fentry/mcount, patchable function entries, ftrace, and future compiler support
From: Paul Murphy
Date: Thu May 07 2026 - 18:04:49 EST
Hi,
I am working on improving rust's support for instrumented functions,
and indirectly, llvm's support for kernel inspired extensions to
mcount/fentry. In short, could patchable-function-entries replace the
usage of mcount/fentry?
The x86-64 kernel uses both fentry and patchable-function-entries in
many common configurations. Using both compiler features
simultaneously raised some questions[1] from the llvm maintainers. The
background of why[2] is reasonable given the toolchain limitations.
Likewise, some toolchain developers see patchable-function-entries as
a replacement for fentry; that isn't true today. I have been working
on adding support llvm/rust[3], and have had reasonable questions
asked about why both are needed.
Is patchable-function-entries missing features which would allow a
full transition away from fentry? If so, what might they be? Today,
llvm does not support -mnop-mcount or -mrecord-mcount for x86-64. It
is a small change, but has met some resistance as many other
architectures have switched to patchable-function-entries.
[1] https://github.com/rust-lang/rfcs/pull/3917#issuecomment-4148370709
[2] discussion around bpf, ftrace, and instrumented functions:
https://lore.kernel.org/bpf/20220722110811.124515-1-jolsa@xxxxxxxxxx/
[3] rust rfc for instrumented functions: github.com/rust-lang/rfcs/pull/3917