-
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
ICE attempting to indirectly call a function that takes a reference through asm! #111709
Comments
Well, it does compile and run successfully if I change the reference to: shim = sym crate::_rust_abi_shim1::<*mut TrapFrame, ()>, instead of shim = sym crate::_rust_abi_shim1::<&mut TrapFrame, ()>, |
Thank you for reporting a very interesting bug. The presence of I can't seem to reproduce this without inline assembly so I think it has to do specifically with an interaction with Ah, I should mention: The way that generics interact with |
Thanks for taking a look! It's a good point about there being an (implicit) lifetime here. I'm not entirely sure what I'm expecting here, since I wouldn't expect
Aha, you've intuited the question I was really trying to answer when I slipped on that ICE: I was half expecting For what it's worth, they do seem to work exactly as I intended here; if I add a second reference that does have a distinct ABI like
I'm sure there's gnarlier edges out there than "pointer or u128", and I probably won't end up using the generic version, but I did think that was neat. Hopefully you do too! |
Minimized example that also works on x86_64, so it's likely not arch dependent: use core::arch::asm;
extern "C" fn test<T>() {}
fn uwu() {
unsafe {
asm!(
"/* {0} */",
sym test::<&mut ()>
);
}
} @rustbot label +A-inline-assembly |
Right, when I say "underspecified" I basically mean that it can work, but it... is not necessarily going to work how you might naively expect it to. So for your future sanity, it's often best to avoid polymorphic declarations in |
I very much appreciate your feedback. I'm fairly certain I'll end up doing something very different in the end, but it was a fun exploration. I'm glad I tried it as well: just doing my part to uphold the law. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
I'm attempting to call a function with a Rust ABI from a trap handler; in one of my attempts to shim in a spot for the compiler to emit a C ABI -> Rust ABI remapping I tried creating a generic shim and grabbing a reference to the compiler's instantiation with the concrete types I needed, as below.
I have no idea if this code would work, but a close cousin does seem to (if I define the shim with concrete types instead of generically).
Code
It doesn't seem to matter, but if it helps: I'm targeting the RISC-V architecture here.
Meta
rustc --version --verbose
:I see the same thing in the rust playground as well: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=1042a83d1938b63786d81595a2cd1207
Error output
Backtrace
The text was updated successfully, but these errors were encountered: