Skip to content

Commit 8bcda8f

Browse files
committed
Add pointer authentication intrinsics
1 parent 17a520a commit 8bcda8f

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

compiler/rustc_codegen_llvm/src/context.rs

+8
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,14 @@ impl<'ll> CodegenCx<'ll, '_> {
931931
ifn!("llvm.va_end", fn(ptr) -> void);
932932
ifn!("llvm.va_copy", fn(ptr, ptr) -> void);
933933

934+
// pointer authentication intrinsics
935+
ifn!("llvm.ptrauth.sign.i64", fn(t_i64, t_i32, t_i64) -> t_i64);
936+
ifn!("llvm.ptrauth.auth.i64", fn(t_i64, t_i32, t_i64) -> t_i64);
937+
ifn!("llvm.ptrauth.strip.i64", fn(t_i64, t_i32) -> t_i64);
938+
ifn!("llvm.ptrauth.resign.i64", fn(t_i64, t_i32, t_i64, t_i32, t_i64) -> t_i64);
939+
ifn!("llvm.ptrauth.sign_generic.i64", fn(t_i64, t_i64) -> t_i64);
940+
ifn!("llvm.ptrauth.blend.i64", fn(t_i64, t_i64) -> t_i64);
941+
934942
if self.sess().instrument_coverage() {
935943
ifn!("llvm.instrprof.increment", fn(ptr, t_i64, t_i32, t_i32) -> void);
936944
}

compiler/rustc_codegen_llvm/src/intrinsic.rs

+19
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,25 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
295295
}
296296
}
297297

298+
sym::ptrauth_sign_key_asia
299+
| sym::ptrauth_sign_key_asib
300+
| sym::ptrauth_sign_key_asda
301+
| sym::ptrauth_sign_key_asdb => {
302+
303+
let key = self.const_i32(match name {
304+
sym::ptrauth_sign_key_asia => 0,
305+
sym::ptrauth_sign_key_asib => 1,
306+
sym::ptrauth_sign_key_asda => 2,
307+
sym::ptrauth_sign_key_asdb => 3,
308+
_ => bug!("Unknown PAuth key"),
309+
});
310+
311+
let value = args[0].immediate()
312+
let discriminator = args[1].immediate()
313+
314+
self.call_intrinsic("llvm.ptrauth.sign.i64", &[value, key, discriminator])
315+
}
316+
298317
sym::raw_eq => {
299318
use abi::Abi::*;
300319
let tp_ty = fn_args.type_at(0);

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+5
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
440440
None => bug!("`va_list` language item needed for C-variadic intrinsics"),
441441
},
442442

443+
ptrauth_sign_key_asda
444+
| ptrauth_sign_key_asdb
445+
| ptrauth_sign_key_asia
446+
| ptrauth_sign_key_asib => (0, vec![tcx.types.i64, tcx.types.i64], tcx.types.i64),
447+
443448
sym::nontemporal_store => {
444449
(1, vec![Ty::new_mut_ptr(tcx, param(0)), param(0)], Ty::new_unit(tcx))
445450
}

compiler/rustc_span/src/symbol.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,10 @@ symbols! {
12601260
ptr_write_bytes,
12611261
ptr_write_unaligned,
12621262
ptr_write_volatile,
1263+
ptrauth_sign_key_asda,
1264+
ptrauth_sign_key_asdb,
1265+
ptrauth_sign_key_asia,
1266+
ptrauth_sign_key_asib,
12631267
pub_macro_rules,
12641268
pub_restricted,
12651269
public,

0 commit comments

Comments
 (0)