Closed
Description
rustc AVR support recently moved to an avr-none
target (#131651). While trying to update the avr-hal crate (Rahix/avr-hal#634) I discovered building for some cpus results in a linker error.
I've created a dependency-free reproducer at https://github.com/tones111/avr_bug
# rust-toolchain.toml
[toolchain]
channel = "nightly-2025-02-26"
components = [ "rust-src" ]
profile = "minimal"
# .cargo/config.toml
[build]
target = "avr-none"
# linking works
#rustflags = ["-C", "target-cpu=atmega328p"]
# avr architecture of input file `/tmp/rustcvmgbHY/symbols.o' is incompatible with avr:51 output
rustflags = ["-C", "target-cpu=atmega1280"]
[unstable]
build-std = ["core"]
# Cargo.toml
[package]
name = "avr-bug"
edition = "2021"
[profile.release]
panic = "abort"
codegen-units = 1
lto = true
opt-level = "s"
// src/main.rs
#![no_std]
#![no_main]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
#[export_name = "main"]
pub unsafe extern "C" fn __main() {
loop {}
}
Attempting to build ( cargo build --release
) results in a linker failure like
Compiling avr-bug v0.0.0 (/home/paul/src/avr_bug)
error: linking with `avr-gcc` failed: exit status: 1
|
= note: "avr-gcc" "/tmp/rustcpXMkWs/symbols.o" "<1 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "/home/paul/src/avr_bug/target/avr-none/release/deps/{librustc_std_workspace_core-58b27ec79d4fc03b.rlib,libcore-e5aabaa098bae4b6.rlib,libcompiler_builtins-7eca6f593cadd3a5.rlib}.rlib" "-Wl,-Bdynamic" "-lgcc" "-Wl,-z,noexecstack" "-o" "/home/paul/src/avr_bug/target/avr-none/release/deps/avr_bug-29daed87aec90e75.elf" "-Wl,--gc-sections" "-no-pie" "-mmcu=atmega1280" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: /usr/bin/avr-ld: avr architecture of input file `/tmp/rustcpXMkWs/symbols.o' is incompatible with avr:51 output
Building for atmega328p
works as expected. Adding -C default-linker-libraries
doesn't change the behavior. Targeting atmega2560 is also problematic.
tool versions
avr-gcc: 14.2.0
avr-libc: 2.2.1
avr-ld: GNU ld (GNU Binutils) 2.43
rustc: nightly-2025-02-26