Rollup merge of #103168 - Amanieu:stable_asm_sym, r=davidtwco

Stabilize asm_sym

Tracking issue #93333

Reference PR: https://github.com/rust-lang/reference/pull/1270
This commit is contained in:
Yuki Okushi 2022-10-18 21:21:32 +09:00 committed by GitHub
commit 6e7d206a7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 61 additions and 114 deletions

View File

@ -192,16 +192,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}
InlineAsmOperand::Sym { ref sym } => {
if !self.tcx.features().asm_sym {
feature_err(
&sess.parse_sess,
sym::asm_sym,
*op_sp,
"sym operands for inline assembly are unstable",
)
.emit();
}
let static_def_id = self
.resolver
.get_partial_res(sym.id)

View File

@ -3,11 +3,12 @@
// Run-time:
// status: 0
#![feature(asm_const, asm_sym)]
#![feature(asm_const)]
use std::arch::{asm, global_asm};
global_asm!("
global_asm!(
"
.global add_asm
add_asm:
mov rax, rdi
@ -132,7 +133,9 @@ fn main() {
assert_eq!(x, 43);
// check sym fn
extern "C" fn foo() -> u64 { 42 }
extern "C" fn foo() -> u64 {
42
}
let x: u64;
unsafe {
asm!("call {}", sym foo, lateout("rax") x);

View File

@ -53,6 +53,8 @@ declare_features! (
(accepted, abi_sysv64, "1.24.0", Some(36167), None),
/// Allows using ADX intrinsics from `core::arch::{x86, x86_64}`.
(accepted, adx_target_feature, "1.61.0", Some(44839), None),
/// Allows using `sym` operands in inline assembly.
(accepted, asm_sym, "CURRENT_RUSTC_VERSION", Some(93333), None),
/// Allows the definition of associated constants in `trait` or `impl` blocks.
(accepted, associated_consts, "1.20.0", Some(29646), None),
/// Allows using associated `type`s in `trait`s.

View File

@ -300,8 +300,6 @@ declare_features! (
(active, asm_const, "1.58.0", Some(93332), None),
/// Enables experimental inline assembly support for additional architectures.
(active, asm_experimental_arch, "1.58.0", Some(93335), None),
/// Allows using `sym` operands in inline assembly.
(active, asm_sym, "1.58.0", Some(93333), None),
/// Allows the `may_unwind` option in inline assembly.
(active, asm_unwind, "1.58.0", Some(93334), None),
/// Allows users to enforce equality of associated constants `TraitImpl<AssocConst=3>`.

View File

@ -1,13 +0,0 @@
# `asm_sym`
The tracking issue for this feature is: [#93333]
[#93333]: https://github.com/rust-lang/rust/issues/93333
------------------------
This feature adds a `sym <path>` operand type to `asm!` and `global_asm!`.
- `<path>` must refer to a `fn` or `static`.
- A mangled symbol name referring to the item is substituted into the asm template string.
- The substituted string does not include any modifiers (e.g. GOT, PLT, relocations, etc).
- `<path>` is allowed to point to a `#[thread_local]` static, in which case the asm code can combine the symbol with relocations (e.g. `@plt`, `@TPOFF`) to read from thread-local data.

View File

@ -2,7 +2,7 @@
// compile-flags: --target aarch64-unknown-linux-gnu
// needs-llvm-components: aarch64
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]

View File

@ -3,7 +3,7 @@
// compile-flags: -C target-feature=+neon
// needs-llvm-components: arm
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]

View File

@ -2,7 +2,7 @@
// compile-flags: --target avr-unknown-gnu-atmega328
// needs-llvm-components: avr
#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(non_camel_case_types)]

View File

@ -2,7 +2,7 @@
// compile-flags: --target bpfel-unknown-none -C target_feature=+alu32
// needs-llvm-components: bpf
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]

View File

@ -4,7 +4,7 @@
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
// compile-flags: -C symbol-mangling-version=v0
#![feature(asm_const, asm_sym)]
#![feature(asm_const)]
#![crate_type = "rlib"]
use std::arch::global_asm;
@ -28,4 +28,6 @@ global_asm!("lea rax, [rip + {}]", sym MY_STATIC);
// CHECK: call _RNvCsiubXh4Yz005_10global_asm6foobar
global_asm!("call {}", sym foobar);
// CHECK: _RNvCsiubXh4Yz005_10global_asm6foobar:
fn foobar() { loop {} }
fn foobar() {
loop {}
}

View File

@ -2,7 +2,7 @@
// compile-flags: --target hexagon-unknown-linux-musl
// needs-llvm-components: hexagon
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]

View File

@ -5,7 +5,7 @@
//[mips64] compile-flags: --target mips64-unknown-linux-gnuabi64
//[mips64] needs-llvm-components: mips
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]

View File

@ -2,7 +2,7 @@
// compile-flags: --target msp430-none-elf
// needs-llvm-components: msp430
#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch, asm_const)]
#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch, asm_const)]
#![crate_type = "rlib"]
#![no_core]
#![allow(non_camel_case_types)]

View File

@ -3,7 +3,7 @@
// compile-flags: --crate-type cdylib
// needs-llvm-components: nvptx
#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch)]
#![no_core]
#[rustc_builtin_macro]

View File

@ -5,7 +5,7 @@
//[powerpc64] compile-flags: --target powerpc64-unknown-linux-gnu
//[powerpc64] needs-llvm-components: powerpc
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]

View File

@ -6,7 +6,7 @@
//[riscv32] needs-llvm-components: riscv
// compile-flags: -C target-feature=+d
#![feature(no_core, lang_items, rustc_attrs, asm_sym)]
#![feature(no_core, lang_items, rustc_attrs)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register)]

View File

@ -3,7 +3,7 @@
//[s390x] compile-flags: --target s390x-unknown-linux-gnu
//[s390x] needs-llvm-components: systemz
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym, asm_experimental_arch)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_experimental_arch)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]

View File

@ -3,7 +3,7 @@
// compile-flags: --crate-type cdylib
// needs-llvm-components: webassembly
#![feature(no_core, lang_items, rustc_attrs, asm_sym, asm_experimental_arch)]
#![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch)]
#![no_core]
#[rustc_builtin_macro]

View File

@ -7,7 +7,7 @@
// compile-flags: -C llvm-args=--x86-asm-syntax=intel
// compile-flags: -C target-feature=+avx512bw
#![feature(no_core, lang_items, rustc_attrs, repr_simd, asm_sym)]
#![feature(no_core, lang_items, rustc_attrs, repr_simd)]
#![crate_type = "rlib"]
#![no_core]
#![allow(asm_sub_register, non_camel_case_types)]

View File

@ -6,20 +6,30 @@
// ignore-arm
// ignore-aarch64
// needs-asm-support
#![feature(asm_sym)]
#[cfg(target_arch = "x86_64")]
pub extern "sysv64" fn all_the_registers(rdi: i64, rsi: i64, rdx: i64,
rcx: i64, r8 : i64, r9 : i64,
xmm0: f32, xmm1: f32, xmm2: f32,
xmm3: f32, xmm4: f32, xmm5: f32,
xmm6: f32, xmm7: f32) -> i64 {
pub extern "sysv64" fn all_the_registers(
rdi: i64,
rsi: i64,
rdx: i64,
rcx: i64,
r8: i64,
r9: i64,
xmm0: f32,
xmm1: f32,
xmm2: f32,
xmm3: f32,
xmm4: f32,
xmm5: f32,
xmm6: f32,
xmm7: f32,
) -> i64 {
assert_eq!(rdi, 1);
assert_eq!(rsi, 2);
assert_eq!(rdx, 3);
assert_eq!(rcx, 4);
assert_eq!(r8, 5);
assert_eq!(r9, 6);
assert_eq!(r8, 5);
assert_eq!(r9, 6);
assert_eq!(xmm0, 1.0f32);
assert_eq!(xmm1, 2.0f32);
assert_eq!(xmm2, 4.0f32);

View File

@ -1,7 +1,7 @@
// only-aarch64
// compile-flags: -C target-feature=+neon
#![feature(asm_const, asm_sym)]
#![feature(asm_const)]
use std::arch::asm;

View File

@ -2,7 +2,7 @@
// run-pass
// needs-asm-support
#![feature(asm_sym, asm_unwind)]
#![feature(asm_unwind)]
use std::arch::asm;
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};

View File

@ -3,7 +3,7 @@
// needs-asm-support
// run-pass
#![feature(thread_local, asm_sym)]
#![feature(thread_local)]
use std::arch::asm;

View File

@ -1,6 +1,6 @@
// only-aarch64
#![feature(repr_simd, never_type, asm_sym)]
#![feature(repr_simd, never_type)]
use std::arch::{asm, global_asm};

View File

@ -1,6 +1,6 @@
// only-aarch64
#![feature(repr_simd, never_type, asm_sym)]
#![feature(repr_simd, never_type)]
use std::arch::{asm, global_asm};

View File

@ -1,7 +1,7 @@
// needs-asm-support
// build-pass
#![feature(asm_const, asm_sym)]
#![feature(asm_const)]
use std::arch::asm;

View File

@ -4,7 +4,7 @@
// ignore-wasm32
#![feature(naked_functions)]
#![feature(asm_const, asm_sym, asm_unwind)]
#![feature(asm_const, asm_unwind)]
#![crate_type = "lib"]
use std::arch::asm;

View File

@ -3,7 +3,7 @@
// ignore-spirv
// ignore-wasm32
#![feature(asm_const, asm_sym)]
#![feature(asm_const)]
use std::arch::{asm, global_asm};

View File

@ -1,7 +1,7 @@
// only-x86_64
// compile-flags: -C target-feature=+avx2
#![feature(asm_const, asm_sym)]
#![feature(asm_const)]
use std::arch::asm;

View File

@ -7,8 +7,6 @@
// regression test for #96797
#![feature(asm_sym)]
use std::arch::global_asm;
#[no_mangle]

View File

@ -3,7 +3,7 @@
// needs-asm-support
// needs-unwind
#![feature(asm_sym, asm_unwind)]
#![feature(asm_unwind)]
use std::arch::asm;
use std::panic::{catch_unwind, resume_unwind, AssertUnwindSafe};

View File

@ -4,8 +4,6 @@
// Checks that multiple clobber_abi options can be used
#![feature(asm_sym)]
use std::arch::asm;
extern "sysv64" fn foo(x: i32) -> i32 {

View File

@ -3,7 +3,7 @@
// needs-asm-support
// run-pass
#![feature(thread_local, asm_sym)]
#![feature(thread_local)]
use std::arch::asm;

View File

@ -1,6 +1,6 @@
// only-x86_64
#![feature(repr_simd, never_type, asm_sym)]
#![feature(repr_simd, never_type)]
use std::arch::{asm, global_asm};

View File

@ -1,14 +1,13 @@
// only-x86_64
// compile-flags: -C target-feature=+avx512f
#![feature(asm_const, asm_sym)]
#![feature(asm_const)]
use std::arch::{asm, global_asm};
use std::arch::x86_64::{_mm256_setzero_ps, _mm_setzero_ps};
fn main() {
}
fn main() {}
// Constants must be... constant

View File

@ -1,5 +1,5 @@
error[E0013]: constants cannot refer to statics
--> $DIR/type-check-4.rs:22:25
--> $DIR/type-check-4.rs:21:25
|
LL | global_asm!("{}", const S);
| ^
@ -7,7 +7,7 @@ LL | global_asm!("{}", const S);
= help: consider extracting the value of the `static` to a `const`, and referring to that
error[E0013]: constants cannot refer to statics
--> $DIR/type-check-4.rs:25:35
--> $DIR/type-check-4.rs:24:35
|
LL | global_asm!("{}", const const_foo(S));
| ^
@ -15,7 +15,7 @@ LL | global_asm!("{}", const const_foo(S));
= help: consider extracting the value of the `static` to a `const`, and referring to that
error[E0013]: constants cannot refer to statics
--> $DIR/type-check-4.rs:28:35
--> $DIR/type-check-4.rs:27:35
|
LL | global_asm!("{}", const const_bar(S));
| ^

View File

@ -1,6 +1,6 @@
// only-x86_64
#![feature(repr_simd, never_type, asm_sym)]
#![feature(repr_simd, never_type)]
use std::arch::asm;

View File

@ -1,19 +0,0 @@
// only-x86_64
use std::arch::asm;
fn bar<const N: usize>() {}
fn foo<const N: usize>() {
unsafe {
asm!("mov eax, {}", sym bar::<N>);
//~^ ERROR sym operands for inline assembly are unstable
}
}
fn main() {
unsafe {
asm!("mov eax, {}", sym foo::<0>);
//~^ ERROR sym operands for inline assembly are unstable
}
}

View File

@ -1,21 +0,0 @@
error[E0658]: sym operands for inline assembly are unstable
--> $DIR/feature-gate-asm_sym.rs:9:29
|
LL | asm!("mov eax, {}", sym bar::<N>);
| ^^^^^^^^^^^^
|
= note: see issue #93333 <https://github.com/rust-lang/rust/issues/93333> for more information
= help: add `#![feature(asm_sym)]` to the crate attributes to enable
error[E0658]: sym operands for inline assembly are unstable
--> $DIR/feature-gate-asm_sym.rs:16:29
|
LL | asm!("mov eax, {}", sym foo::<0>);
| ^^^^^^^^^^^^
|
= note: see issue #93333 <https://github.com/rust-lang/rust/issues/93333> for more information
= help: add `#![feature(asm_sym)]` to the crate attributes to enable
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0658`.