-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Contents from global_asm! leak into other assemblies #81838
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
The example code above is mine, and I like it "leaking" as it allows me to use If #![feature(global_asm)]
const BAR: u64 = 10;
global_asm!("
.global bar
bar:
add x0, x0, {bar}
ret
", bar = const(BAR)); |
We do not want to support this behavior. This only exists in LLVM to support building the Linux kernel which relies on a lot of GCC internal details. However I'm less sure whether it's worth the trouble of messing with the CGU partitioning to actually enforce this. |
If it is not enforced, people will rely on this and various other non-obvious forms of this unintended feature. It will become stable by convention, even if we say this should not work and people should not rely on it. The only alternative I see is to keep |
The same issue happens with just #![feature(asm)]
const BAR: u64 = 10;
pub fn bar(mut v: u64) -> u64 {
unsafe {
asm!(r"
.macro foo, arg, size
add \arg, \size
.endm");
asm!("foo {v}, {}", const(BAR), v = inout(reg) v);
}
v
} |
As of Rust 1.86.0, the following code builds fine with fn main() {}
mod a {
core::arch::global_asm!(".macro foo", ".endm", "foo",);
}
mod b {
core::arch::global_asm!(".macro foo", ".endm", "foo",);
} Without the submodules it fails in either configuration. It seems that in some cases separate I'd like to be able to use a pattern like |
If two such |
You can use |
In code like this as noted here
the macro will leak into the inline
asm!
, but this is likely extremely brittle. For instance, Rust is free to split this module into 2 distinct CGUs, making the code like this mysteriously work or break.This could probably be mitigated by isolating all the
global_asm!
into its own CGU – that way none of the inline asm invocations would be able to observe theglobal_asm!
stuff. Alternatively, if we find we want to support this behaviour we would be forced to collect all uses ofglobal_asm!
and items containing inline asm in a crate into a single CGU. Supporting this would also have implications to alternative backend support.cc #35119
The text was updated successfully, but these errors were encountered: