Skip to content

Commit 44a3a66

Browse files
committed
Stabilize asm! and global_asm!
They are also removed from the prelude as per the decision in rust-lang#87228. stdarch and compiler-builtins are updated to work with the new, stable asm! and global_asm! macros.
1 parent b3a5537 commit 44a3a66

File tree

123 files changed

+540
-1636
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+540
-1636
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,9 @@ dependencies = [
680680

681681
[[package]]
682682
name = "compiler_builtins"
683-
version = "0.1.55"
683+
version = "0.1.65"
684684
source = "registry+https://github.com/rust-lang/crates.io-index"
685-
checksum = "c9ac60765140c97aaf531dae151a287646b0805ec725805da9e2a3ee31cd501c"
685+
checksum = "ed37ea958309f2451e1cea7fd2b37aa56b1894c9a9fbdbbe6a194f7b78f0362d"
686686
dependencies = [
687687
"cc",
688688
"rustc-std-workspace-core",

compiler/rustc_codegen_gcc/tests/run/asm.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
// Run-time:
44
// status: 0
55

6-
#![feature(asm, global_asm)]
7-
86
global_asm!("
97
.global add_asm
108
add_asm:

compiler/rustc_lint/src/builtin.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,7 +3147,8 @@ declare_lint! {
31473147
/// ### Example
31483148
///
31493149
/// ```rust,compile_fail
3150-
/// #![feature(asm)]
3150+
/// use std::arch::asm;
3151+
///
31513152
/// fn main() {
31523153
/// unsafe {
31533154
/// asm!("foo: bar");
@@ -3164,10 +3165,7 @@ declare_lint! {
31643165
/// of this, GNU assembler [local labels] *must* be used instead of labels
31653166
/// with a name. Using named labels might cause assembler or linker errors.
31663167
///
3167-
/// See the [unstable book] for more details.
3168-
///
31693168
/// [local labels]: https://sourceware.org/binutils/docs/as/Symbol-Names.html#Local-Labels
3170-
/// [unstable book]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels
31713169
pub NAMED_ASM_LABELS,
31723170
Deny,
31733171
"named labels in inline assembly",

compiler/rustc_lint/src/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ pub trait LintContext: Sized {
772772
}
773773
BuiltinLintDiagnostics::NamedAsmLabel(help) => {
774774
db.help(&help);
775-
db.note("see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information");
775+
//db.note("see the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information");
776776
}
777777
}
778778
// Rewrap `db`, and pass control to the user.

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,8 +2419,8 @@ declare_lint! {
24192419
///
24202420
/// ### Example
24212421
///
2422-
/// ```rust,ignore (fails on system llvm)
2423-
/// #![feature(asm)]
2422+
/// ```rust
2423+
/// use std::arch::asm;
24242424
///
24252425
/// fn main() {
24262426
/// #[cfg(target_arch="x86_64")]
@@ -2430,19 +2430,7 @@ declare_lint! {
24302430
/// }
24312431
/// ```
24322432
///
2433-
/// This will produce:
2434-
///
2435-
/// ```text
2436-
/// warning: formatting may not be suitable for sub-register argument
2437-
/// --> src/main.rs:6:19
2438-
/// |
2439-
/// 6 | asm!("mov {0}, {0}", in(reg) 0i16);
2440-
/// | ^^^ ^^^ ---- for this argument
2441-
/// |
2442-
/// = note: `#[warn(asm_sub_register)]` on by default
2443-
/// = help: use the `x` modifier to have the register formatted as `ax`
2444-
/// = help: or use the `r` modifier to keep the default formatting of `rax`
2445-
/// ```
2433+
/// {{produces}}
24462434
///
24472435
/// ### Explanation
24482436
///
@@ -2455,10 +2443,6 @@ declare_lint! {
24552443
/// register size, to alert you of possibly using the incorrect width. To
24562444
/// fix this, add the suggested modifier to the template, or cast the
24572445
/// value to the correct size.
2458-
///
2459-
/// See [register template modifiers] for more details.
2460-
///
2461-
/// [register template modifiers]: https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#register-template-modifiers
24622446
pub ASM_SUB_REGISTER,
24632447
Warn,
24642448
"using only a subset of a register for inline asm inputs",
@@ -2470,34 +2454,21 @@ declare_lint! {
24702454
///
24712455
/// ### Example
24722456
///
2473-
/// ```rust,ignore (fails on system llvm)
2474-
/// #![feature(asm)]
2457+
/// ```rust
2458+
/// use std::arch::asm;
24752459
///
24762460
/// fn main() {
24772461
/// #[cfg(target_arch="x86_64")]
24782462
/// unsafe {
24792463
/// asm!(
24802464
/// ".att_syntax",
2481-
/// "movl {0}, {0}", in(reg) 0usize
2465+
/// "movq %{0}, %{0}", in(reg) 0usize
24822466
/// );
24832467
/// }
24842468
/// }
24852469
/// ```
24862470
///
2487-
/// This will produce:
2488-
///
2489-
/// ```text
2490-
/// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2491-
/// --> test.rs:7:14
2492-
/// |
2493-
/// 7 | ".att_syntax",
2494-
/// | ^^^^^^^^^^^
2495-
/// 8 | "movq {0}, {0}", out(reg) _,
2496-
/// 9 | );
2497-
/// | - help: add option: `, options(att_syntax)`
2498-
/// |
2499-
/// = note: `#[warn(bad_asm_style)]` on by default
2500-
/// ```
2471+
/// {{produces}}
25012472
///
25022473
/// ### Explanation
25032474
///
@@ -2739,7 +2710,8 @@ declare_lint! {
27392710
///
27402711
/// ```rust
27412712
/// #![feature(naked_functions)]
2742-
/// #![feature(asm)]
2713+
///
2714+
/// use std::arch::asm;
27432715
///
27442716
/// #[naked]
27452717
/// pub fn default_abi() -> u32 {

library/core/src/lib.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
#![feature(abi_unadjusted)]
153153
#![feature(allow_internal_unsafe)]
154154
#![feature(allow_internal_unstable)]
155-
#![feature(asm)]
156155
#![feature(associated_type_bounds)]
157156
#![feature(auto_traits)]
158157
#![feature(cfg_target_has_atomic)]
@@ -372,26 +371,14 @@ pub mod arch {
372371
pub use crate::core_arch::arch::*;
373372

374373
/// Inline assembly.
375-
///
376-
/// Read the [unstable book] for the usage.
377-
///
378-
/// [unstable book]: ../../unstable-book/library-features/asm.html
379-
#[unstable(
380-
feature = "asm",
381-
issue = "72016",
382-
reason = "inline assembly is not stable enough for use and is subject to change"
383-
)]
374+
#[stable(feature = "asm", since = "1.59.0")]
384375
#[rustc_builtin_macro]
385376
pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
386377
/* compiler built-in */
387378
}
388379
389380
/// Module-level inline assembly.
390-
#[unstable(
391-
feature = "global_asm",
392-
issue = "35119",
393-
reason = "`global_asm!` is not stable enough for use and is subject to change"
394-
)]
381+
#[stable(feature = "global_asm", since = "1.59.0")]
395382
#[rustc_builtin_macro]
396383
pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
397384
/* compiler built-in */

library/core/src/num/dec2flt/fpu.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub use fpu_precision::set_precision;
1010
// computations are performed in the desired precision.
1111
#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
1212
mod fpu_precision {
13+
use core::arch::asm;
1314
use core::mem::size_of;
1415

1516
/// A structure used to preserve the original value of the FPU control word, so that it can be

library/core/src/prelude/v1.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,6 @@ pub use crate::{
6969
#[doc(no_inline)]
7070
pub use crate::concat_bytes;
7171

72-
#[unstable(
73-
feature = "asm",
74-
issue = "72016",
75-
reason = "inline assembly is not stable enough for use and is subject to change"
76-
)]
77-
#[doc(no_inline)]
78-
pub use crate::arch::asm;
79-
80-
#[unstable(
81-
feature = "global_asm",
82-
issue = "35119",
83-
reason = "`global_asm!` is not stable enough for use and is subject to change"
84-
)]
85-
#[doc(no_inline)]
86-
pub use crate::arch::global_asm;
87-
8872
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
8973
#[allow(deprecated, deprecated_in_future)]
9074
#[doc(no_inline)]

library/panic_abort/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(std_internals)]
1515
#![feature(staged_api)]
1616
#![feature(rustc_attrs)]
17-
#![feature(asm)]
1817
#![feature(c_unwind)]
1918

2019
#[cfg(target_os = "android")]
@@ -69,11 +68,11 @@ pub unsafe extern "C-unwind" fn __rust_start_panic(_payload: *mut &mut dyn BoxMe
6968
const FAST_FAIL_FATAL_APP_EXIT: usize = 7;
7069
cfg_if::cfg_if! {
7170
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
72-
asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
71+
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
7372
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
74-
asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
73+
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
7574
} else if #[cfg(target_arch = "aarch64")] {
76-
asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
75+
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
7776
} else {
7877
core::intrinsics::abort();
7978
}

library/std/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ panic_unwind = { path = "../panic_unwind", optional = true }
1616
panic_abort = { path = "../panic_abort" }
1717
core = { path = "../core" }
1818
libc = { version = "0.2.108", default-features = false, features = ['rustc-dep-of-std'] }
19-
compiler_builtins = { version = "0.1.55" }
19+
compiler_builtins = { version = "0.1.65" }
2020
profiler_builtins = { path = "../profiler_builtins", optional = true }
2121
unwind = { path = "../unwind" }
2222
hashbrown = { version = "0.11", default-features = false, features = ['rustc-dep-of-std'] }

library/std/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@
233233
#![feature(allow_internal_unstable)]
234234
#![feature(arbitrary_self_types)]
235235
#![feature(array_error_internals)]
236-
#![feature(asm)]
237236
#![feature(assert_matches)]
238237
#![feature(associated_type_bounds)]
239238
#![feature(async_stream)]
@@ -288,7 +287,6 @@
288287
#![feature(gen_future)]
289288
#![feature(generator_trait)]
290289
#![feature(get_mut_unchecked)]
291-
#![feature(global_asm)]
292290
#![feature(hashmap_internals)]
293291
#![feature(int_error_internals)]
294292
#![feature(integer_atomics)]

library/std/src/os/fortanix_sgx/arch.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#![unstable(feature = "sgx_platform", issue = "56975")]
66

77
use crate::mem::MaybeUninit;
8+
use core::arch::asm;
89

910
/// Wrapper struct to force 16-byte alignment.
1011
#[repr(align(16))]

library/std/src/prelude/v1.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,6 @@ pub use core::prelude::v1::{
5454
#[doc(no_inline)]
5555
pub use core::prelude::v1::concat_bytes;
5656

57-
#[unstable(
58-
feature = "asm",
59-
issue = "72016",
60-
reason = "inline assembly is not stable enough for use and is subject to change"
61-
)]
62-
#[doc(no_inline)]
63-
pub use core::prelude::v1::asm;
64-
65-
#[unstable(
66-
feature = "global_asm",
67-
issue = "35119",
68-
reason = "`global_asm!` is not stable enough for use and is subject to change"
69-
)]
70-
#[doc(no_inline)]
71-
pub use core::prelude::v1::global_asm;
72-
7357
// FIXME: Attribute and internal derive macros are not documented because for them rustdoc generates
7458
// dead links which fail link checker testing.
7559
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]

library/std/src/sys/sgx/abi/mem.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use core::arch::asm;
2+
13
// Do not remove inline: will result in relocation failure
24
#[inline(always)]
35
pub(crate) unsafe fn rel_ptr<T>(offset: u64) -> *const T {

library/std/src/sys/sgx/abi/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![cfg_attr(test, allow(unused))] // RT initialization logic is not compiled for test
22

33
use crate::io::Write;
4+
use core::arch::global_asm;
45
use core::sync::atomic::{AtomicUsize, Ordering};
56

67
// runtime features

library/std/src/sys/solid/abi/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ pub fn breakpoint_program_exited(tid: usize) {
1010
match () {
1111
// SOLID_BP_PROGRAM_EXITED = 15
1212
#[cfg(target_arch = "arm")]
13-
() => asm!("bkpt #15", in("r0") tid),
14-
#[cfg(target_arch = "aarch64")]
15-
() => asm!("hlt #15", in("x0") tid),
13+
() => core::arch::asm!("bkpt #15", in("r0") tid),
14+
#[cfg(core::arch::asm = "aarch64")]
15+
() => core::arch::asm!("hlt #15", in("x0") tid),
1616
}
1717
}
1818
}
@@ -23,9 +23,9 @@ pub fn breakpoint_abort() {
2323
match () {
2424
// SOLID_BP_CSABORT = 16
2525
#[cfg(target_arch = "arm")]
26-
() => asm!("bkpt #16"),
26+
() => core::arch::asm!("bkpt #16"),
2727
#[cfg(target_arch = "aarch64")]
28-
() => asm!("hlt #16"),
28+
() => core::arch::asm!("hlt #16"),
2929
}
3030
}
3131
}

library/std/src/sys/windows/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,13 @@ pub fn abort_internal() -> ! {
288288
unsafe {
289289
cfg_if::cfg_if! {
290290
if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] {
291-
asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
291+
core::arch::asm!("int $$0x29", in("ecx") FAST_FAIL_FATAL_APP_EXIT);
292292
crate::intrinsics::unreachable();
293293
} else if #[cfg(all(target_arch = "arm", target_feature = "thumb-mode"))] {
294-
asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
294+
core::arch::asm!(".inst 0xDEFB", in("r0") FAST_FAIL_FATAL_APP_EXIT);
295295
crate::intrinsics::unreachable();
296296
} else if #[cfg(target_arch = "aarch64")] {
297-
asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
297+
core::arch::asm!("brk 0xF003", in("x0") FAST_FAIL_FATAL_APP_EXIT);
298298
crate::intrinsics::unreachable();
299299
}
300300
}

src/doc/unstable-book/src/compiler-flags/sanitizer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).
199199
## Example
200200
201201
```text
202-
#![feature(asm, naked_functions)]
202+
#![feature(naked_functions)]
203203
204204
use std::mem;
205205

0 commit comments

Comments
 (0)