cargo: cargo build : failed to "SIGSEGV: invalid memory reference"

Problem I made new project A by using cargo new A, and then cd into A, there was an error when execute cargo build as shown below:

$ cargo build
   Compiling A v0.1.0 (/app01/users/magj/project/A)                                                                                                      
error: Could not compile `A`.                                                                                                                                             

To learn more, run the command again with --verbose.
$ cargo fix
    Checking A v0.1.0 (/app01/users/magj/project/A)                                                                                                      
child failed with signal `11`                                                                                                                                             
error: Could not compile `A`.                                                                                                                                             
warning: build failed, waiting for other jobs to finish...
child failed with signal `11`                                                                                                                                             
error: Could not compile `A`.                                                                                                                                             

To learn more, run the command again with --verbose.
$ cargo build --verbose
   Compiling A v0.1.0 (/app01/users/magj/project/A)                                                                                                      
     Running `rustc --edition=2018 --crate-name A src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=f597d7ad360532a8 -C extra-filename=-f597d7ad360532a8 --out-dir /app01//users/magj/project/A/target/debug/deps -C incremental=/app01/users/magj/project/A/target/debug/incremental -L dependency=/app01/users/magj/project/A/target/debug/deps`
error: Could not compile `A`.                                                                                                                                             

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name A src/main.rs --color always --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=f597d7ad360532a8 -C extra-filename=-f597d7ad360532a8 --out-dir /app01/users/magj/project/A/target/debug/deps -C incremental=/app01/users/magj/project/A/target/debug/incremental -L dependency=/app01/users/magj/project/A/target/debug/deps` (signal: 11, SIGSEGV: invalid memory reference)

$ gdb --args cargo build
GNU gdb (GDB) 7.10
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from cargo...done.
(gdb) run
Starting program: /app01/users/magj/bin/cargo build
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x2aaaacc00700 (LWP 56200)]                                                                                                                                   
[New Thread 0x2aaaace01700 (LWP 56201)]
   Compiling A v0.1.0 (/app01/users/magj/project/A)
[Thread 0x2aaaace01700 (LWP 56201) exited]                                                                                                                                

Program received signal SIGUSR1, User defined signal 1.
[Switching to Thread 0x2aaaacc00700 (LWP 56200)]
0x00002aaaab35b6d5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
(gdb) bt
#0  0x00002aaaab35b6d5 in pthread_cond_wait@@GLIBC_2.3.2 () from /lib64/libpthread.so.0
#1  0x0000555555e15163 in std::sys::unix::condvar::Condvar::wait::he5d25300ddf74601 () at libstd/sys/unix/condvar.rs:80
#2  std::sys_common::condvar::Condvar::wait::h36b32ede1d96b90b () at libstd/sys_common/condvar.rs:51
#3  std::sync::condvar::Condvar::wait::h4bc1b24c6087215a () at libstd/sync/condvar.rs:214
#4  std::thread::park::h4316a33db2f197df () at libstd/thread/mod.rs:820
#5  0x0000555555e0f892 in std::sync::mpsc::blocking::WaitToken::wait::hd5c4ebd205aa384b () at libstd/sync/mpsc/blocking.rs:81
#6  0x0000555555a40acd in _$LT$std..sync..mpsc..oneshot..Packet$LT$T$GT$$GT$::recv::hf03aac5aa501ba7e ()
#7  0x0000555555a3fa18 in _$LT$std..sync..mpsc..IntoIter$LT$T$GT$$u20$as$u20$core..iter..iterator..Iterator$GT$::next::h85a8d2011d6296d2 ()
#8  0x0000555555a435cd in std::sys_common::backtrace::__rust_begin_short_backtrace::hf94da93f63b244bf ()
#9  0x0000555555a4384e in std::panicking::try::do_call::hb9f2e6075a7c45ed ()
#10 0x0000555555e3830a in __rust_maybe_catch_panic () at libpanic_unwind/lib.rs:102
#11 0x0000555555a3c86f in _$LT$F$u20$as$u20$alloc..boxed..FnBox$LT$A$GT$$GT$::call_box::h517f8682259ec2ba ()
#12 0x0000555555e21f2e in _$LT$alloc..boxed..Box$LT$$LP$dyn$u20$alloc..boxed..FnBox$LT$A$C$$u20$Output$u3d$R$GT$$u20$$u2b$$u20$$u27$a$RP$$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::he3acfc8f1203786f () at liballoc/boxed.rs:682
#13 std::sys_common::thread::start_thread::h5213f803a61d7811 () at libstd/sys_common/thread.rs:24
#14 0x0000555555e0e396 in std::sys::unix::thread::Thread::new::thread_start::he89121f566d2a8c7 () at libstd/sys/unix/thread.rs:90
#15 0x00002aaaab357dc5 in start_thread () from /lib64/libpthread.so.0
#16 0x00002aaaab8781cd in clone () from /lib64/libc.so.6

Steps

Possible Solution(s)

Notes

Output of cargo version:

$ uname -a
Linux cs-test-app1 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 29 17:29:29 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux
$ cargo --version
cargo 1.31.0 (339d9f9c8 2018-11-16)
$ rustc --version
rustc 1.31.0 (abe02cefd 2018-12-04)

$ cat Cargo.toml 
[package]
name = "A"
version = "0.1.0"
authors = ["bill"]
edition = "2018"

[dependencies]

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 18 (7 by maintainers)

Most upvoted comments

Same problem here with RPi4. @ehuss’s suggestion worked:

[profile.release]
codegen-units=1

This code compiles well:

fn main() {
    let s1 = String::from("hello");

    println!("address {}.", *&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&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*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&*&s1);
}

Here are 2030 dereference operations. But 2031 operation (one more *&) raise an error SIGSEGV: invalid memory reference.

I’m getting this on raspi when doing --release builds

  • happens on raspi3 with 512M RAM but also on raspi4 with 4G RAM
  • dev builds are fine
  • reducing number of jobs doesn’t help
  • happens on regular project but also on cargo new hello
  • lto: false doesn’t help
cargo --version
cargo 1.38.0 (23ef9a4ef 2019-08-20)

rustc --version
rustc 1.38.0 (625451e37 2019-09-23)

I can provide any other info if you tell me how to get it 😃

ARM toolchain issue has been fixed on nightly so codegen-units=1 is no longer required there. If everything goes as expected next stable release will be fixed.

OP issue cause is still unknown.

Had this error only when compiling with --release in a Raspberry Pi 3 with a 64 bits kernel. codegen-units=1 also solved it for me. I am running rustc 1.40.

@cztomsik Have you tried getting a core dump? Can you tell if it is cargo or rustc that is crashing? If it is rustc, I would suggest filing an issue at https://github.com/rust-lang/rust/issues with any backtrace information you can provide. Have you looked at some of the open issues like https://github.com/rust-lang/rust/issues/62896/? Have you tried setting codegen-units=1?