avr-rust / book.avr-rust.com

The AVR-Rust guidebook
https://book.avr-rust.com/
Other
75 stars 19 forks source link

Example blink program fails to build on WSL 2 - segfault while compiling core #27

Closed FrankvdStam closed 2 years ago

FrankvdStam commented 4 years ago

Was trying to create a new project with the guidebook, came across this error so I tried the blink example, same error. It segfaults when compiling core.

I'm running this on WSL 2, host is windows 10 version 10.0.19041.508.

Can I fetch you any logs/system specs to help?

Should not be related to the avr toolchain, I'm using Clion with WSL2 as well, building C projects directly with avr-gcc without issues.

Not sure if this is the right place for this issue, if not please point me in the right direction.

=========================================================================
Clone

frank@FrankDesktop:/mnt/c/projects/embedded$ git clone https://github.com/avr-rust/blink.git
Cloning into 'blink'...
remote: Enumerating objects: 56, done.
remote: Counting objects: 100% (56/56), done.
remote: Compressing objects: 100% (33/33), done.
remote: Total 132 (delta 21), reused 37 (delta 13), pack-reused 76
Receiving objects: 100% (132/132), 21.56 KiB | 1.44 MiB/s, done.
Resolving deltas: 100% (52/52), done.

=========================================================================
cd & setting nightly
frank@FrankDesktop:/mnt/c/projects/embedded$ cd blink
frank@FrankDesktop:/mnt/c/projects/embedded/blink$  rustup override set nightly
info: using existing install for 'nightly-x86_64-unknown-linux-gnu'
info: override toolchain for '/mnt/c/projects/embedded/blink' set to 'nightly-x86_64-unknown-linux-gnu'

  nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.48.0-nightly (99111606f 2020-09-11)

=========================================================================
build
frank@FrankDesktop:/mnt/c/projects/embedded/blink$ cargo build -Z build-std=core --target avr-atmega328p.json --release
  Downloaded bitflags v0.7.0
  Downloaded lazy_static v0.2.11
  Downloaded xmltree v0.4.0
  Downloaded ruduino v0.2.0
  Downloaded xml-rs v0.4.1
  Downloaded avr-mcu v0.2.6
  Downloaded 6 crates (3.5 MB) in 2.14s (largest was `avr-mcu` at 3.4 MB)
   Compiling bitflags v0.7.0
   Compiling lazy_static v0.2.11
   Compiling compiler_builtins v0.1.35
   Compiling core v0.0.0 (/home/frank/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling xml-rs v0.4.1
   Compiling xmltree v0.4.0
   Compiling avr-mcu v0.2.6
   Compiling ruduino v0.2.0
   Compiling rustc-std-workspace-core v1.99.0 (/home/frank/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
error: could not compile `core`

Caused by:
  process didn't exit successfully: `rustc --crate-name core --edition=2018 /home/frank/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=beaa6e4a1c2d7af3 -C extra-filename=-beaa6e4a1c2d7af3 --out-dir /mnt/c/projects/embedded/blink/target/avr-atmega328p/release/deps --target /mnt/c/projects/embedded/blink/avr-atmega328p.json -Z force-unstable-if-unmarked -L dependency=/mnt/c/projects/embedded/blink/target/avr-atmega328p/release/deps -L dependency=/mnt/c/projects/embedded/blink/target/release/deps --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
error: build failed
frank@FrankDesktop:/mnt/c/projects/embedded/blink$
dylanmckay commented 4 years ago

Hey @FrankvdStam

Very interesting failure

I'm running this on WSL 2, host is windows 10 version 10.0.19041.508.

Can I fetch you any logs/system specs to help?

Yes indeed - I'm not running Windows so it will be hard to reproduce. The main piece of logs that would help: the backtrace.

How to generate:

Two methods:

  1. Run the same 'cargo build' command but with GDB (i.e. gdb --args cargo build ...). NOTE: cargo build is only a driver that calls into Rustc, the error will be coming from rustc itself. GDB by default does not follow child processes and only debugs the top-level cargo invocation. Run set follow-fork-mode child and then run inside GDB to catch errors from Rustc.
  2. OR take the Rustc command that cargo gave back to you and run it again manually under gdb. I.e. gdb --args rustc --crate-name core --edition=2018 /home/frank/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=beaa6e4a1c2d7af3 -C extra-filename=-beaa6e4a1c2d7af3 --out-dir /mnt/c/projects/embedded/blink/target/avr-atmega328p/release/deps --target /mnt/c/projects/embedded/blink/avr-atmega328p.json -Z force-unstable-if-unmarked -L dependency=/mnt/c/projects/embedded/blink/target/avr-atmega328p/release/deps -L dependency=/mnt/c/projects/embedded/blink/target/release/deps --cap-lints allow. NOTE: Cargo will have deleted most of the tempdirs used in the Rustc invocation after Cargo failed. This means that invoking the same Rustc command again will fail with "directory not found" errors. The fix: you can safely drop a bunch of parameters from the Rustc call and use Rust defaults instead (for example, remove --error-format=json, --out-dir,-L dependency ...flags and Rustc will be able to work OR runcargo rustc -- -C save-tempsand the directories will be left around, allowing a second identicalrustc` invocation to pass.
FrankvdStam commented 4 years ago

Here's what I get with gdb:

frank@FrankDesktop:/mnt/c/projects/embedded/blink$ set follow-fork-mode child
frank@FrankDesktop:/mnt/c/projects/embedded/blink$ gdb --args cargo build -Z build-std=core --target avr-atmega328p.json --release
GNU gdb (Ubuntu 9.1-0ubuntu1) 9.1
Copyright (C) 2020 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-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...
(gdb) run
Starting program: /home/frank/.cargo/bin/cargo build -Z build-std=core --target avr-atmega328p.json --release
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
process 250 is executing new program: /home/frank/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7c29700 (LWP 254)]
[New Thread 0x7ffff7a28700 (LWP 255)]
[New Thread 0x7ffff7827700 (LWP 256)]
[New Thread 0x7ffff7623700 (LWP 257)]
   Compiling core v0.0.0 (/home/frank/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
[New Thread 0x7ffff741f700 (LWP 258)]
[New Thread 0x7ffff721b700 (LWP 259)]                                   ] 0/14: lazy_static, compiler_builtins(buil...
[Thread 0x7ffff7a28700 (LWP 255) exited]
[Thread 0x7ffff7827700 (LWP 256) exited]                                ] 2/14: compiler_builtins(build.rs), xml-rs...
[Thread 0x7ffff721b700 (LWP 259) exited]
[New Thread 0x7ffff701a700 (LWP 260)]
[Thread 0x7ffff7623700 (LWP 257) exited]                                ] 3/14: xmltree, compiler_builtins(build.rs...
[New Thread 0x7ffff6e19700 (LWP 261)]
[Thread 0x7ffff6e19700 (LWP 261) exited]
[Detaching after fork from child process 262]                           ] 5/14: xmltree, core
[Thread 0x7ffff701a700 (LWP 260) exited]
[New Thread 0x7ffff6c18700 (LWP 263)]
[Thread 0x7ffff6c18700 (LWP 263) exited]                                ] 6/14: avr-mcu, core
[New Thread 0x7ffff6a17700 (LWP 264)]
[Thread 0x7ffff6a17700 (LWP 264) exited]==>                             ] 7/14: ruduino(build.rs), core
[New Thread 0x7ffff6816700 (LWP 265)]
[Thread 0x7ffff6816700 (LWP 265) exited]
   Compiling rustc-std-workspace-core v1.99.0 (/home/frank/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
[New Thread 0x7ffff6615700 (LWP 267)]
[Detaching after fork from child process 268]=====>                     ] 9/14: rustc-std-workspace-core, core
   Compiling compiler_builtins v0.1.35
[New Thread 0x7ffff6414700 (LWP 277)]
[Detaching after fork from child process 280]=====>                     ] 9/14: rustc-std-workspace-core, core, com...
[Thread 0x7ffff6615700 (LWP 267) exited]=============>                 ] 10/14: core, compiler_builtins
error: [Thread 0x7ffff741f700 (LWP 258) exited]
could not compile `core`

Caused by:
  process didn't exit successfully: `rustc --crate-name core --edition=2018 /home/frank/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C metadata=286d5c86f0f152bc -C extra-filename=-286d5c86f0f152bc --out-dir /mnt/c/projects/embedded/blink/target/avr-atmega328p/release/deps --target /mnt/c/projects/embedded/blink/avr-atmega328p.json -Z force-unstable-if-unmarked -L dependency=/mnt/c/projects/embedded/blink/target/avr-atmega328p/release/deps -L dependency=/mnt/c/projects/embedded/blink/target/release/deps --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
[Thread 0x7ffff6414700 (LWP 277) exited]
--Type <RET> for more, q to quit, c to continue without paging--Quit
(gdb) aqRET> for more, q to quit, c to continue without paging--
Undefined command: "aq".  Try "help".
(gdb) q
A debugging session is active.

        Inferior 1 [process 250] will be killed.

Quit anyway? (y or n) n
Not confirmed.
(gdb) backtrace
#0  __pthread_disable_asynccancel () at ../sysdeps/unix/sysv/linux/x86_64/cancellation.S:83
#1  0x00007ffff7f9b38a in futex_wait_cancelable (private=<optimized out>, expected=0, futex_word=0x55555679e46c) at ../sysdeps/nptl/futex-internal.h:184
#2  __pthread_cond_wait_common (abstime=0x0, clockid=0, mutex=0x555556753b40, cond=0x55555679e440) at pthread_cond_wait.c:508
#3  __pthread_cond_wait (cond=0x55555679e440, mutex=0x555556753b40) at pthread_cond_wait.c:638
#4  0x0000555555f9874d in jobserver::HelperState::for_each_request ()
#5  0x0000555555f995dc in std::sys_common::backtrace::__rust_begin_short_backtrace ()
#6  0x0000555555f99208 in core::ops::function::FnOnce::call_once{{vtable-shim}} ()
#7  0x0000555555fdb19a in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/99111606fcda4fdb0646e4f7ee0f6cbcb76fb84a/library/alloc/src/boxed.rs:1042
#8  <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/99111606fcda4fdb0646e4f7ee0f6cbcb76fb84a/library/alloc/src/boxed.rs:1042
#9  std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:87
#10 0x00007ffff7f94609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#11 0x00007ffff7ea0103 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
(gdb)
FrankvdStam commented 4 years ago

Found this but I'm not sure it's related.

ahupp commented 3 years ago

I have the same issue, also on WSL2, debian bullseye. I'd be pretty surprised if this was truly related to running under WSL2 since that's basically a VM. But we all use the same kernel version and I wonder if there's an issue there.

This is the backtrace I get:

0x00007ffff07dfbc9 in llvm::MachineInstr::addRegisterDead(llvm::Register, llvm::TargetRegisterInfo const*, bool) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
(gdb) bt
#0  0x00007ffff07dfbc9 in llvm::MachineInstr::addRegisterDead(llvm::Register, llvm::TargetRegisterInfo const*, bool) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#1  0x00007ffff0740a78 in llvm::LiveIntervals::computeDeadValues(llvm::LiveInterval&, llvm::SmallVectorImpl<llvm::MachineInstr*>*) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#2  0x00007ffff0742082 in llvm::LiveIntervals::shrinkToUses(llvm::LiveInterval*, llvm::SmallVectorImpl<llvm::MachineInstr*>*) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#3  0x00007ffff075e896 in llvm::LiveRangeEdit::eliminateDeadDefs(llvm::SmallVectorImpl<llvm::MachineInstr*>&, llvm::ArrayRef<llvm::Register>, llvm::AAResults*) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#4  0x00007ffff070032d in (anonymous namespace)::HoistSpillHelper::hoistAllSpills() ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#5  0x00007ffff0902aa7 in llvm::RegAllocBase::postOptimization() ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#6  0x00007ffff090e517 in (anonymous namespace)::RAGreedy::runOnMachineFunction(llvm::MachineFunction&) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#7  0x00007ffff07d344e in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#8  0x00007ffff05adc92 in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#9  0x00007ffff05b46a3 in llvm::FPPassManager::runOnModule(llvm::Module&) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#10 0x00007ffff05ae6ea in llvm::legacy::PassManagerImpl::run(llvm::Module&) ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-11-rust-1.49.0-nightly.so
#11 0x00007ffff417a1f0 in LLVMRustWriteOutputFile ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9deb636e5c5c0be1.so
#12 0x00007ffff406452c in rustc_codegen_llvm::back::write::write_output_file ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9deb636e5c5c0be1.so
#13 0x00007ffff4069173 in rustc_codegen_llvm::back::write::codegen ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9deb636e5c5c0be1.so
#14 0x00007ffff409598b in rustc_codegen_ssa::back::write::finish_intra_module_work ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9deb636e5c5c0be1.so
#15 0x00007ffff408f188 in rustc_codegen_ssa::back::write::execute_work_item ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9deb636e5c5c0be1.so
#16 0x00007ffff3f8133f in std::sys_common::backtrace::__rust_begin_short_backtrace ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9deb636e5c5c0be1.so
#17 0x00007ffff4016b95 in core::ops::function::FnOnce::call_once{{vtable-shim}} ()
   from /home/ahupp/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-9deb636e5c5c0be1.so
#18 0x00007ffff33f486a in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once ()
    at /rustc/e160e5cb80652bc2afe74cb3affbe35b74243ea9/library/alloc/src/boxed.rs:1042
#19 <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once ()
    at /rustc/e160e5cb80652bc2afe74cb3affbe35b74243ea9/library/alloc/src/boxed.rs:1042
#20 std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:87
#21 0x00007ffff331eea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#22 0x00007ffff323beaf in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
dylanmckay commented 3 years ago

Likely not related to WSL but instead a duplicate of https://github.com/rust-lang/rust/issues/76930

FrankvdStam commented 2 years ago

I see that some work is being done on the other mentioned issue, might just want to close this and track progress there. I've since moved on to arm based MCU's and no longer use AVR based chips so it's not relevant for me anymore. I'll leave it up to you @dylanmckay if you want to leave this open.

stappersg commented 2 years ago

Closing this: