forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report error when using naked functions with arguments
As mentioned in issue: rust-lang#42779 a naked function with arguments will cause LLVM to generate some prologue code for the arguments. This goes against the idea of a naked function and can cause difficult to diagnose bugs. The current situation is wrong and leaves users exposed to nasty bugs. There are two possible solutions: 1. Not allow any naked functions to have arguments. This is the method taken by this patch. 2. Modify LLVM to not generate any prologue code for naked functions. This seems like a more controversial change as it will impact all LLVM users and I am not sure how other languages will handle this. It seems unlikely that there are many naked functions that don't call inline assembly as the first or only code in the function. In which case the inline assembly can assess the registers used to pass arguments still allowing arguments to be passed to naked functions. Rust shouldn't be calling naked functions [1] so this is unlikely to be a major concern. 1: https://github.com/rust-lang/rfcs/blob/master/text/1201-naked-fns.md "Because the calling convention of a naked function is not guaranteed to match any calling convention the compiler is compatible with, calls to naked functions from within Rust code are forbidden unless the function is also declared with a well-defined ABI." Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
- Loading branch information
1 parent
a37fe2d
commit 95cf939
Showing
5 changed files
with
56 additions
and
66 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
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,12 @@ | ||
#![feature(asm, naked_functions)] | ||
|
||
#[naked] //~ ERROR E0051 | ||
#[no_mangle] | ||
#[inline(never)] | ||
pub extern "C" fn naked_test(_fubar: u64) { | ||
unsafe { asm!("int3") } | ||
} | ||
|
||
pub fn main() { | ||
naked_test(1); | ||
} |
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,9 @@ | ||
error[E0051]: unable to use `naked` on function with inputs | ||
--> $DIR/E0051.rs:3:1 | ||
| | ||
LL | #[naked] | ||
| ^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0051`. |