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

Rust inline asm with generics and macros builds using --release, fails in debug #106838

Closed
danlehmann opened this issue Jan 14, 2023 · 3 comments
Closed
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug.

Comments

@danlehmann
Copy link

I tried this code:

use std::arch::{asm, global_asm};

global_asm!("
.macro test
.endm
");

fn function<const N: u32>() {
    unsafe {
        asm!("test", options(noreturn))
    }
}

fn main() {
    function::<1>()
}

I expected to see this happen: This code should work when compiling for release and debug.

Instead, this happened: It builds fine using --release. In debug mode, the inline assembler can't see the macro test.

I'd expect that either both Debug and Release work or that both fail equally.

~/CLionProjects/untitled1 % cargo run                                                   
   Compiling untitled1 v0.1.0 (/Users/daniel/CLionProjects/untitled1)
error: unrecognized instruction mnemonic, did you mean: tst?
  --> src/main.rs:11:15
   |
11 |         asm!("test", options(noreturn))
   |               ^
   |
note: instantiated into assembly here
  --> <inline asm>:1:2
   |
1  |     test
   |     ^

error: could not compile `untitled1` due to previous error



~/CLionProjects/untitled1 % cargo run --release
   Compiling untitled1 v0.1.0 (/Users/daniel/CLionProjects/untitled1)
    Finished release [optimized] target(s) in 0.10s
     Running `target/release/untitled1`

Meta

rustc --version --verbose:

rustc 1.68.0-nightly (3020239de 2023-01-09)
binary: rustc
commit-hash: 3020239de947ec52677e9b4e853a6a9fc073d1f9
commit-date: 2023-01-09
host: aarch64-apple-darwin
release: 1.68.0-nightly
LLVM version: 15.0.6

@danlehmann danlehmann added the C-bug Category: This is a bug. label Jan 14, 2023
@asquared31415
Copy link
Contributor

@rustbot label +A-inline-assembly

I did some poking and it seems to be tied to the presence of the -C incremental flag, which is passed by default in the default cargo debug profile.

@rustbot rustbot added the A-inline-assembly Area: Inline assembly (`asm!(…)`) label Jan 14, 2023
@asquared31415
Copy link
Contributor

oh this is an example of how #81838 can break

@Amanieu
Copy link
Member

Amanieu commented Apr 7, 2023

This is explicitly not supported by inline assembly:

If inline assembly includes any "stateful" directive that modifies how subsequent assembly is processed, the block must undo the effects of any such directives before the inline assembly ends.

Basically you can't rely on things defined in other asm blocks.

@Amanieu Amanieu closed this as completed Apr 7, 2023
c0per added a commit to Azure-stars/Starry that referenced this issue Jul 24, 2023
类似这个 issue 的问题:rust-lang/rust#106838

一个 asm!() 中定义的 macro 不保证能在另一个 asm!() 中使用。

在 debug 模式下编译时出现了编译错误,提示 macro 未知。
POP_GENERAL_REGS 和 LDR 等 macro 的定义位于 axhal,复制了一份到 axtask
中,解决了这个问题。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants