Compile Error on AVR atmega328p with global_asm! in lib.rs #134758
Labels
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
O-AVR
Target: AVR processors (ATtiny, ATmega, etc.)
This is my first issue, so I'm not sure if this is the right place to report or if it is reported already.
Also formatting this issue is new to me ...
I'm on Rust with AVR atmega328p, using
nightly-2024-11-12-aarch64-unknown-linux-gnu (default)
rustc 1.84.0-nightly (81eef2d 2024-11-11)
I use "global_asm!" macro which compiles Ok in a bin main.rs and gives a compile error in a lib lib.rs.
The error is
error: :2:5: instruction requires a CPU feature not currently enabled
x:
jmp x
^
The source in both, main.rs and lib.rs is
//
global_asm!(r#"
x:
jmp x
"#);
To test, I have two crates, one to test as --bin with main.rs, one to test as --lib with lib.rs
Both crates have .cargo/config.toml
[build]
target = "avr-atmega328p.json"
[target.avr-atmega328p]
rustflags = [
#
"-Clink-arg=-nostartfiles",
]
[unstable]
build-std = ["core"]
Both have Config.toml
[package]
name = "..."
edition = "2021"
[dependencies]
[profile.release]
panic = "abort"
lto = true
The main.rs in the bin test crate :
//!
#![no_std]
#![no_main]
//
#![allow(unused_imports)]
//
#![feature(asm_experimental_arch)]
use core::arch::{ asm, global_asm };
//
global_asm!(r#"
x:
jmp x
"#);
///
use core::panic::PanicInfo;
#[panic_handler]
fn panic(panic: &PanicInfo<'>) -> ! {
loop {
}
}
... compiles and links fine !
The lib.rs in the lib test crate :
//!
#![no_std]
//
#![allow(unused_imports)]
//
#![feature(asm_experimental_arch)]
use core::arch::{ asm, global_asm };
//
global_asm!(r#"
x:
jmp x
"#);
... and gives compile error
error: :2:5: instruction requires a CPU feature not currently enabled
jmp x
^
Command for both crates is cargo build --release
./home/rust/rust-repos/rustc/rust/src/llvm-project/llvm/lib/Object/ModuleSymbolTable.cpp
I've tracked it down to llvm :
llvm-project/llvm/lib/Object/ModuleSymbolTable.cpp
static void initializeRecordStreamer(...)
{
...
std::unique_ptr STI(
T->createMCSubtargetInfo(TT.str(), "", ""));
...
}
The ("","") forces the feature map to go to the lowest for AVR and does not honor, that "atmega328p" features should be used.
Ich I patch it to
std::unique_ptr STI(
T->createMCSubtargetInfo(TT.str(), "atmega328p", ""));
it compiles fine :) But this is not a Solution
So here I stuck ...
br
xjn
The text was updated successfully, but these errors were encountered: