Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile Error on AVR atmega328p with global_asm! in lib.rs #134758

Open
xjnxjnxjn opened this issue Dec 25, 2024 · 0 comments
Open

Compile Error on AVR atmega328p with global_asm! in lib.rs #134758

xjnxjnxjn opened this issue Dec 25, 2024 · 0 comments
Labels
needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. O-AVR Target: AVR processors (ATtiny, ATmega, etc.)

Comments

@xjnxjnxjn
Copy link

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

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 25, 2024
@jieyouxu jieyouxu added the O-AVR Target: AVR processors (ATtiny, ATmega, etc.) label Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. O-AVR Target: AVR processors (ATtiny, ATmega, etc.)
Projects
None yet
Development

No branches or pull requests

3 participants