Skip to content
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

PartialEq impl for IpAddr causes SIGBUS on mips-unknown-linux-gnu #1060

Open
4 of 11 tasks
djkoloski opened this issue Oct 6, 2022 · 14 comments
Open
4 of 11 tasks

PartialEq impl for IpAddr causes SIGBUS on mips-unknown-linux-gnu #1060

djkoloski opened this issue Oct 6, 2022 · 14 comments
Labels
A-mips Area: MIPS targets A-qemu Area: qemu runners bug upstream

Comments

@djkoloski
Copy link

Checklist

Describe your issue

(originally filed at rust-lang/rust#102722, original text below)

I tried this code on mips-unknown-linux-gnu through cargo-cross:

use std::net::{IpAddr, Ipv4Addr};

fn main() {
    let value = IpAddr::V4(Ipv4Addr::new(31, 41, 59, 26));
    assert_eq!(&value, &value);
}
cross run --target mips-unknown-linux-gnu --verbose

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:

  1. This is extremely plain code, just a struct in an enum.
  2. This is crashing in the implementation of PartialEq which has been generated by a derive.
  3. Removing the outer IpAddr does not cause a crash.
  4. Far more complex code runs successfully.

Meta

rustc --version --verbose:

rustc 1.64.0 (a55dd71d5 2022-09-19)
binary: rustc
commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52
commit-date: 2022-09-19
host: x86_64-pc-windows-msvc
release: 1.64.0
LLVM version: 14.0.6

What target(s) are you cross-compiling for?

mips-unknown-linux-gnu

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.4 (6ecf9e3 2022-10-4-05)

Example

use std::net::{IpAddr, Ipv4Addr};

fn main() {
    let value = IpAddr::V4(Ipv4Addr::new(31, 41, 59, 26));
    assert_eq!(&value, &value);
}
cross run --target mips-unknown-linux-gnu --verbose

Additional information / notes

It looks like this is a cross issue, as cross installed with cargo install does not exhibit this issue but cross installed with cargo install --git does. It looks like the QEMU version has been bumped a few times since I can last confirm last passed roughly 25 days ago. However, it could be anything really.

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Oct 6, 2022

We're using the official Ubuntu toolchain for the target, so it's pretty unlikely to be a toolchain issue. I've also been unable to reproduce it locally, but obviously, that doesn't mean the issue doesn't exist. We also use the same toolchain as Rust's Dockerfile in their ci. If you can provide more info on your setup, I might see if I can get a working test case in a VM.

I'm also unable to reproduce this on the latest cross with newer images. My information is:

  • Docker Host: linux/amd64
  • Docker Version: 20.10.18, build b40c2f6
  • Cross Version: cross 0.2.4 (0fcfc0b 2022-09-29) (latest commit here)
  • Rust Version: 1.62.0 (a8314ef7d 2022-06-27)
  • Image Info: ghcr.io/cross-rs/mips-unknown-linux-gnu: main, 2b49a90c51c7, 22 hours ago (so the latest main)
  • Host Distro Info: Fedora 36
  • Host Kernel Version: 5.19.12-200

And inside the images:

  • Qemu MIPS Version: 7.0.0
  • MIPS GCC Version: 9.4.0
  • MIPS glibc Version: 2.30

I have the following main.rs:

use std::net::{IpAddr, Ipv4Addr};

fn main() {
    let value = IpAddr::V4(Ipv4Addr::new(31, 41, 59, 26));
    assert_eq!(&value, &value);
    println!("tests succeeded");
}

And then run:

$ cross run --target mips-unknown-linux-gnu
    Finished dev [unoptimized + debuginfo] target(s) in 0.14s
     Running `/qemu-runner mips /target/mips-unknown-linux-gnu/debug/issue_1060`
tests succeeded

The only other difference is we use a newer version of Ubuntu (20.04) than the Rust CI Dockerfile (16.04), which was done as part of the update in #591.

@Emilgardis

This comment was marked as off-topic.

@Emilgardis

This comment was marked as off-topic.

@Alexhuszagh
Copy link
Contributor

CROSS_CONTAINER_OPTS="--privileged --security-opt=seccomp=unconfined" cross run doesn't work

Does it produce the same SIGBUS signal? Also, I'd have to imagine it's the --privileged flag since disabling the seccomp profile just means all system calls are allowed.

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Oct 6, 2022

This will be updated, but this is the systems I've tested. A checked box means it passes:

  • Linux AMD64: Docker Version: 20.10.18, build b40c2f6
  • Windows WSL2 Backend (not inside WSL2): 20.10.17, build 100c701
  • Windows in WSL2 (Ubuntu 22.04): (Podman 3.4.4)

All are using the latest main images. I'll see if I can reproduce it on my Macbook (x86_64, 2013).

The security options are also not causing issues on my Fedora 36 system.

@Emilgardis
Copy link
Member

try with a newer rustc

@Emilgardis
Copy link
Member

(I can get the error with the same versions as you but still, never know)

@Alexhuszagh
Copy link
Contributor

It's also not reproducing with 1.61.0, 1.63.0 and 1.64.0 on my machines.

@Emilgardis
Copy link
Member

Oh!

I'm getting this error

❯ CROSS_CONTAINER_OPTS="--privileged --security-opt=seccomp=unconfined" cross run
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
<jemalloc>: MADV_DONTNEED does not work (memset will be used instead)
<jemalloc>: (This is the expected behaviour if you are running under QEMU)
    Finished dev [unoptimized + debuginfo] target(s) in 3.20s
     Running `/qemu-runner mips /target/mips-unknown-linux-gnu/debug/mips-qemu`
qemu-mips: Unable to reserve 0x80000000 bytes of virtual address space at 0x8000 (Success) for use as guest address space (check yourvirtual memory ulimit setting, min_mmap_addr or reserve less using -R option)

maybe the fact I can get this to error is not applicable since it's not the same

@Alexhuszagh
Copy link
Contributor

Ah that's a different issue.

Also, @djkoloski, feel free to send me the output binaries from the test-case that are compiled on your machine to me (ahuszagh@gmail.com). I'd like to test them locally. I'm pretty sure it's an issue of the kernel versions the Docker container is using are different, since that's the only that seems to have changed :/.

@Emilgardis
Copy link
Member

you can also attach them to a message here 👍🏼

@zachs18
Copy link
Contributor

zachs18 commented Oct 6, 2022

I think this is either a QEMU issue or a miscompilation, and not a cross issue, because I can observe it without cross at all.

I can get this error without cross on qemu-mips version 7.0.0 (Debian 1:7.0+dfsg-7ubuntu2) on Ubuntu Kinetic (20.10 pre-release).

# .cargo/config.coml
[target.mips-unknown-linux-gnu]
linker = "mips-linux-gnu-gcc"
runner = ["qemu-mips", "-L", "/usr/mips-linux-gnu"]

(same main.rs as OP, default Cargo.toml; run sudo apt install gcc-mips-linux-gnu qemu-user)
On Ubuntu 20.10 with qemu 7.0.0:

$ 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 target/mips-unknown-linux-gnu/debug/rust-102722`
qemu: uncaught target signal 10 (Bus error) - core dumped
Bus error (core dumped)

On Ubuntu 20.04 with qemu 6.2.0: (no error)

$ cargo run --target mips-unknown-linux-gnu
   Compiling rust-102722 v0.1.0 (/home/zachary/Programming/mwe/rust-102722)
    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running `qemu-mips -L /usr/mips-linux-gnu target/mips-unknown-linux-gnu/debug/rust-102722`

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Oct 7, 2022

I'll try to get some minimal VMs (not using Docker because I need to ensure the kernel is actually for the host distro it is) for this, copy over the Qemu binaries we have for different versions (great thing is due to the different tags published and that they're statically linked, this is easy), and compile binaries for different versions and detect if this is a cross issue or a Qemu issue.

Going to Try with:

  • Qemu 6.2.0
  • Qemu 7.0.0

On VMs for:

  • Ubuntu 20.04
  • Ubuntu 20.10

(I might be able to get away with this on WSL2).

Compiled Against:

  • Cross 0.2.4 (Ubuntu 16.04 MIPS toolchain)
  • Cross main (Ubuntu 20.04 MIPS toolchain)

This will be using a 1.64.0 Rust toolchain.

@Alexhuszagh
Copy link
Contributor

Alexhuszagh commented Oct 7, 2022

I'm almost certain this is an odd interaction between Linux (and likely mostly the kernel, since this seems to matter in Docker images of unaffected Ubuntu versions, where the only difference for the same image on different machines is the host kernel), since the Qemu version only matters on Ubuntu 22.04, but not Ubuntu 20.04.

Test Information

Using cross for versions 0.2.4 and the latest main, I did the following:

main.rs

use std::net::{IpAddr, Ipv4Addr};

fn main() {
    let value = IpAddr::V4(Ipv4Addr::new(31, 41, 59, 26));
    assert_eq!(&value, &value);
}

build

cargo install cross
cross build --target mips-unknown-linux-gnu
cp target/mips-unknown-linux-gnu/issue_1060 mips-0.2.4

cargo clean

cargo install cross --git https://github.com/cross-rs/cross
cross build --target mips-unknown-linux-gnu
cp target/mips-unknown-linux-gnu/issue_1060 mips-main

Just to confirm the toolchains used and resulting binaries were certainly different, I calculated the hashsums just in case (using the same toolchains with clean builds produced the same sum):

$ sha256sum mips_main
e46f7038794e11c6299d19036cd768e664a5f43ddc3802405da942436442094c *mips_main
$ sha256sum mips_0.2.4
0975d99db29702dcf5c95f1f019359975aaf47791941b818974a259592f5fc45 *mips_0.2.4

From here, then on WSL2 I tried the following:

apt-get install g++-mips-linux-gnu libc6-dev-mips-cross qemu-user qemu-user-static -y
# ubuntu 22.04 has qemu 7.1.0, 20.04 has 4.2.1
cp /usr/bin/qemu-mips-static qemu-mips-$version

./qemu-mips-4.2.1 -L /usr/mips-linux-gnu mips_main
./qemu-mips-4.2.1 -L /usr/mips-linux-gnu mips_0.2.4

./qemu-mips-7.1.0 -L /usr/mips-linux-gnu mips_main
./qemu-mips-7.1.0 -L /usr/mips-linux-gnu mips_0.2.4

Results

The docker results are for runs inside Docker containers with a host of Fedora 36 5.19.12-200.fc36.x86_64, so this is the useful information for the Docker kernel info.

0.2.4

Qemu Version Ubuntu 20.04 Ubuntu 22.04 Ubuntu 20.04 (Docker) Ubuntu 22.04 (Docker)
4.2.1 X
7.1.0 X X

main

Qemu Version Ubuntu 20.04 Ubuntu 22.04 Ubuntu 20.04 (Docker) Ubuntu 22.04 (Docker)
4.2.1 X
7.1.0 X X

The signal from Ubuntu 20.04 (Docker) is a SIGSEGV, not SIGBUS:

qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault (core dumped)

Files

These are the attached static qemu builds for 4.2.1 and 7.1.0, as well as the debug builds for the 0.2.4 and main images.

issue_1060.zip

@Alexhuszagh Alexhuszagh added upstream and removed needs-information needs more information to replicate labels Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mips Area: MIPS targets A-qemu Area: qemu runners bug upstream
Projects
None yet
Development

No branches or pull requests

4 participants