Description
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 (81eef2d36 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: <inline asm>: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: <inline asm>: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<MCSubtargetInfo> 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<MCSubtargetInfo> STI(
T->createMCSubtargetInfo(TT.str(), "atmega328p", ""));
it compiles fine :) But this is not a Solution
So here I stuck ...
br
xjn