Skip to content

Commit 59b042d

Browse files
committed
New signature of get_fn_addr, teach Rust how to sign fn pointers
Allow PAC metadata to be passed to `get_fn_addr` and related API changes.
1 parent 9ff44af commit 59b042d

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/common.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use gccjit::{LValue, RValue, ToRValue, Type};
22
use rustc_abi::Primitive::Pointer;
33
use rustc_abi::{self as abi, HasDataLayout};
44
use rustc_codegen_ssa::traits::{
5-
BaseTypeCodegenMethods, ConstCodegenMethods, MiscCodegenMethods, StaticCodegenMethods,
5+
BaseTypeCodegenMethods, ConstCodegenMethods, MiscCodegenMethods, PacMetadata,
6+
StaticCodegenMethods,
67
};
78
use rustc_middle::mir::Mutability;
89
use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar};
@@ -229,7 +230,13 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
229230
None
230231
}
231232

232-
fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, ty: Type<'gcc>) -> RValue<'gcc> {
233+
fn scalar_to_backend_with_pac(
234+
&self,
235+
cv: Scalar,
236+
layout: abi::Scalar,
237+
ty: Type<'gcc>,
238+
_pac: Option<PacMetadata>,
239+
) -> RValue<'gcc> {
233240
let bitsize = if layout.is_bool() { 1 } else { layout.size(self).bits() };
234241
match cv {
235242
Scalar::Int(int) => {
@@ -278,7 +285,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
278285
}
279286
value
280287
}
281-
GlobalAlloc::Function { instance, .. } => self.get_fn_addr(instance),
288+
GlobalAlloc::Function { instance, .. } => self.get_fn_addr(instance, None),
282289
GlobalAlloc::VTable(ty, dyn_ty) => {
283290
let alloc = self
284291
.tcx

src/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use gccjit::{Block, CType, Context, Function, FunctionType, LValue, Location, RV
55
use rustc_abi::{Align, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
66
use rustc_codegen_ssa::base::wants_msvc_seh;
77
use rustc_codegen_ssa::errors as ssa_errors;
8-
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, MiscCodegenMethods};
8+
use rustc_codegen_ssa::traits::{
9+
BackendTypes, BaseTypeCodegenMethods, MiscCodegenMethods, PacMetadata,
10+
};
911
use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN};
1012
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1113
use rustc_middle::mir::interpret::Allocation;
@@ -398,7 +400,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
398400
get_fn(self, instance)
399401
}
400402

401-
fn get_fn_addr(&self, instance: Instance<'tcx>) -> RValue<'gcc> {
403+
fn get_fn_addr(&self, instance: Instance<'tcx>, _pac: Option<PacMetadata>) -> RValue<'gcc> {
402404
let func_name = self.tcx.symbol_name(instance).name;
403405

404406
let func = if let Some(variable) = self.get_declared_value(func_name) {

0 commit comments

Comments
 (0)