forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#93153 - tmiasko:reject-unsupported-naked-fu…
…nctions, r=Amanieu Reject unsupported naked functions Transition unsupported naked functions future incompatibility lint into an error: * Naked functions must contain a single inline assembly block. Introduced as future incompatibility lint in 1.50 rust-lang#79653. Change into an error fixes a soundness issue described in rust-lang#32489. * Naked functions must not use any forms of inline attribute. Introduced as future incompatibility lint in 1.56 rust-lang#87652. Closes rust-lang#32490. Closes rust-lang#32489. r? ``@Amanieu`` ``@npmccallum`` ``@joshtriplett``
- Loading branch information
Showing
9 changed files
with
183 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
An unsupported naked function definition. | ||
|
||
Erroneous code example: | ||
|
||
```compile_fail,E0787 | ||
#![feature(naked_functions)] | ||
#[naked] | ||
pub extern "C" fn f() -> u32 { | ||
42 | ||
} | ||
``` | ||
|
||
The naked functions must be defined using a single inline assembly | ||
block. | ||
|
||
The execution must never fall through past the end of the assembly | ||
code so the block must use `noreturn` option. The asm block can also | ||
use `att_syntax` and `raw` options, but others options are not allowed. | ||
|
||
The asm block must not contain any operands other than `const` and | ||
`sym`. | ||
|
||
### Additional information | ||
|
||
For more information, please see [RFC 2972]. | ||
|
||
[RFC 2972]: https://github.com/rust-lang/rfcs/blob/master/text/2972-constrained-naked.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,32 @@ | ||
// compile-flags: -C no-prepopulate-passes | ||
// needs-asm-support | ||
// only-x86_64 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(naked_functions)] | ||
use std::arch::asm; | ||
|
||
// CHECK: Function Attrs: naked | ||
// CHECK-NEXT: define{{.*}}void @naked_empty() | ||
#[no_mangle] | ||
#[naked] | ||
pub fn naked_empty() { | ||
pub unsafe extern "C" fn naked_empty() { | ||
// CHECK-NEXT: {{.+}}: | ||
// CHECK-NEXT: ret void | ||
// CHECK-NEXT: call void asm | ||
// CHECK-NEXT: unreachable | ||
asm!("ret", | ||
options(noreturn)); | ||
} | ||
|
||
// CHECK: Function Attrs: naked | ||
// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_args_and_return(i64 %a, i64 %b) | ||
#[no_mangle] | ||
#[naked] | ||
// CHECK-NEXT: define{{.*}}void @naked_with_args(i{{[0-9]+( %a)?}}) | ||
pub fn naked_with_args(a: isize) { | ||
pub unsafe extern "C" fn naked_with_args_and_return(a: isize, b: isize) -> isize { | ||
// CHECK-NEXT: {{.+}}: | ||
// CHECK: ret void | ||
} | ||
|
||
// CHECK: Function Attrs: naked | ||
// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_return() | ||
#[no_mangle] | ||
#[naked] | ||
pub fn naked_with_return() -> isize { | ||
// CHECK-NEXT: {{.+}}: | ||
// CHECK-NEXT: ret i{{[0-9]+}} 0 | ||
0 | ||
} | ||
|
||
// CHECK: Function Attrs: naked | ||
// CHECK-NEXT: define{{.*}}i{{[0-9]+}} @naked_with_args_and_return(i{{[0-9]+( %a)?}}) | ||
#[no_mangle] | ||
#[naked] | ||
pub fn naked_with_args_and_return(a: isize) -> isize { | ||
// CHECK-NEXT: {{.+}}: | ||
// CHECK: ret i{{[0-9]+}} 0 | ||
0 | ||
// CHECK-NEXT: call void asm | ||
// CHECK-NEXT: unreachable | ||
asm!("lea rax, [rdi + rsi]", | ||
"ret", | ||
options(noreturn)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
|
||
use std::arch::asm; | ||
|
||
#[inline(always)] | ||
#[naked] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn f() { | ||
|
Oops, something went wrong.