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

rustc distributed for riscv64 linux segfaults on almost anything #117022

Closed
LaoLittle opened this issue Oct 21, 2023 · 32 comments
Closed

rustc distributed for riscv64 linux segfaults on almost anything #117022

LaoLittle opened this issue Oct 21, 2023 · 32 comments
Labels
C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-riscv Target: RISC-V architecture T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@LaoLittle
Copy link

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: riscv64gc-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

cat /proc/version:

Linux version 6.5.0-9-generic (buildd@riscv64-qemu-lgw01-068) (riscv64-linux-gnu-gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0, GNU ld (GNU Binutils for Ubuntu) 2.41) #9.1-Ubuntu SMP Sat Oct  7 17:18:31 UTC 2023
Backtrace

/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0xbb93a6)[0x3f83fb93a6]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x3f8b848800]
/lib/riscv64-linux-gnu/libc.so.6(read+0x44)[0x3f831e8ece]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-7c20a79be40626d5.so(_ZN51_$LT$$RF$std..fs..File$u20$as$u20$std..io..Read$GT$4read17h6080e84dd1fe0357E+0x28)[0x3f833295d4]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52eaf36)[0x3f886eaf36]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52eccc0)[0x3f886eccc0]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ed3b6)[0x3f886ed3b6]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ed416)[0x3f886ed416]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52edce8)[0x3f886edce8]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52eeac0)[0x3f886eeac0]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-7c20a79be40626d5.so(rust_metadata_std_bf3dc212422480e+0xaf7e2)[0x3f833457e2]
/lib/riscv64-linux-gnu/libc.so.6(+0x6a956)[0x3f8319e956]
/lib/riscv64-linux-gnu/libc.so.6(+0xbbbf0)[0x3f831efbf0]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0xbb93a6)[0x3faa1b93a6]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x3fb1aca800]
/lib/riscv64-linux-gnu/libc.so.6(read+0x44)[0x3fa93e8ece]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-7c20a79be40626d5.so(_ZN51_$LT$$RF$std..fs..File$u20$as$u20$std..io..Read$GT$4read17h6080e84dd1fe0357E+0x28)[0x3fa95295d4]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52eaf36)[0x3fae8eaf36]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52eccc0)[0x3fae8eccc0]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ed3b6)[0x3fae8ed3b6]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ed416)[0x3fae8ed416]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52edce8)[0x3fae8edce8]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52eeac0)[0x3fae8eeac0]
/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-7c20a79be40626d5.so(rust_metadata_std_bf3dc212422480e+0xaf7e2)[0x3fa95457e2]
/lib/riscv64-linux-gnu/libc.so.6(+0x6a956)[0x3fa939e956]
/lib/riscv64-linux-gnu/libc.so.6(+0xbbbf0)[0x3fa93efbf0]
error: could not compile `libc` (lib)
                                                                                Caused by:                  
  process didn't exit successfully: `/home/laolittle/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/rustc --crate-name libc /home/laolittle/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.149/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=80 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off --cfg 'feature="default"' --cfg 'feature="extra_traits"' --cfg 'feature="std"' -C metadata=7cb0156b76950299 -C extra-filename=-7cb0156b76950299 --out-dir /tmp/cargo-installoqXMnf/release/deps -C strip=symbols -L dependency=/tmp/cargo-installoqXMnf/release/deps --cap-lints allow --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_int128 --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor --cfg libc_non_exhaustive --cfg libc_long_array --cfg libc_ptr_addr_of --cfg libc_underscore_const_names --cfg libc_const_extern_fn` (signal: 11, SIGSEGV: invalid memory reference)
error: failed to compile `bat v0.24.0`, intermediate artifacts can be found at `/tmp/cargo-installoqXMnf`.
To reuse those artifacts with a future compilation, set the environment variable `CARGO_TARGET_DIR` to that path.

@LaoLittle LaoLittle added the C-bug Category: This is a bug. label Oct 21, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 21, 2023
@Noratrieb Noratrieb added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. O-riscv Target: RISC-V architecture and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 21, 2023
@saethlin
Copy link
Member

Can you compile a hello world program? Anything at all?

The segfault here is from the Read impl on File, which makes me think something is deeply broken.

@LaoLittle
Copy link
Author

Can you compile a hello world program? Anything at all?

The segfault here is from the Read impl on File, which makes me think something is deeply broken.

hello world is fine

@saethlin saethlin added the O-freebsd Operating system: FreeBSD label Oct 22, 2023
@raw-bin
Copy link

raw-bin commented Nov 10, 2023

Hi.

I think this may be related. Observed when running cargo and rustc on qemu's virt machine emulation with an ubuntu root filesystem:

robin@ubuntu:~/Work/workspace/rust-testing/misc$ cargo new hello
     Created binary (application) `hello` package

robin@ubuntu:~/Work/workspace/rust-testing/misc$ cd hello

robin@ubuntu:~/Work/workspace/rust-testing/misc/hello$ cargo run
   Compiling hello v0.1.0 (/home/robin/Work/workspace/rust-testing/misc/hello)
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x7d240c)[0x7fffa09d240c]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7fffa3d13800]
/lib/riscv64-linux-gnu/libc.so.6(syscall+0x16)[0x7fff9ffe1406]
/lib/riscv64-linux-gnu/libstd-e74a09c2d8dfb358.so(_ZN3std3sys4unix5locks11futex_mutex5Mutex14lock_contended17h82bb17465d9a013fE+0x96)[0x7fffa00f6c7e]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a92d42)[0x7fffa2c92d42]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a93234)[0x7fffa2c93234]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a95160)[0x7fffa2c95160]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a95208)[0x7fffa2c95208]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a943ae)[0x7fffa2c943ae]
/lib/riscv64-linux-gnu/libstd-e74a09c2d8dfb358.so(rust_metadata_std_4809e9723d3e348c+0x7a798)[0x7fffa0103798]
/lib/riscv64-linux-gnu/libc.so.6(+0x6a956)[0x7fff9ff91956]
/lib/riscv64-linux-gnu/libc.so.6(+0xbbbf0)[0x7fff9ffe2bf0]
    Finished dev [unoptimized + debuginfo] target(s) in 7.10s
     Running `target/debug/hello`
Hello, world!

robin@ubuntu:~/Work/workspace/rust-testing/misc/hello$ uname -a
Linux ubuntu 6.5.0-10-generic #10.1-Ubuntu SMP Sat Oct 28 04:47:16 UTC 2023 riscv64 riscv64 riscv64 GNU/Linux

robin@ubuntu:~/Work/workspace/rust-testing/misc/hello$ rustc --version
rustc 1.71.1 (eb26296b5 2023-08-03) (built from a source tarball)

robin@ubuntu:~/Work/workspace/rust-testing/misc/hello$ cargo --version
cargo 1.71.1

Note that:

  1. This is an ubuntu 23.10 preinstalled RISCV64 server image for qemu's virt machine platform. The image was obtained from here.

  2. The qemu invocation was:

qemu-system-riscv64 -machine virt -nographic \
  -m 8G -smp 8 \
  -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin \
  -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf \
  -device virtio-rng-pci \
  -drive file=ubuntu-23.10-preinstalled-server-riscv64.img,format=raw,if=virtio \
  -netdev user,id=net0,hostfwd=tcp::2222-:22 -device virtio-net-device,netdev=net0
  1. The host is an x86_64 box

The backtrace seems to be triggered by a read of some VDSO symbol by cargo~rustc et al which isn't nice. However, the hello binary is built and runs correctly.

Happy to provide any more info.

Thanks

@saethlin saethlin removed the O-freebsd Operating system: FreeBSD label Nov 10, 2023
@raw-bin
Copy link

raw-bin commented Nov 10, 2023

Another data point. When I try to build the rust compiler natively I get a similar backtrace for rustc but this time it appears to trigger a fatal SIGSEGV:

robin@ubuntu:~/Work/workspace/rust-testing/rust$ ./x.py -h
INFO: Downloading and building bootstrap before processing --help command.
      See src/bootstrap/README.md for help with common commands.
Building bootstrap
   Compiling proc-macro2 v1.0.60
   Compiling memchr v2.5.0
   Compiling quote v1.0.26
error: rustc interrupted by SIGSEGV, printing backtrace

/home/robin/Work/workspace/rust-testing/rust/build/riscv64gc-unknown-linux-gnu/stage0/bin/../lib/librustc_driver-fdc49e368e40bdcf.so(+0xbcbbee)[0x7fff8d1cbbee]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7fff94ba3800]
/lib/riscv64-linux-gnu/libc.so.6(read+0x44)[0x7fff8c552ece]
/home/robin/Work/workspace/rust-testing/rust/build/riscv64gc-unknown-linux-gnu/stage0/bin/../lib/libstd-aa93b6b6286a632f.so(_ZN3std3sys4unix2fs4File4read17h39fb8e8834bf4c77E+0x26)[0x7fff94ae0068]
/home/robin/Work/workspace/rust-testing/rust/build/riscv64gc-unknown-linux-gnu/stage0/bin/../lib/librustc_driver-fdc49e368e40bdcf.so(+0x5330fe2)[0x7fff91930fe2]
/home/robin/Work/workspace/rust-testing/rust/build/riscv64gc-unknown-linux-gnu/stage0/bin/../lib/librustc_driver-fdc49e368e40bdcf.so(+0x532ffd0)[0x7fff9192ffd0]
/home/robin/Work/workspace/rust-testing/rust/build/riscv64gc-unknown-linux-gnu/stage0/bin/../lib/librustc_driver-fdc49e368e40bdcf.so(+0x5331dd6)[0x7fff91931dd6]
/home/robin/Work/workspace/rust-testing/rust/build/riscv64gc-unknown-linux-gnu/stage0/bin/../lib/librustc_driver-fdc49e368e40bdcf.so(+0x5331e2a)[0x7fff91931e2a]
/home/robin/Work/workspace/rust-testing/rust/build/riscv64gc-unknown-linux-gnu/stage0/bin/../lib/librustc_driver-fdc49e368e40bdcf.so(+0x5332662)[0x7fff91932662]
/home/robin/Work/workspace/rust-testing/rust/build/riscv64gc-unknown-linux-gnu/stage0/bin/../lib/librustc_driver-fdc49e368e40bdcf.so(+0x5333606)[0x7fff91933606]
/home/robin/Work/workspace/rust-testing/rust/build/riscv64gc-unknown-linux-gnu/stage0/bin/../lib/libstd-aa93b6b6286a632f.so(rust_metadata_std_9285b80fa7b34547+0xaec00)[0x7fff94ae5c00]
/lib/riscv64-linux-gnu/libc.so.6(+0x6a956)[0x7fff8c508956]
/lib/riscv64-linux-gnu/libc.so.6(+0xbbbf0)[0x7fff8c559bf0]

note: we would appreciate a report at https://github.com/rust-lang/rust
error: rustc interrupted by SIGSEGV, printing backtrace

Git hash for the rust source checkout:
commit d4c86cf (HEAD -> master, origin/master, origin/HEAD)

@saethlin
Copy link
Member

Could these be related to #117101 (comment)?

This was caused by the update to LLVM 17: it adds additional attributes to the object file which indicate which ISA extensions are used. These are parsed by cc and turned into a -march parameter passed to ld. However it seems that older versions of ld don't understand the new target feature attributes added by LLVM 17.

@raw-bin
Copy link

raw-bin commented Nov 13, 2023

@saethlin: It does appear likely. Will try to dig a bit.

@herrernst
Copy link

herrernst commented Nov 14, 2023

I probably have the same or similar issue: I am using current stable rustc directly on riscv64 (Ubuntu 23.10). Even a simple "hello world" spits out weird stuff:

ubuntu@rv:~/src$ cat > example.rs
fn main() {
    println!("Hello World!");
}
ubuntu@rv:~/src$ rustc example.rs 
/home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0xbb93a6)[0x3f7b1b93a6]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x3f82b23800]
/lib/riscv64-linux-gnu/libc.so.6(syscall+0x16)[0x3f7a558406]
/home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-7c20a79be40626d5.so(_ZN3std3sys4unix5locks13futex_condvar7Condvar4wait17hb973eb74843e1e38E+0x64)[0x3f82a65c9c]
/home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ecc88)[0x3f7f8ecc88]
/home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ed3b6)[0x3f7f8ed3b6]
/home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ed416)[0x3f7f8ed416]
/home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52edce8)[0x3f7f8edce8]
/home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52eeac0)[0x3f7f8eeac0]
/home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-7c20a79be40626d5.so(rust_metadata_std_bf3dc212422480e+0xaf7e2)[0x3f82a647e2]
/lib/riscv64-linux-gnu/libc.so.6(+0x6a956)[0x3f7a508956]
/lib/riscv64-linux-gnu/libc.so.6(+0xbbbf0)[0x3f7a559bf0]

It run's though:

ubuntu@rv:~/src$ ./example 
Hello World!

System info:

ubuntu@rv:~/src$ rustc --version --verbose
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: riscv64gc-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2
ubuntu@rv:~/src$ ld --version
GNU ld (GNU Binutils for Ubuntu) 2.41

@tommythorn
Copy link

Could these be related to #117101 (comment)?

This was caused by the update to LLVM 17: it adds additional attributes to the object file which indicate which ISA extensions are used. These are parsed by cc and turned into a -march parameter passed to ld. However it seems that older versions of ld don't understand the new target feature attributes added by LLVM 17.

I don't think so, but let me give the background: I just now created an QEMU RISC-V vm based on https://cdimage.ubuntu.com/releases/23.10/release/ubuntu-23.10-preinstalled-server-riscv64.img.xz following the instructions on https://wiki.ubuntu.com/RISC-V/QEMU (adjusted for the different image). I booted this image and updated it to the development version (do-release-upgrade -d). I then installed rust via the rustup.rs curl line.

Now a cargo new foo; cd foo; cargo run results in

cargo run
   Compiling foo v0.1.0 (/tmp/foo)
error: rustc interrupted by SIGSEGV, printing backtrace

/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0xbcb99a)[0x7fffaab6599a]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7fffb2379800]
/lib/riscv64-linux-gnu/libc.so.6(syscall+0x16)[0x7fffa9d83406]
/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-3fecb5e5a54e748b.so(_ZN3std3sys4unix5locks11futex_mutex5Mutex14lock_contended17hbaa92935a778b624E+0x96)[0x7fffa9ea6218]
/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-3fecb5e5a54e748b.so(_ZN3std3sys4unix5locks13futex_condvar7Condvar4wait17hfe9ded54e8302796E+0x9e)[0x7fffa9ee20d8]
/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x532d230)[0x7fffaf2c7230]
/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x532f06e)[0x7fffaf2c906e]
/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x532f0c2)[0x7fffaf2c90c2]
/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x532f8fa)[0x7fffaf2c98fa]
/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x533089e)[0x7fffaf2ca89e]
/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-3fecb5e5a54e748b.so(rust_metadata_std_8ca29eab19a61e15+0xaebf0)[0x7fffa9ee0bf0]
/lib/riscv64-linux-gnu/libc.so.6(+0x6a956)[0x7fffa9d33956]
/lib/riscv64-linux-gnu/libc.so.6(+0xbbbf0)[0x7fffa9d84bf0]

note: we would appreciate a report at https://github.com/rust-lang/rust
    Finished dev [unoptimized + debuginfo] target(s) in 3.41s
     Running `target/debug/foo`
Hello, world!

but a more evolved projects fails with

...
note: we would appreciate a report at https://github.com/rust-lang/rust
error: could not compile `glob` (lib)

Caused by:
  process didn't exit successfully: `/home/tommy/.rustup.riscv64-linux/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/rustc --crate-name glob /home/tommy/.cargo.ri
scv64-linux/registry/src/index.crates.io-6f17d22bba15001f/glob-0.3.1/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=166 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debug-assertions=off -C overflow-checks=on -C metadata=8829a008e64224de -C extra-
filename=-8829a008e64224de --out-dir /home/tommy/projects/fulmo/target/release/deps -L dependency=/home/tommy/projects/fulmo/target/release/deps --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)

However #117101 (comment) claims that this should work with ld version 2.41

(Sigh I realize now that this is redundant with the previous comment. Hopefully it adds some value).

@tommythorn
Copy link

tommythorn commented Nov 22, 2023

It reproduces with at least 1.73.0, 1.72.0, 1.70.0, and 1.68.0. I haven't found a workaround.
I think the title is misleading as it happens on anything.

@saethlin saethlin changed the title Compiler SIGSEGV in riscv64 linux when compiling crate libc rustc distributed for riscv64 linux segfaults on almost anything Nov 22, 2023
@saethlin
Copy link
Member

saethlin commented Nov 22, 2023

Better? If you'd prefer something else just say and I'll paste it in. (Up-thread someone said they could compile hello world)

@tommythorn
Copy link

tommythorn commented Nov 22, 2023

Ha, thanks. Well, as best I can tell everything will complain and just about anything non-trivial will fail.

Debian 12 with ld 2.40 doesn't appear to have an issue, but both Ubuntu 23.10 (ld 2.40) and Ubuntu 24.04 (ld 2.41) reproduces this.

@saethlin saethlin added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Nov 23, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 23, 2023
@jonathanpallant
Copy link
Contributor

I had a try, and it was fine on Ubuntu 22.04.

ubuntu@x86:~$ qemu-system-riscv64 -machine virt -m 2048 -nographic -bios /usr/lib/riscv64-linux-gnu/opensbi/generic/fw_jump.bin -kernel /usr/lib/u-boot/qemu-riscv64_smode/uboot.elf -device virtio-net-device,netdev=eth0 -netdev user,id=eth0 -device virtio-rng-pci -drive file=ubuntu.img,format=raw,if=virtio
...

ubuntu@riscv:~$ uname -a
Linux ubuntu 5.19.0-1021-generic #23~22.04.1-Ubuntu SMP Thu Jun 22 12:49:35 UTC 2023 riscv64 riscv64 riscv64 GNU/Linux
ubuntu@riscv:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION="Ubuntu 22.04.3 LTS"
ubuntu@riscv:~$ rustc --version
rustc 1.74.0 (79e9716c9 2023-11-13)
ubuntu@riscv:~$ cd hello/
ubuntu@riscv:~/hello$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.42s
     Running `target/debug/hello`
Hello!
Hello, world!
ubuntu@riscv:~/hello$ cd ..
ubuntu@riscv:~$ ./sample-rust 1 2 3 # this is a program I compiled with Ferrocene earlier
Hello
Arg  =
invalid args
Arg 0 = "./sample-rust"
Arg 1 = "1"
Arg 2 = "2"
Arg 3 = "3"
ubuntu@riscv:~$ file ./sample-rust
./sample-rust: ELF 64-bit LSB pie executable, UCB RISC-V, RVC, double-float ABI, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-riscv64-lp64d.so.1, BuildID[sha1]=f366420af49ba5f83b91cc4322e780655f1cb0cf, for GNU/Linux 4.15.0, with debug_info, not stripped

@jonathanpallant
Copy link
Contributor

jonathanpallant commented Nov 23, 2023

I can replicate the errors 23.10 though

  • rustup runs fine on 22.04 and 23.10
  • my sample-rust binary I built elsewhere runs on 22.04 and 23.10
  • rustc runs OK on 22.04 and on whatever platform we built the stdlib on

So what is rustc doing that offends the kernel in 23.10 so much?

$ gdb `which rustc`
(gdb) run -- /home/ubuntu/hello/src/main.rs
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/riscv64-linux-gnu/libthread_db.so.1".
process 3130 is executing new program: /home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/rustc
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/riscv64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffef823c40 (LWP 3132)]
[New Thread 0x7fffede1bc40 (LWP 3133)]
[New Thread 0x7fffedc1ac40 (LWP 3134)]
[New Thread 0x7fffec7fec40 (LWP 3135)]
[New Thread 0x7fffec5fdc40 (LWP 3136)]
[Thread 0x7fffec7fec40 (LWP 3135) exited]
[Thread 0x7fffec5fdc40 (LWP 3136) exited]

Thread 3 "rustc" received signal SIGUSR1, User defined signal 1.
[Switching to Thread 0x7fffede1bc40 (LWP 3133)]
syscall (syscall_number=98, arg1=<optimized out>, arg2=137, arg3=2, arg4=0,
    arg5=0, arg6=-1, arg7=98) at ../sysdeps/unix/sysv/linux/riscv/syscall.c:27
27	../sysdeps/unix/sysv/linux/riscv/syscall.c: No such file or directory.
(gdb) where
#0  syscall (syscall_number=98, arg1=<optimized out>, arg2=137, arg3=2,
    arg4=0, arg5=0, arg6=-1, arg7=98)
    at ../sysdeps/unix/sysv/linux/riscv/syscall.c:27
#1  0x00007ffff7f1e09e in std::sys::unix::futex::futex_wait ()
    at library/std/src/sys/unix/futex.rs:62
#2  std::sys::unix::locks::futex_condvar::Condvar::wait_optional_timeout ()
    at library/std/src/sys/unix/locks/futex_condvar.rs:49
#3  std::sys::unix::locks::futex_condvar::Condvar::wait ()
    at library/std/src/sys/unix/locks/futex_condvar.rs:33
#4  0x00007ffff4d2d230 in <jobserver::HelperState>::for_each_request::<jobserver::imp::spawn_helper::{closure#1}::{closure#0}> ()
   from /home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so
#5  0x00007ffff4d2f06e in std::sys_common::backtrace::__rust_begin_short_backtrace::<jobserver::imp::spawn_helper::{closure#1}, ()> ()
   from /home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so
#6  0x00007ffff4d2f0c2 in std::panicking::try::do_call::<core::panic::unwind_safe::AssertUnwindSafe<<std::thread::Builder>::spawn_unchecked_<jobserver::imp::spawn_helper::{closure#1}, ()>::{closure#1}::{closure#0}>, ()> ()
   from /home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so
#7  0x00007ffff4d2f8fa in __rust_try.llvm.14045574179110023769 ()
--Type <RET> for more, q to quit, c to continue without paging--
   from /home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so
#8  0x00007ffff4d3089e in <<std::thread::Builder>::spawn_unchecked_<jobserver::imp::spawn_helper::{closure#1}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} ()
   from /home/ubuntu/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so
#9  0x00007ffff7f1cbf0 in alloc::boxed::{impl#47}::call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global> ()
    at library/alloc/src/boxed.rs:2007
#10 alloc::boxed::{impl#47}::call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global> ()
    at library/alloc/src/boxed.rs:2007
#11 std::sys::unix::thread::{impl#2}::new::thread_start ()
    at library/std/src/sys/unix/thread.rs:108
#12 0x00007fffef908956 in start_thread (arg=<optimized out>)
    at ./nptl/pthread_create.c:444
#13 0x00007fffef959bf0 in __thread_start_clone3 ()
    at ../sysdeps/unix/sysv/linux/riscv/clone3.S:71

The last comment on #102155 seems to be the same issue (but not the OP, that was different).

libc thinks 98 is SYS_futex - https://docs.rs/libc/latest/riscv64gc-unknown-linux-gnu/libc/constant.SYS_futex.html

But Syscall 98 does not appear on https://jborza.com/post/2021-05-11-riscv-linux-syscalls/. Instead the Futex syscall is given as 422.

Edit:

Header agrees its 98 so that website is maybe just wrong.

ubuntu@riscv:/usr/include$ grep "__NR_futex" . -R
./riscv64-linux-gnu/bits/syscall.h:#ifdef __NR_futex
./riscv64-linux-gnu/bits/syscall.h:# define SYS_futex __NR_futex
./riscv64-linux-gnu/bits/syscall.h:#ifdef __NR_futex_time64
./riscv64-linux-gnu/bits/syscall.h:# define SYS_futex_time64 __NR_futex_time64
./riscv64-linux-gnu/bits/syscall.h:#ifdef __NR_futex_waitv
./riscv64-linux-gnu/bits/syscall.h:# define SYS_futex_waitv __NR_futex_waitv
./asm-generic/unistd.h:#define __NR_futex 98
./asm-generic/unistd.h:__SC_3264(__NR_futex, sys_futex_time32, sys_futex)
./asm-generic/unistd.h:#define __NR_futex_time64 422
./asm-generic/unistd.h:__SYSCALL(__NR_futex_time64, sys_futex)
./asm-generic/unistd.h:#define __NR_futex_waitv 449
./asm-generic/unistd.h:__SYSCALL(__NR_futex_waitv, sys_futex_waitv)

@jonathanpallant
Copy link
Contributor

jonathanpallant commented Nov 23, 2023

Ubuntu's own rustc doesn't work either, so it's not a glibc version thing.

ubuntu@riscv:~/hello$ which rustc
/usr/bin/rustc

ubuntu@riscv:~/hello$ rustc --version
rustc 1.71.1 (eb26296b5 2023-08-03) (built from a source tarball)

ubuntu@riscv:~/hello$ rustc ./src/main.rs
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x7d240c)[0x7fff8a3d240c]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x7fff8d839800]
/lib/riscv64-linux-gnu/libc.so.6(syscall+0x16)[0x7fff899e1406]
/lib/riscv64-linux-gnu/libstd-e74a09c2d8dfb358.so(_ZN3std3sys4unix5locks13futex_condvar7Condvar4wait17h02293b5d419ad109E+0x64)[0x7fff89b44c0a]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a92d42)[0x7fff8c692d42]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a93234)[0x7fff8c693234]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a95160)[0x7fff8c695160]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a95208)[0x7fff8c695208]
/lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so(+0x2a943ae)[0x7fff8c6943ae]
/lib/riscv64-linux-gnu/libstd-e74a09c2d8dfb358.so(rust_metadata_std_4809e9723d3e348c+0x7a798)[0x7fff89b03798]
/lib/riscv64-linux-gnu/libc.so.6(+0x6a956)[0x7fff89991956]
/lib/riscv64-linux-gnu/libc.so.6(+0xbbbf0)[0x7fff899e2bf0]

ubuntu@riscv:~/hello$

And it goes pop in the same place:

$ gdb rustc
(gdb) run -- src/main.rs
syscall (syscall_number=98, arg1=<optimized out>, arg2=137, arg3=2, arg4=0,
    arg5=0, arg6=-1, arg7=98) at ../sysdeps/unix/sysv/linux/riscv/syscall.c:27
27	../sysdeps/unix/sysv/linux/riscv/syscall.c: No such file or directory.
(gdb) where
#0  syscall (syscall_number=98, arg1=<optimized out>, arg2=137, arg3=2,
    arg4=0, arg5=0, arg6=-1, arg7=98)
    at ../sysdeps/unix/sysv/linux/riscv/syscall.c:27
#1  0x00007ffff42f6c7e in std::sys::unix::locks::futex_mutex::Mutex::lock_contended () from /lib/riscv64-linux-gnu/libstd-e74a09c2d8dfb358.so
#2  0x00007ffff6e92d42 in ?? ()
   from /lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so
#3  0x00007ffff6e93234 in ?? ()
   from /lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so
#4  0x00007ffff6e95160 in ?? ()
   from /lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so
#5  0x00007ffff6e95208 in ?? ()
   from /lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so
#6  0x00007ffff6e943ae in ?? ()
   from /lib/riscv64-linux-gnu/librustc_driver-192663414457c4de.so
#7  0x00007ffff4303798 in ?? ()
   from /lib/riscv64-linux-gnu/libstd-e74a09c2d8dfb358.so
#8  0x00007ffff4191956 in start_thread (arg=<optimized out>)
    at ./nptl/pthread_create.c:444
#9  0x00007ffff41e2bf0 in __thread_start_clone3 ()
    at ../sysdeps/unix/sysv/linux/riscv/clone3.S:71

@thejpster
Copy link
Contributor

So I booted the Ubuntu 22.04 image with a default 5.19 kernel (built from source) and that was fine. Then I built a 6.6 kernel and booted it with that and ... it was also fine. So it's not "new kernel changed something and broke futexes".

Then I booted Ubuntu 23.10 (with its default kernel) and that was still broken. So I tried 23.10 with my new custom 6.6 kernel and that was now fine!

ubuntu@ubuntu:~$ uname -a
Linux ubuntu 6.6.0 #3 SMP Thu Nov 23 23:22:59 GMT 2023 riscv64 riscv64 riscv64 GNU/Linux

ubuntu@ubuntu:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=23.10
DISTRIB_CODENAME=mantic
DISTRIB_DESCRIPTION="Ubuntu 23.10"

ubuntu@ubuntu:~$ rustc ./hello/src/main.rs

ubuntu@ubuntu:~$ ./main
Hello, world!

So there's something about the default kernel 6.5 in Ubuntu 23.10 that is broken, but that is fine if you build a defconfig vanilla 6.6 kernel.

I guess someone could grab the 6.5 kernel source from Ubuntu and build it from scratch. Maybe there's actually a bug in the Ubuntu GCC so it miscompiles the kernel? I'm using the GCC 12.2 from Debian 12 to cross-compile my kernels because that's what this test machine has on it.

It's looking fairly unlikely it's a rustc bug though. Or it would be a hell of a rustc bug if it only showed up on some kernel versions and not in others.

@tommythorn
Copy link

tommythorn commented Nov 24, 2023

There's a complicating factor. I tried running it under gdb catch the issue. I don't know if this is relevant but I no longer can reproduce the issue with the simple cargo new foo;cd foo;cargo run! However, a larger non-trivial projects still reproduces it. Same OS (Ubuntu 24.04), same kernel, same ld, etc. So, it seems to be a bit non-deterministic.

(Edited to reflect retesting with a larger example).

@tommythorn
Copy link

tommythorn commented Nov 24, 2023

@thejpster did you try running some bigger loads, say, cargo install ripgrep? I don't think rustc ./hello/src/main.rs is sufficient to conclude anything.

@jonathanpallant
Copy link
Contributor

Building a basic main.rs was a very reliable trigger on 23.10 with the stock kernel, but yeah, I can push it a bit and see. Perhaps you could also try a vanilla kernel and see if that helps?

@jonathanpallant
Copy link
Contributor

$ cargo install ripgrep
(much time passes - I only gave the VM 2GB of RAM)
   Installed package `ripgrep v13.0.0` (executable `rg`)
$ rg --version
ripgrep 13.0.0
-SIMD -AVX (compiled)
$ uname -a
Linux ubuntu 6.6.0 #3 SMP Thu Nov 23 23:22:59 GMT 2023 riscv64 riscvc64 riscv64 GNU/Linux
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=23.10
DISTRIB_CODENAME=mantic
DISTRIB_DESCRIPTION="Ubuntu 23.10"
$

@jonathanpallant
Copy link
Contributor

jonathanpallant commented Nov 24, 2023

Alright, I compiled a 6.5 kernel using Ubuntu's config (copied from /boot/config-6.5.0-9-generic) using the Debian compiler and it crashes rustc just like the stock 23.10 kernel does.

So there's something in Ubuntu's kernel 6.5 that isn't in the vanilla 6.6.

I guess I could try making a vanilla 6.5 - maybe the bug was fixed in 6.6? Then I could look at the diffs between the two.

But really at this point it really doesn't look like a rustc issue.

@jonathanpallant
Copy link
Contributor

ooooh, vanilla 6.5 crashes with a 23.10 disk image. So maybe it was fixed in 6.6 and it wasn't an Ubuntu specific bug.

@herrernst
Copy link

Addition to my report at #117022 (comment):
If someone needs info from a real device, I have a Mango Pi Pro running ubuntu-23.10-preinstalled-server-riscv64+nezha.img.xz:

$ uname -a
Linux rv 6.5.0-13-generic #13.1-Ubuntu SMP Wed Nov  8 10:32:38 UTC 2023 riscv64 riscv64 riscv64 GNU/Linux

$ cat /proc/cpuinfo 
processor	: 0
hart		: 0
isa		: rv64imafdc_zicntr_zicsr_zifencei_zihpm
mmu		: sv39
uarch		: thead,c906
mvendorid	: 0x5b7
marchid		: 0x0
mimpid		: 0x0

$ cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=23.10
DISTRIB_CODENAME=mantic
DISTRIB_DESCRIPTION="Ubuntu 23.10"

@thejpster
Copy link
Contributor

Are there any other kernels you could try? I've found 6.4 works and 6.6 works, so it seems a 6.5 specific issue.

@herrernst
Copy link

herrernst commented Nov 24, 2023

Sorry, I don't know how to compile and install kernels, let alone cross-arch. But maybe I will try with other pre-baked images.

One thing I've noticed though: With rust 1.73.0 as mentioned in #117022 (comment) I've "just" get a warning for every compilation step, but resulting binaries seem fine (e.g. ripgrep works).
But I've just updated to rust 1.74.0 (via rustup), and now I immediately get segfaults, even for simple example.rs (but it still compiles and runs).
So in rust also something must have changed between 1.73 and 1.74.

user@rv:~/src$ rustc -V
rustc 1.74.0 (79e9716c9 2023-11-13)
user@rv:~/src$ rustc example.rs 
error: rustc interrupted by SIGSEGV, printing backtrace

/home/user/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0xbcb99a)[0x3f7bbcb99a]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x3f83587800]
/lib/riscv64-linux-gnu/libc.so.6(syscall+0x16)[0x3f7af58406]
/home/user/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-3fecb5e5a54e748b.so(_ZN3std3sys4unix5locks13futex_condvar7Condvar4wait17hfe9ded54e8302796E+0x64)[0x3f834cb09e]
/home/user/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x532d230)[0x3f8032d230]
/home/user/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x532f06e)[0x3f8032f06e]
/home/user/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x532f0c2)[0x3f8032f0c2]
/home/user/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x532f8fa)[0x3f8032f8fa]
/home/user/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-32688bc33ce513ef.so(+0x533089e)[0x3f8033089e]
/home/user/.rustup/toolchains/stable-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-3fecb5e5a54e748b.so(rust_metadata_std_8ca29eab19a61e15+0xaebf0)[0x3f834c9bf0]
/lib/riscv64-linux-gnu/libc.so.6(+0x6a956)[0x3f7af08956]
/lib/riscv64-linux-gnu/libc.so.6(+0xbbbf0)[0x3f7af59bf0]

note: we would appreciate a report at https://github.com/rust-lang/rust
user@rv:~/src$ ls
example  example.rs
user@rv:~/src$ ./example #binary exists and runs!
Hello World!
user@rv:~/src$ rustup default 1.73-riscv64gc-unknown-linux-gnu
info: using existing install for '1.73-riscv64gc-unknown-linux-gnu'
info: default toolchain set to '1.73-riscv64gc-unknown-linux-gnu'

  1.73-riscv64gc-unknown-linux-gnu unchanged - rustc 1.73.0 (cc66ad468 2023-10-03)

user@rv:~/src$ rustc example.rs 
/home/user/.rustup/toolchains/1.73-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0xbb93a6)[0x3fb0bb93a6]
linux-vdso.so.1(__vdso_rt_sigreturn+0x0)[0x3fb83dd800]
/lib/riscv64-linux-gnu/libc.so.6(syscall+0x16)[0x3fafdee406]
/home/user/.rustup/toolchains/1.73-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-7c20a79be40626d5.so(_ZN3std3sys4unix5locks13futex_condvar7Condvar4wait17hb973eb74843e1e38E+0x64)[0x3faff46c9c]
/home/user/.rustup/toolchains/1.73-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ecc88)[0x3fb52ecc88]
/home/user/.rustup/toolchains/1.73-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ed3b6)[0x3fb52ed3b6]
/home/user/.rustup/toolchains/1.73-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52ed416)[0x3fb52ed416]
/home/user/.rustup/toolchains/1.73-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52edce8)[0x3fb52edce8]
/home/user/.rustup/toolchains/1.73-riscv64gc-unknown-linux-gnu/bin/../lib/librustc_driver-3ba4609cd58445ac.so(+0x52eeac0)[0x3fb52eeac0]
/home/user/.rustup/toolchains/1.73-riscv64gc-unknown-linux-gnu/bin/../lib/libstd-7c20a79be40626d5.so(rust_metadata_std_bf3dc212422480e+0xaf7e2)[0x3faff457e2]
/lib/riscv64-linux-gnu/libc.so.6(+0x6a956)[0x3fafd9e956]
/lib/riscv64-linux-gnu/libc.so.6(+0xbbbf0)[0x3fafdefbf0]
user@rv:~/src$ ./example 
Hello World!

Interestingly, I can even compile ripgrep in spite of the SIGSEGV messages, and it works.

@thejpster
Copy link
Contributor

I could easily believe that rustc started using futexes in another part of the compilation process and the bug seems to be around kernel handling of the futex syscall in kernel 6.5 specifically.

Has anyone seen it fail on anything other than kernel 6.5?

@apiraino
Copy link
Contributor

apiraino commented Dec 5, 2023

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 5, 2023
@jonathanpallant
Copy link
Contributor

We should probably open a bug upstream on Canonical's issue tracker, as their kernel seems pretty broken and folks are going to keep falling over this.

@jonathanpallant
Copy link
Contributor

jonathanpallant commented Dec 5, 2023

Well I bounced off their IRC support channel (who told me to read the page I had just read and which had sent me to the IRC channel).

I can only suggest running ubuntu-bug /var/crash/_usr_bin_rustc.1000.crash or similar after a rustc crash and maybe if enough people do it they'll notice and fix it. Ensure you sudo apt install whoopsie first.

@jonathanpallant
Copy link
Contributor

This may be https://bugs.launchpad.net/ubuntu-kernel-tests/+bug/2042388.

I updated to 6.5.0-14 which has a fix for that bug, and the issue went away. I was able to compile hello world without issue. Now leaving it compiling ripgrep (which takes about an hour).

@tommythorn
Copy link

Thank you. I apologize, it never occurred to me that it could have been a kernel bug. I think we can close this now as it's neither a rustc nor even a Rust bug.

@herrernst
Copy link

I can also confirm the bug is fixed for me on my SBC after upgrading kernel from 6.5.0-13 to 6.5.0-14 on Ubuntu 23.10.

For reference, here is also a bug report on upstream kernel: https://bugzilla.kernel.org/show_bug.cgi?id=217923

Fix seems to be included in Linux 6.6: https://lwn.net/Articles/947826/
Ubuntu probably has backported it now to 6.5.

Thanks for your work and information.

@apiraino
Copy link
Contributor

apiraino commented Dec 6, 2023

great work folks. Thanks for the follow-up on this issue.

Going to close as not-our-bug

@rustbot label -P-high -regression-stable-to-stable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. O-riscv Target: RISC-V architecture T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

10 participants