-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “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? Sign in to your account
Dynamic library generates functions with no meaningful assembly. #125299
Comments
@pirocks You should avoid using The nightly docs for
Specifically using use std::{ptr, mem};
#[no_mangle]
pub unsafe extern "system" fn foo_bar_baz(addr: i64) -> i8 {
let ptr: *const i8 = ptr::null().wrapping_offset(addr);
ptr.read()
} The following, however, uses an #[no_mangle]
pub unsafe extern "system" fn foo_bar_baz(addr: i64) -> i8 {
let ptr: *const i8 = addr as ptr;
ptr.read()
} If you can, it would be a good idea to redeclare the relevant interfaces to accept pointers instead... |
We actually lower it to pretty much exactly that since #121282. |
I apologize for my kinda dumb mistake there. I was under the impression I should at least get some kind of assembly from that function since I thought transmuting from pointer to integer to pointer again was defined, but docs seem to not agree on that. |
Well as a slight follow up question: Would a clippy and/or compiler warning PR along the lines of "transmute from integer to pointer is ub" be welcome? |
Clippy already lints against it, but it lints it for a different reason than UB. It doesn't explain that dereferencing the resulting pointer is UB. And the way it is worded suggests that the replacement of using a cast has identical behavior, which is not the case at all.
|
@pirocks Yes, PRing a lint against doing |
I tried this code(compiling in release mode):
in with the following Cargo.toml:
I expected to see this happen:
I expected a dynamic executable with a function labelled foo_bar_baz in it.
Instead, this happened:
I get a label for the function foo_bar_baz, but it is an undefined instruction only. On older rust versions I get the expected assembly.
I have a much larger project which is affected by this, and it seems to be broadly the same, affects many no_mangle unsafe extern functions(but not all such functions, not really clear as to what the deciding factor is but probably has something to do with function body).
Meta
Repros in latest stable and nightly. cargo-rustc-bisect says:
rustc --version --verbose
:Edit:
Clarified that I was compiling in release mode.
The text was updated successfully, but these errors were encountered: