rust-lang / rust-lang/rust

SIGILL compiler crash when using AVR inline assembly

Open
#132,158 14 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-LLVM C-bug I-crash O-AVR T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
#![no_std]
#![no_main]
#![feature(asm_experimental_arch)]

use core::{panic::PanicInfo, arch::asm};

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

#[no_mangle]
pub extern "C" fn main() {
    let target: *mut u8 = 0x0025 as *mut u8;
    let value: u8 = 0;
    unsafe {
        asm!(
            "st {port}, {value}",
            port = in(reg_ptr) target,
            value = in(reg) value,
        );
    }
    panic!()
}
Meta

rustc --version --verbose:

rustc 1.84.0-nightly (a93c1718c 2024-10-24)
binary: rustc
commit-hash: a93c1718c80b9f100056c8eec3fc37fbd6424134
commit-date: 2024-10-24
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
Error output
error: could not compile `avr-project` (bin "avr-project")

Caused by:
  process didn't exit successfully: `/home/ondre/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name avr_project --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=186 --crate-type bin --emit=dep-info,link -C opt-level=3 -C panic=abort -C lto -C codegen-units=1 --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=3c8db77931085eba -C extra-filename=-3c8db77931085eba --out-dir /home/ondre/avrlibstest/target/avr-atmega328p/release/deps --target /home/ondre/avrlibstest/avr-atmega328p.json -C strip=debuginfo -L dependency=/home/ondre/avrlibstest/target/avr-atmega328p/release/deps -L dependency=/home/ondre/avrlibstest/target/release/deps --extern 'noprelude:compiler_builtins=/home/ondre/avrlibstest/target/avr-atmega328p/release/deps/libcompiler_builtins-013c779640681efb.rlib' --extern 'noprelude:core=/home/ondre/avrlibstest/target/avr-atmega328p/release/deps/libcore-1167638d3e17fa03.rlib' -Z unstable-options` (signal: 4, SIGILL: illegal instruction)
Project config

In file rust-toolchain.toml:

[toolchain]
channel = "nightly"

In file .cargo/config.toml:

[build]
target = "avr-atmega328p.json"

[unstable]
build-std = ["core"]

In file avr-atmega328p.json:

{
  "arch": "avr",
  "atomic-cas": false,
  "cpu": "atmega328p",
  "crt-objects-fallback": "false",
  "data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
  "eh-frame-header": false,
  "env": "gnu",
  "exe-suffix": ".elf",
  "late-link-args": {
    "gnu-cc": [
      "-lgcc"
    ],
    "gnu-lld-cc": [
      "-lgcc"
    ]
  },
  "linker": "avr-gcc",
  "linker-flavor": "gnu-cc",
  "llvm-target": "avr-unknown-unknown",
  "max-atomic-width": 16,
  "metadata": {
    "description": null,
    "host_tools": null,
    "std": null,
    "tier": null
  },
  "pre-link-args": {
    "gnu-cc": [
      "-mmcu=atmega328p"
    ],
    "gnu-lld-cc": [
      "-mmcu=atmega328p"
    ]
  },
  "relocation-model": "static",
  "target-c-int-width": "16",
  "target-pointer-width": "16"
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the crash using the inline assembly in src/main.rs with rust-toolchain.toml, .cargo/config.toml, and avr-atmega328p.json. Start by examining AVR target compilation and inline-assembly handling, then verify that the supplied build no longer terminates with SIGILL.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, embedded-iot
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.