-
Notifications
You must be signed in to change notification settings - Fork 35
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
u128 miscompilation in 1.63.0.2 #137
Comments
Thanks for the test case! I'm really struggling with this one, I'm pretty sure anything that is printed is wrong. For instance, if you add a couple of asserts to that test case: let x = dbg!(p1.a) as u128 * 10;
dbg!(x);
assert_eq!(x, 10); You'll find that the actual values there are correct. I have also confirmed this by printing the numbers a byte at a time and reconstructing the number manually, which indicates an issue with printing. I imagine some part of the What this doesn't explain is why sleep is not working for you 🤔. |
Good point, I may not be triggering any incorrect behavior other than the prints. Now I tried modifying #[inline(never)]
pub fn observe_u32(val: u32) {
println!("{val}");
}
#[cfg(target_os = "espidf")]
pub fn sleep(dur: Duration) {
let mut micros = dur.as_micros();
unsafe {
while micros > 0 {
let st = if micros > u32::MAX as u128 { u32::MAX } else { micros as u32 };
Self::observe_u32(st);
libc::usleep(st);
micros -= st as u128;
}
}
} This keeps printing |
I don't think so, because we use the |
Hmm, perhaps this is related to the depth of the call stack, just copying some offending functions to the demo application doesn't cause the issue 🤔 |
This might be completely unrelated to this bug, but something fishy is still going on with the calling ABI. This is the part of
So to my reading, the first parameter is correctly put in Could it be that the LLVM ABI implementation you ported is also buggy? I'd assume they are still compatible with each other, which is why this might not be the cause of this particular bug. Not sure how I could see the assembly of the |
Just to say, I have also observed this, with 1.63.0.2, only on xtensa (almost the same app works fine on an ESP32-C3).
|
Hey folks, I've spent the last week debugging the current ABI, reading various Xtensa ISA documents, as well as looking into the Xtensa LLVM backend and how it handles parts of the ABI in codegen. I've just pushed esp-1.63.0.3 branch which I believe now solves all the ABI issues. I would appreciate it if you could build that branch and test it out before I release this :). FYI on my journey, I found another bug related to some 128bit integer math, which I have reported internally. Hopefully, that should get sorted soon too :). Thank you for your patience! |
Can confirm that the original test now works correctly, as does |
Thanks for all the work @MabezDev! I can confirm the 1.63.0.3 branch solves both my u128 issues. |
rust-esp32-std-demo seems to run fine now - no longer backtraces after |
It should be noted this also manifests itself as UART |
@MabezDev any plans to release this? |
Due to the release of 1.64.0.0 being so soon, we've released that instead of 1.63.0.3. The branch is available here: https://github.com/esp-rs/rust. Builds will be available soon, but slower than usual as we have to rebuild LLVM too. |
legend, thx for clarification |
The following code
prints (on
-C opt-level=z
)The test is reduced from
std::thread::sleep
which currently gets stuck sleeping forever. It's pretty particular about the details, otherwise it might work correctly or cause panics in the format code.I've also added this to https://github.com/ollpu/esp-rustc-abi-bug
The text was updated successfully, but these errors were encountered: