-
Notifications
You must be signed in to change notification settings - Fork 13.3k
met unrecognized instruction mnemonic error when naked function uses macro defined in global_asm! #134960
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
Comments
There is no guarantee that any assembler state is preserved between inline asm blocks. In fact if we could, we would explicitly prevent you from using this. As for why it no longer works in this case: It is possible that the naked function definition got moved to before the global asm, or to another codegen unit. |
I agree that there should not be a guarantee between inline |
No, it's intended for stuff like defining global constants or functions, not touching assembler state. It's explicitly documented that you must not modify or rely on assembler state: https://doc.rust-lang.org/stable/reference/inline-assembly.html#r-asm.ts-args.llvm-syntax |
Thank you, could you please tell me a better way to do this? And how does this change assembler state? .set REG_SIZE, 8
.macro load_gp i, basereg=t6
ld x\i, ((\i)*REG_SIZE)(\basereg)
.endm asm! asm: .set i, 1
.rept 31
load_gp %i, t6
.set i, i+1
.endr I want to keep these inside rust, not asm files. I'm trying to learn, but I just don't understand the things which changed between a few months ago where I last touched this code and it still worked and now. |
A macro adds a the macro definition to the assembler state.
these macros make the code order sensitive, so what probably happened is that some random thing in the compiler changed to order the stuff differently |
Seems like you can try what I suggested to do here. |
Thank you both, now I just have to figure out why .rept won't work, I probably should go do some more assembly programming |
I tried this code with
cargo b --target riscv64gc-unknown-none-elf
I expected to see this happen: the code compiles.
Instead, this happened: macro in global_asm! is not recognized in naked_asm!.
Actually the code does compile until nightly-2024-12-12. I use cargo-bisect-rustc to find out the regressed commit is 1daec06 , which points to #128004 .
Is this a desired behavior change? How could the code compile on latest nightly rustc?
BTW the code above compiles with
cargo check --target riscv64gc-unknown-none-elf
, why is that?Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: