Skip to content

Commit

Permalink
stabilize naked_functions
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Dec 12, 2024
1 parent 4606a4d commit 6183807
Show file tree
Hide file tree
Showing 43 changed files with 150 additions and 279 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
#![feature(
no_core,
lang_items,
never_type,
linkage,
extern_types,
naked_functions,
thread_local,
repr_simd
)]
#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, repr_simd)]
#![no_core]
#![allow(dead_code, non_camel_case_types, internal_features)]

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0787.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ An unsupported naked function definition.
Erroneous code example:

```compile_fail,E0787
#![feature(naked_functions)]
#[naked]
pub extern "C" fn f() -> u32 {
42
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ declare_features! (
/// Allows patterns with concurrent by-move and by-ref bindings.
/// For example, you can write `Foo(a, ref b)` where `a` is by-move and `b` is by-ref.
(accepted, move_ref_pattern, "1.49.0", Some(68354)),
/// Allows using `#[naked]` on functions.
(accepted, naked_functions, "CURRENT_RUSTC_VERSION", Some(90957)),
/// Allows specifying modifiers in the link attribute: `#[link(modifiers = "...")]`
(accepted, native_link_modifiers, "1.61.0", Some(81490)),
/// Allows specifying the bundle link modifier
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
ungated!(unsafe no_mangle, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),
ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, EncodeCrossCrate::No),
ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, EncodeCrossCrate::Yes),
ungated!(naked, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No),

// Limits:
ungated!(
Expand Down Expand Up @@ -505,12 +506,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// Unstable attributes:
// ==========================================================================

// Linking:
gated!(
naked, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No,
naked_functions, experimental!(naked)
),

// Testing:
gated!(
test_runner, CrateLevel, template!(List: "path"), ErrorFollowing,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,6 @@ declare_features! (
(unstable, must_not_suspend, "1.57.0", Some(83310)),
/// Allows `mut ref` and `mut ref mut` identifier patterns.
(incomplete, mut_ref, "1.79.0", Some(123076)),
/// Allows using `#[naked]` on functions.
(unstable, naked_functions, "1.9.0", Some(90957)),
/// Allows specifying the as-needed link modifier
(unstable, native_link_modifiers_as_needed, "1.53.0", Some(81490)),
/// Allow negative trait implementations.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2923,7 +2923,7 @@ declare_lint! {
/// ### Example
///
/// ```rust
/// #![feature(asm_experimental_arch, naked_functions)]
/// #![feature(asm_experimental_arch)]
///
/// use std::arch::naked_asm;
///
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub macro asm("assembly template", $(operands,)* $(options($(option),*))?) {
///
/// [Rust By Example]: https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html
/// [reference]: https://doc.rust-lang.org/nightly/reference/inline-assembly.html
#[unstable(feature = "naked_functions", issue = "90957")]
#[stable(feature = "naked_functions", since = "CURRENT_RUSTC_VERSION")]
#[rustc_builtin_macro]
pub macro naked_asm("assembly template", $(operands,)* $(options($(option),*))?) {
/* compiler built-in */
Expand Down
6 changes: 2 additions & 4 deletions src/doc/unstable-book/src/compiler-flags/sanitizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.
## Example 1: Redirecting control flow using an indirect branch/call to an invalid destination
```rust,ignore (making doc tests pass cross-platform is hard)
#![feature(naked_functions)]

use std::arch::asm;
use std::arch::naked_asm;
use std::mem;

fn add_one(x: i32) -> i32 {
Expand All @@ -258,7 +256,7 @@ fn add_one(x: i32) -> i32 {
pub extern "C" fn add_two(x: i32) {
// x + 2 preceded by a landing pad/nop block
unsafe {
asm!(
naked_asm!(
"
nop
nop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
ungated!(no_mangle, Normal, template!(Word), WarnFollowing, @only_local: true),
ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, @only_local: true),
ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding),
ungated!(naked, Normal, template!(Word), WarnFollowing, @only_local: true),

// Limits:
ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
Expand Down Expand Up @@ -253,12 +254,6 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
// Unstable attributes:
// ==========================================================================

// Linking:
gated!(
naked, Normal, template!(Word), WarnFollowing, @only_local: true,
naked_functions, experimental!(naked)
),

// Testing:
gated!(
test_runner, CrateLevel, template!(List: "path"), ErrorFollowing, custom_test_frameworks,
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly/aarch64-naked-fn-no-bti-prolog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ only-aarch64

#![crate_type = "lib"]
#![feature(naked_functions)]

use std::arch::naked_asm;

// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions",
Expand Down
2 changes: 1 addition & 1 deletion tests/assembly/x86_64-naked-fn-no-cet-prolog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ only-x86_64

#![crate_type = "lib"]
#![feature(naked_functions)]

use std::arch::naked_asm;

// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions",
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/cffi/c-variadic-naked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#![crate_type = "lib"]
#![feature(c_variadic)]
#![feature(naked_functions)]
#![no_std]

#[naked]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/naked-asan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#![crate_type = "lib"]
#![no_std]
#![feature(abi_x86_interrupt, naked_functions)]
#![feature(abi_x86_interrupt)]

pub fn caller() {
page_fault_handler(1, 2);
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/naked-fn/aligned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ ignore-arm no "ret" mnemonic

#![crate_type = "lib"]
#![feature(naked_functions, fn_align)]
#![feature(fn_align)]
use std::arch::naked_asm;

// CHECK: .balign 16
Expand Down
1 change: 0 additions & 1 deletion tests/codegen/naked-fn/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//@ only-x86_64

#![crate_type = "lib"]
#![feature(naked_functions, asm_const)]

use std::arch::naked_asm;

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/naked-fn/instruction-set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//@ [thumb-mode] needs-llvm-components: arm

#![crate_type = "lib"]
#![feature(no_core, lang_items, rustc_attrs, naked_functions)]
#![feature(no_core, lang_items, rustc_attrs)]
#![no_core]

#[rustc_builtin_macro]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/naked-fn/naked-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//@[thumb] needs-llvm-components: arm

#![crate_type = "lib"]
#![feature(no_core, lang_items, rustc_attrs, naked_functions)]
#![feature(no_core, lang_items, rustc_attrs)]
#![no_core]

#[rustc_builtin_macro]
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/naked-symbol-visibility/a_rust_dylib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(naked_functions, linkage)]
#![feature(linkage)]
#![crate_type = "dylib"]

use std::arch::naked_asm;
Expand Down
1 change: 0 additions & 1 deletion tests/ui/asm/naked-asm-outside-naked-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//@ ignore-nvptx64
//@ ignore-spirv

#![feature(naked_functions)]
#![crate_type = "lib"]

use std::arch::naked_asm;
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/asm/naked-asm-outside-naked-fn.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error: the `naked_asm!` macro can only be used in functions marked with `#[naked]`
--> $DIR/naked-asm-outside-naked-fn.rs:21:14
--> $DIR/naked-asm-outside-naked-fn.rs:20:14
|
LL | unsafe { naked_asm!("") }
| ^^^^^^^^^^^^^^

error: the `naked_asm!` macro can only be used in functions marked with `#[naked]`
--> $DIR/naked-asm-outside-naked-fn.rs:26:18
--> $DIR/naked-asm-outside-naked-fn.rs:25:18
|
LL | unsafe { (|| naked_asm!(""))() }
| ^^^^^^^^^^^^^^

error: the `naked_asm!` macro can only be used in functions marked with `#[naked]`
--> $DIR/naked-asm-outside-naked-fn.rs:32:19
--> $DIR/naked-asm-outside-naked-fn.rs:31:19
|
LL | unsafe { naked_asm!("") } ;
| ^^^^^^^^^^^^^^
Expand Down
1 change: 0 additions & 1 deletion tests/ui/asm/naked-functions-ffi.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ check-pass
//@ needs-asm-support
#![feature(naked_functions)]
#![crate_type = "lib"]

use std::arch::naked_asm;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/asm/naked-functions-ffi.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: `extern` fn uses type `char`, which is not FFI-safe
--> $DIR/naked-functions-ffi.rs:9:28
--> $DIR/naked-functions-ffi.rs:8:28
|
LL | pub extern "C" fn naked(p: char) -> u128 {
| ^^^^ not FFI-safe
Expand All @@ -9,7 +9,7 @@ LL | pub extern "C" fn naked(p: char) -> u128 {
= note: `#[warn(improper_ctypes_definitions)]` on by default

warning: `extern` fn uses type `u128`, which is not FFI-safe
--> $DIR/naked-functions-ffi.rs:9:37
--> $DIR/naked-functions-ffi.rs:8:37
|
LL | pub extern "C" fn naked(p: char) -> u128 {
| ^^^^ not FFI-safe
Expand Down
1 change: 0 additions & 1 deletion tests/ui/asm/naked-functions-inline.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ needs-asm-support
#![feature(naked_functions)]
#![crate_type = "lib"]

use std::arch::naked_asm;
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/asm/naked-functions-inline.stderr
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
error[E0736]: attribute incompatible with `#[naked]`
--> $DIR/naked-functions-inline.rs:13:1
--> $DIR/naked-functions-inline.rs:12:1
|
LL | #[naked]
| -------- function marked with `#[naked]` here
LL | #[inline]
| ^^^^^^^^^ the `inline` attribute is incompatible with `#[naked]`

error[E0736]: attribute incompatible with `#[naked]`
--> $DIR/naked-functions-inline.rs:20:1
--> $DIR/naked-functions-inline.rs:19:1
|
LL | #[naked]
| -------- function marked with `#[naked]` here
LL | #[inline(always)]
| ^^^^^^^^^^^^^^^^^ the `inline` attribute is incompatible with `#[naked]`

error[E0736]: attribute incompatible with `#[naked]`
--> $DIR/naked-functions-inline.rs:27:1
--> $DIR/naked-functions-inline.rs:26:1
|
LL | #[naked]
| -------- function marked with `#[naked]` here
LL | #[inline(never)]
| ^^^^^^^^^^^^^^^^ the `inline` attribute is incompatible with `#[naked]`

error[E0736]: attribute incompatible with `#[naked]`
--> $DIR/naked-functions-inline.rs:34:19
--> $DIR/naked-functions-inline.rs:33:19
|
LL | #[naked]
| -------- function marked with `#[naked]` here
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/asm/naked-functions-instruction-set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ build-pass

#![crate_type = "lib"]
#![feature(no_core, lang_items, rustc_attrs, naked_functions)]
#![feature(no_core, lang_items, rustc_attrs)]
#![no_core]

#[rustc_builtin_macro]
Expand Down
1 change: 0 additions & 1 deletion tests/ui/asm/naked-functions-testattrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//@ compile-flags: --test

#![allow(undefined_naked_function_abi)]
#![feature(naked_functions)]
#![feature(test)]
#![crate_type = "lib"]

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/asm/naked-functions-testattrs.stderr
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
error[E0736]: cannot use `#[naked]` with testing attributes
--> $DIR/naked-functions-testattrs.rs:12:1
--> $DIR/naked-functions-testattrs.rs:11:1
|
LL | #[test]
| ------- function marked with testing attribute here
LL | #[naked]
| ^^^^^^^^ `#[naked]` is incompatible with testing attributes

error[E0736]: cannot use `#[naked]` with testing attributes
--> $DIR/naked-functions-testattrs.rs:20:1
--> $DIR/naked-functions-testattrs.rs:19:1
|
LL | #[test]
| ------- function marked with testing attribute here
LL | #[naked]
| ^^^^^^^^ `#[naked]` is incompatible with testing attributes

error[E0736]: cannot use `#[naked]` with testing attributes
--> $DIR/naked-functions-testattrs.rs:28:1
--> $DIR/naked-functions-testattrs.rs:27:1
|
LL | #[test]
| ------- function marked with testing attribute here
LL | #[naked]
| ^^^^^^^^ `#[naked]` is incompatible with testing attributes

error[E0736]: cannot use `#[naked]` with testing attributes
--> $DIR/naked-functions-testattrs.rs:35:1
--> $DIR/naked-functions-testattrs.rs:34:1
|
LL | #[bench]
| -------- function marked with testing attribute here
Expand Down
Loading

0 comments on commit 6183807

Please sign in to comment.