-
Notifications
You must be signed in to change notification settings - Fork 13.4k
PartialEq
impl for IpAddr
causes SIGBUS
on mips-unknown-linux-gnu
#102722
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
Comments
Trying to repro, but I can't.
Is it possible this is related to a qemu version? |
Maybe? I thought it might also be host platform specific but then remembered that the same issue occurred locally (on Windows) and in a GitHub action (on Ubuntu). I updated |
The github action you linked installs I do see the issue when running with Here's another example program (intentionally performing an unaligned read of a unsafe fn read_u32_unaligned(ptr: *const [u8]) -> u32 {
*ptr.cast()
}
fn main() {
let x: Box<[u8; 8]> = Box::new([1,2,3,4,5,6,7,8]);
unsafe {
println!("{:08X}", read_u32_unaligned(&*x));
println!("{:08X}", read_u32_unaligned(&x[1..])); // at least one of these accesses is definitely unaligned
}
} Gives these results: Does not give
Gives
Maybe we should look into if the original example program is miscompiled down to something with an unaligned memory access? I looked at it a bit, but I do not know MIPS assembly enough to make sense of it. |
Between |
Thanks for the help everyone, I think this is pretty conclusively a |
I think this may be a QEMU issue or a miscompilation, and not a # .cargo/config.coml
[target.mips-unknown-linux-gnu]
linker = "mips-linux-gnu-gcc"
runner = ["qemu-mips", "-L", "/usr/mips-linux-gnu", "-g", "23456"] (same main.rs as OP, default Cargo.toml, run # Note: this will wait for GDB to connect
$ cargo run --target mips-unknown-linux-gnu
Compiling rust-102722 v0.1.0 (/root/rust-102722-mwe)
Finished dev [unoptimized + debuginfo] target(s) in 0.16s
Running `qemu-mips -L /usr/mips-linux-gnu -g 23456 target/mips-unknown-linux-gnu/debug/rust-102722`
qemu: uncaught target signal 10 (Bus error) - core dumped
Bus error (core dumped) # In another terminal
$ gdb-multiarch target/mips-unknown-linux-gnu/debug/rust-102722
gdb> sysroot /usr/mips-linux-gnu
gdb> target remote localhost:23456
gdb> c
Program received signal SIGBUS, Bus error.
... Specifically, I observed that The program is about to perform Note that this same instruction executes without SIGBUS on QEMU 6.2.0 for some reason. Does anyone know for sure if MIPS allows unaligned accesses or not? If it does, then this may be a QEMU issue. If not, then this may be a miscompilation. |
Reopening this since it seems worth investigating as a potential miscompilation. Thanks @zachs18 for putting in a ton of legwork to gather some more information! |
I have run the code with both
After running |
@urosbericsyrmia What version of QEMU are you using? I can still reproduce this on QEMU 8.0.4 (in an Ubuntu 23.10 docker container) with a slightly modified use std::net::{IpAddr, Ipv4Addr};
fn main() {
println!("A");
let value = IpAddr::V4(Ipv4Addr::new(31, 41, 59, 26));
assert_eq!(&value, &value);
println!("B");
} gives cargo run -Z build-std --target mips-unknown-linux-gnu
Compiling rust-102722 v0.1.0 (/rust-102722-mwe)
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.49s
Running `qemu-mips -L /usr/mips-linux-gnu target/mips-unknown-linux-gnu/debug/rust-102722`
A
Bus error (core dumped)
Now the first bus error happens is in |
Originally, I was running the code with QEMU 4.2.1.
But after installing and building QEMU 8.0.4 I get the same error as you.
Thus, is this a QEMU issue? I'm going to take a closer look, thanks for your effort. |
As far as I can tell this issue is unrelated to rust. Should we close it here and move it somewhere else? |
@urosbericsyrmia So far, AFAICT no one in this thread has definitively figured out if mips-unknown-linux-gnu allows unaligned |
Just wanted to point out that I was able to reproduce the issue with the following main.rs:
I get:
By debugging the code I came to a conclusion that there is no issue with |
Could we close this issue if it doesn't occur anymore? |
Another reproducer of what is probably the same issue: use core::mem::ManuallyDrop;
fn noop() {}
fn meow_new<E>(cause: E) -> ManuallyDrop<E> {
noop();
ManuallyDrop::new(cause)
}
#[repr(packed)]
struct Unaligned(i32);
fn main() {
meow_new(Unaligned(123i32));
} $ rustc -Vv
rustc 1.84.0-nightly (439284741 2024-10-21)
binary: rustc
commit-hash: 4392847410ddd67f6734dd9845f9742ff9e85c83
commit-date: 2024-10-21
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
$ cross run --target mips-unknown-linux-gnu -Zbuild-std
Bus error (core dumped) As far as I can see from the core dump, the problem is an unaligned |
I can't reproduce that crash. I'm on
|
Hmm. I can reproduce this using the git version of cross ( |
I think I've partially figured it out. |
I've installed cross from git, so now I'm on
And I can reproduce the SIGBUS. |
I've filed an upstream issue: llvm/llvm-project#114283 |
LLVM 20 ships with a fix. @rustbot label +llvm-fixed-upstream |
Rust now ships LLVM 20, and I've verified that my code now works correctly. I think this can be closed. |
I tried this code on
mips-unknown-linux-gnu
throughcargo-cross
:I expected to see this happen: the program exits successfully.
Instead, this happened:
qemu: uncaught target signal 10 (Bus error) - core dumped
This is truly baffling because:
PartialEq
which has been generated by a derive.IpAddr
does not cause a crash.If this is a problem with
cargo-cross
instead, I would be happy to move the bug to the corresponding repo.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: