Allow section override when using patchable-function-entries#157445
Allow section override when using patchable-function-entries#157445pmur wants to merge 1 commit into
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_hir/src/attrs |
|
r? @jackh726 rustbot has assigned @jackh726. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
I think this is an important feature which we weren't aware of during the initial implementation of #123115. Adding this should allow Rust to reduce the need to implement mcount or fentry (essentially x86 only) for compatibility within the linux kernel, and likely reduces the need for rust-lang/rfcs#3917. |
|
@rustbot reroll |
|
@rustbot reroll |
| /// Nops after the entry | ||
| entry: u8, | ||
| /// An optional section name to record the entry location | ||
| section: Option<String>, |
There was a problem hiding this comment.
| section: Option<String>, | |
| section: Option<Symbol>, |
This will be simpler if you pass around the symbol (not String/&str) everywhere, just use as_str before calling llvm api.
There was a problem hiding this comment.
I think this is initialized before string interning is available. Or, so the runtime crash leads me to believe. Is there somewhere to insert a late initialization?
There was a problem hiding this comment.
Ah, I wasn't aware of that, makes sense. I'd leave it as is then.
|
Reminder, once the PR becomes ready for a review, use |
| sym::section => { | ||
| // Duplicate entries are not allowed | ||
| if section.is_some() { | ||
| errored = true; |
There was a problem hiding this comment.
nit: usually we use Option<ErrorGuaranteed> for "has errored" variables. Feel free to implement it or not, at your option.
There was a problem hiding this comment.
Can that be done within the attribute parsing framework? I think I am constrained to the SingleAttributeParser trait.
There was a problem hiding this comment.
Functions like duplicate_key return ErrorGuaranteed for this reason.
I think that gets punted to the assembler, and the targets object file format. For ELF, I think that is any nul terminated string. |
This comment has been minimized.
This comment has been minimized.
So this would fail at the codegen stage? It makes for a better user experience to reject it earlier, similar to #155817 |
8f7613b to
c729ed3
Compare
This comment has been minimized.
This comment has been minimized.
|
Updated to handle nul's more gracefully. llvm doesn't handle the inline nul gracefully. |
c729ed3 to
55b62aa
Compare
This comment has been minimized.
This comment has been minimized.
Thanks, this looks good. What about empty strings? IIRC with link_name, llvm would just make up something. |
llvm is grumpy and percolates up an error. I think ELF allows an empty section name (whenever that would be useful, I am not sure). I'll add the check. |
55b62aa to
d96530a
Compare
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.
d96530a to
a81de40
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
View all comments
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-entryto accept an argument of the formprefix_nops,total_nops,record_section, which places all entry record into a user specified section.Likewise, extend the
patchable_function_entryattribute to accept an optionalsection="name"option to place a function into a specific section.This is made possible by llvm attribute
patchable-function-entry-sectionadded in llvm 21.