-
Notifications
You must be signed in to change notification settings - Fork 229
use #[naked]
for __rust_probestack
#897
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? No Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
fb31ab0
to
61be61f
Compare
compiler-builtins/src/probestack.rs
Outdated
core::arch::global_asm!( | ||
define_rust_probestack!( | ||
#[unsafe(naked)] | ||
#[no_mangle] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that exporting this as a C symbol is important, but maybe it's not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, rustc hard codes the name of this function. It should probably be changed to use #[rustc_std_internal_symbol]
mangling though, but that would require coordination between rustc and compiler-builtins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually using #[no_mangle]
would cause __rust_probestack
to be exported from cdylibs, so I think it will have to be changed to #[rustc_std_internal_symbol]
in this PR and changed on the rustc side when bumping the compiler-builtins dependency. It is currently not exported from cdylibs as rustc isn't aware that the global_asm!() exports __rust_probestack
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm,
error[E0658]: this is an internal attribute that will never be stable
--> compiler-builtins/src/probestack.rs:64:1
|
64 | #[rustc_std_internal_symbol]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add `#![feature(rustc_attrs)]` to the crate attributes to enable
= note: this compiler was built on 2025-04-21; consider upgrading it if it is out of date
error[E0736]: attribute incompatible with `#[unsafe(naked)]`
--> compiler-builtins/src/probestack.rs:64:1
|
63 | #[unsafe(naked)]
| ---------------- function marked with `#[unsafe(naked)]` here
64 | #[rustc_std_internal_symbol]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `rustc_std_internal_symbol` attribute is incompatible with `#[unsafe(naked)]`
I guess compiler-builtins
can just enable #![feature(rustc_attrs)]
, but that second error needs a fix in rustc
first.
f4d8cfa
to
d70607d
Compare
define_rust_probestack!( | ||
#[unsafe(naked)] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn __rust_probestack() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you mention in the doc comment that the custom ABI is the reason this is unsafe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean in the module doc comment? We can add some specific details (about what registers are used etc) if we add a doc comment to the function itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was referring to the comments above each of the functions, I guess they're not actually doc comments though they could be. Something like (hence the `unsafe`, since the ABI does not actually match `extern "C"`)
in the paragraph describing ABI is sufficient, unless you want to add more. Just to have a note that it isn't supposed to be extern "C"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That reminded me of a few other cases we have where naked functions are extern "C"
but that doesn't really make sense. Seems like a somewhat common issue, I wrote up rust-lang/rust#140566 as a possible way to make this more clear (not for this pr of course).
…d_internal_symbol, r=bjorn3 allow `#[rustc_std_internal_symbol]` in combination with `#[naked]` The need for this came up in rust-lang/compiler-builtins#897, but in general this seems useful and valid to allow. Based on a quick scan, I don't think changes to the generated assembly are needed. cc `@bjorn3`
Thanks for putting this together, this is a nice bit of simplification. After the
Feel free to do any cleanup you see fit. Split NFC commits are great, GH's "ignore whitespace" option on the review UI works for everything else 🙂 |
d70607d
to
4d09a30
Compare
4d09a30
to
a548e1f
Compare
Hmm, formatting does not really help much, because formatting in asm is undefined. So let's leave it as it is. I did merge the definition for |
There will need to be a change on the rustc side anyway when updating compiler-builtins. |
…d_internal_symbol, r=bjorn3 allow `#[rustc_std_internal_symbol]` in combination with `#[naked]` The need for this came up in rust-lang/compiler-builtins#897, but in general this seems useful and valid to allow. Based on a quick scan, I don't think changes to the generated assembly are needed. cc ``@bjorn3``
Well currently the bootstrap compiler rejects So yeah waiting for the new beta is probably easiest (not sure how rustweek impacts the schedule there, but we'll see) |
…d_internal_symbol, r=bjorn3 allow `#[rustc_std_internal_symbol]` in combination with `#[naked]` The need for this came up in rust-lang/compiler-builtins#897, but in general this seems useful and valid to allow. Based on a quick scan, I don't think changes to the generated assembly are needed. cc `@bjorn3`
Rollup merge of rust-lang#140552 - folkertdev:naked-function-rustc_std_internal_symbol, r=bjorn3 allow `#[rustc_std_internal_symbol]` in combination with `#[naked]` The need for this came up in rust-lang/compiler-builtins#897, but in general this seems useful and valid to allow. Based on a quick scan, I don't think changes to the generated assembly are needed. cc ``@bjorn3``
This should work now.
#[naked]
takes care of adding the directives thatdefine_rust_probestack
added.I deliberately did not format/indent the assembly code to make review easier. I could do that in a separate commit it that is desirable.
Let's see if CI is OK with this.