-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #98998 - workingjubilee:naked-means-no-clothes-enforc…
…ement-technology, r=Amanieu Remove branch target prologues from `#[naked] fn` This patch hacks around #98768 for now via injecting appropriate attributes into the LLVMIR we emit for naked functions. I intend to pursue this upstream so that these attributes can be removed in general, but it's slow going wading through C++ for me.
- Loading branch information
Showing
7 changed files
with
56 additions
and
1 deletion.
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
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,21 @@ | ||
// compile-flags: -C no-prepopulate-passes -Zbranch-protection=bti | ||
// assembly-output: emit-asm | ||
// needs-asm-support | ||
// only-aarch64 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(naked_functions)] | ||
use std::arch::asm; | ||
|
||
// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions", | ||
// meaning "no prologue whatsoever, no, really, not one instruction." | ||
// Unfortunately, aarch64's "branch target identification" works via hints at landing sites. | ||
// LLVM implements this via making sure of that, even for functions with the naked attribute. | ||
// So, we must emit an appropriate instruction instead! | ||
#[no_mangle] | ||
#[naked] | ||
pub unsafe extern "C" fn _hlt() -> ! { | ||
// CHECK-NOT: hint #34 | ||
// CHECK: hlt #0x1 | ||
asm!("hlt #1", 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// compile-flags: -C no-prepopulate-passes -Zcf-protection=full | ||
// assembly-output: emit-asm | ||
// needs-asm-support | ||
// only-x86_64 | ||
|
||
#![crate_type = "lib"] | ||
#![feature(naked_functions)] | ||
use std::arch::asm; | ||
|
||
// The problem at hand: Rust has adopted a fairly strict meaning for "naked functions", | ||
// meaning "no prologue whatsoever, no, really, not one instruction." | ||
// Unfortunately, x86's control-flow enforcement, specifically indirect branch protection, | ||
// works by using an instruction for each possible landing site, | ||
// and LLVM implements this via making sure of that. | ||
#[no_mangle] | ||
#[naked] | ||
pub unsafe extern "sysv64" fn will_halt() -> ! { | ||
// CHECK-NOT: endbr{{32|64}} | ||
// CHECK: hlt | ||
asm!("hlt", options(noreturn)) | ||
} | ||
|
||
// what about aarch64? | ||
// "branch-protection"=false |
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