mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
Also stop emitting BTI prologues for naked functions
Same idea but for AArch64.
This commit is contained in:
parent
92174f988b
commit
530b5da49b
@ -303,6 +303,8 @@ pub fn from_fn_attrs<'ll, 'tcx>(
|
||||
// And it is a module-level attribute, so the alternative is pulling naked functions into new LLVM modules.
|
||||
// Otherwise LLVM's "naked" functions come with endbr prefixes per https://github.com/rust-lang/rust/issues/98768
|
||||
to_add.push(AttributeKind::NoCfCheck.create_attr(cx.llcx));
|
||||
// Need this for AArch64.
|
||||
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "branch-target-enforcement", "false"));
|
||||
}
|
||||
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR) {
|
||||
// apply to return place instead of function (unlike all other attributes applied in this function)
|
||||
|
21
src/test/assembly/aarch64-naked-fn-no-bti-prolog.rs
Normal file
21
src/test/assembly/aarch64-naked-fn-no-bti-prolog.rs
Normal file
@ -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))
|
||||
}
|
Loading…
Reference in New Issue
Block a user