Proposal
I am proposing that Rust support patchable-function-entry as present in clang and gcc. This feature is generally used to allow hotpatching and instrumentation of code.
What
patchable-function-entry provides configurable nop padding before function symbols and after function symbols but before any generated code. We refer to the former as prefix padding and the latter as entry padding. For example, if we had a function f with prefix set to 3 and entry to 2, we'd expect to see:
f_pad:
nop
nop
nop
f:
nop
nop
// Code goes here
f_pad here is not a real symbol or label, it is only inserted here for explanatory purposes. A __patchable_function_entries section will be added to the output object containing the addresses of each f_pad-like location in the object.
prefix and entry correspond to the LLVM attribute implementation.
The flag form instead uses nop_count and offset to match the clang and gcc flags for easier integration into build systems.
Why
The Linux kernel uses -fpatchable-function-entry heavily, including for ftrace and FINEIBT for x86. Today, enabling these features alongside Rust will lead to confusing or broken behavior (ftrace will fail to trace Rust functions when developing, FINEIBT will conflict with the kcfi sanitizer, etc.).
It also uses the clang and gcc attribute patchable_function_entry to disable this padding on fragile functions or those used for instrumentation. I have a companion RFC draft for this which covers both the flag described here and support for the attribute. This MCP is focused on just adding support for the flag, as this will unblock kernel work while we wait on RFC resolution for full support.
Integrating Rust code into this and other large projects which expect all native code to have these nop buffers will be made easier by allowing them to request the same treatment of native functions they get in C and C++.
Mentors or Reviewers
Process
The main points of the Major Change Process are as follows:
You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
Proposal
I am proposing that Rust support
patchable-function-entryas present inclangandgcc. This feature is generally used to allow hotpatching and instrumentation of code.What
patchable-function-entryprovides configurable nop padding before function symbols and after function symbols but before any generated code. We refer to the former asprefixpadding and the latter asentrypadding. For example, if we had a functionfwithprefixset to 3 andentryto 2, we'd expect to see:f_padhere is not a real symbol or label, it is only inserted here for explanatory purposes. A__patchable_function_entriessection will be added to the output object containing the addresses of eachf_pad-like location in the object.prefixandentrycorrespond to the LLVM attribute implementation.The flag form instead uses
nop_countandoffsetto match theclangandgccflags for easier integration into build systems.Why
The Linux kernel uses
-fpatchable-function-entryheavily, including forftraceandFINEIBTfor x86. Today, enabling these features alongside Rust will lead to confusing or broken behavior (ftracewill fail to trace Rust functions when developing,FINEIBTwill conflict with thekcfisanitizer, etc.).It also uses the
clangandgccattributepatchable_function_entryto disable this padding on fragile functions or those used for instrumentation. I have a companion RFC draft for this which covers both the flag described here and support for the attribute. This MCP is focused on just adding support for the flag, as this will unblock kernel work while we wait on RFC resolution for full support.Integrating Rust code into this and other large projects which expect all native code to have these nop buffers will be made easier by allowing them to request the same treatment of native functions they get in C and C++.
Mentors or Reviewers
Process
The main points of the Major Change Process are as follows:
@rustbot second.-C flag, then full team check-off is required.@rfcbot fcp mergeon either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.