[SOLVED] SIGSEGV when trying to build minimal program for attiny85

Hello!

Absolute rust newbie here. I'm trying to compile an absolutely minimal program for an attiny85 micro controller. No development board, just a plain attiny85.
Unfortunately, I'll get a SIGSEGV in rustc-std-workspace-core when trying to compile. Those are the details:

± rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/markus/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu

active toolchain
----------------

nightly-x86_64-unknown-linux-gnu (directory override for '/home/markus/tmp/rust-playground/avr01')
rustc 1.69.0-nightly (0416b1a6f 2023-02-14)

Cargo.toml:

[package]
name = "avr01"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

[dependencies.attiny-hal]
git = "https://github.com/rahix/avr-hal"
version = "*"
features = ["attiny85"]

main.rs:

#![no_std]
#![no_main]

#[no_mangle]
pub extern fn main() {
}

#[panic_handler]
fn my_panic(_info: &core::panic::PanicInfo) -> ! {
    loop {}
}

I'm using the spec from avr-hal.

This is what happens:

± cargo build -Z build-std=core --target avr-attiny85.json 
    Blocking waiting for file lock on build directory
   Compiling compiler_builtins v0.1.87
   Compiling core v0.0.0 (/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling proc-macro2 v1.0.51
   Compiling unicode-ident v1.0.6
   Compiling quote v1.0.23
   Compiling syn v1.0.107
   Compiling rustversion v1.0.11
   Compiling proc-macro-hack v0.5.20+deprecated
   Compiling paste v1.0.11
   Compiling avr-hal-generic v0.1.0 (https://github.com/rahix/avr-hal#4c9c44c3)
   Compiling ufmt-macros v0.2.0
   Compiling rustc-std-workspace-core v1.99.0 (/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-0402d84ba5f47f34.so(+0x32c5e63)[0x14b8af8c5e63]
/lib/x86_64-linux-gnu/libc.so.6(+0x3bf90)[0x14b8ac45af90]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.69.0-nightly.so(_ZN4llvm12MachineInstr10addOperandERNS_15MachineFunctionERKNS_14MachineOperandE+0x1e6)[0x14b8aaa00542]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.69.0-nightly.so(+0x4c7d58c)[0x14b8aa27d58c]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.69.0-nightly.so(+0x4c7d2df)[0x14b8aa27d2df]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.69.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0xafd)[0x14b8aac4acd9]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.69.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x2f)[0x14b8aac4a1bb]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-15-rust-1.69.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x21a)[0x14b8aad544a0]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-0402d84ba5f47f34.so(+0x27bc892)[0x14b8aedbc892]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-0402d84ba5f47f34.so(+0x27bc2aa)[0x14b8aedbc2aa]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-0402d84ba5f47f34.so(+0x27ba4c5)[0x14b8aedba4c5]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-0402d84ba5f47f34.so(+0x27b767d)[0x14b8aedb767d]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-0402d84ba5f47f34.so(+0x27b65ff)[0x14b8aedb65ff]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-0402d84ba5f47f34.so(+0x27b55e0)[0x14b8aedb55e0]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-0402d84ba5f47f34.so(+0x26eff26)[0x14b8aeceff26]
/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libstd-67e0fe4bfa018a5e.so(rust_metadata_std_c4719229b53c8129+0x10ed23)[0x14b8b0b98d23]
/lib/x86_64-linux-gnu/libc.so.6(+0x88fd4)[0x14b8ac4a7fd4]
/lib/x86_64-linux-gnu/libc.so.6(+0x10966c)[0x14b8ac52866c]
   Compiling nb v1.0.0
   Compiling nb v0.1.3
   Compiling ufmt-write v0.1.0
   Compiling bare-metal v1.0.0
   Compiling vcell v0.1.3
   Compiling cfg-if v1.0.0
   Compiling void v1.0.2
   Compiling embedded-hal v0.2.7
   Compiling avr-device v0.5.0
   Compiling ufmt v0.1.2
error: could not compile `core`

Caused by:
  process didn't exit successfully: `rustc --crate-name core --edition=2021 /home/markus/.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,future-incompat --diagnostic-width=225 --crate-type lib --emit=dep-info,metadata,link -C panic=abort -C embed-bitcode=no -C debuginfo=2 -C metadata=d0c1272c4f5cdc4e -C extra-filename=-d0c1272c4f5cdc4e --out-dir /home/markus/tmp/rust-playground/avr01/target/avr-attiny85/debug/deps --target /home/markus/tmp/rust-playground/avr01/avr-attiny85.json -Z force-unstable-if-unmarked -L dependency=/home/markus/tmp/rust-playground/avr01/target/avr-attiny85/debug/deps -L dependency=/home/markus/tmp/rust-playground/avr01/target/debug/deps --cap-lints allow` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...

Since this happens when building rust core, I as an absolute beginner am a bit puzzled...

(Note that I'm only rust beginner. I have 30 years of programming experience, several years in the embedded world. Now an old dog wants to learn new tricks :slight_smile: )

It would be absolutely awesome if you could help me.
Thanks,

The Grue.

[AVR] compiler segfaults · Issue #107261 · rust-lang/rust · GitHub seems related.

Good news: after rustup update nightly today (i.e. rustc 1.69.0-nightly (4507fdaaa 2023-02-18) , this error is gone.
Now I have this error (no changes in the minimal code that I have described above):

± cargo clean
[:~/tmp/rust-playground/avr01] master* ± cargo build -Z build-std=core --target avr-attiny85.json 
   Compiling compiler_builtins v0.1.87
   Compiling core v0.0.0 (/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling proc-macro2 v1.0.51
   Compiling quote v1.0.23
   Compiling unicode-ident v1.0.6
   Compiling proc-macro-hack v0.5.20+deprecated
   Compiling syn v1.0.107
   Compiling rustversion v1.0.11
   Compiling paste v1.0.11
   Compiling avr-hal-generic v0.1.0 (https://github.com/rahix/avr-hal#4c9c44c3)
   Compiling ufmt-macros v0.2.0
   Compiling rustc-std-workspace-core v1.99.0 (/home/markus/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
error: ran out of registers during register allocation

error: could not compile `core` due to previous error

And it seems very much related to this "solved" issue:

Sigh…

Since they asked for it, I opened another ticket:

I have a working build now. The steps to fix it come from the github issue. I had to:

  • Add this to Cargo.toml
[profile.release]
lto = true
  • Make a release build:
cargo build -Z build-std=core --target avr-attiny85.json --release

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.