Skip to content

Contents from global_asm! leak into other assemblies #81838

Open
@nagisa

Description

@nagisa

In code like this as noted here

#![feature(global_asm)]
#![feature(asm)]

global_asm!(r"
.macro foo, arg, size
  add \arg, \arg, \size
.endm");

const BAR: u64 = 10;

pub fn bar(mut v: u64) -> u64 {
    unsafe { 
        asm!("foo {v}, {}", const(BAR), v = inout(reg) v);
    }
    v
}

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 the global_asm! stuff. Alternatively, if we find we want to support this behaviour we would be forced to collect all uses of global_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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.F-asm`#![feature(asm)]` (not `llvm_asm`)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions