Allow section override when using patchable-function-entries

Sometimes it is necessary to group patchable function entrypoint
records in distinct linker sections. This is the case for some bpf
functions within the linux kernel which shouldn't be visible to
ftrace.

Extend `-Zpatchable-function-entry` to accept an argument of the form
`prefix_nops,total_nops,record_section`, which places all entry
record into a user specified section.

Likewise, extend the `patchable_function_entry` attribute to accept an
optional `section="name"` option to place a function into a specific
section.

This is made possible by llvm attribute `patchable-function-entry-section`
added in llvm 21.
This commit is contained in:
Paul Murphy
2026-06-03 16:40:12 -05:00
parent 7dc2c162b9
commit c340e8a2ba
18 changed files with 257 additions and 74 deletions
@@ -0,0 +1,20 @@
//@ compile-flags: -Z patchable-function-entry=15,10,default_foo_section
//
#![feature(patchable_function_entry)]
#![crate_type = "lib"]
// This should have the default, as set by the compile flags
#[no_mangle]
pub fn fun0() {}
// This should override the default section name
#[no_mangle]
#[patchable_function_entry(section = "bar_section")]
pub fn fun1() {}
// CHECK: @fun0() unnamed_addr #0
// CHECK: @fun1() unnamed_addr #1
// CHECK: attributes #0 = { {{.*}}"patchable-function-entry"="5"{{.*}}"patchable-function-entry-section"="default_foo_section"{{.*}}"patchable-function-prefix"="10" {{.*}} }
// CHECK: attributes #1 = { {{.*}}"patchable-function-entry"="5"{{.*}}"patchable-function-entry-section"="bar_section"{{.*}}"patchable-function-prefix"="10" {{.*}} }