Skip to main content

rustc_codegen_ssa/traits/
misc.rs

1use std::cell::RefCell;
2
3use rustc_data_structures::fx::FxHashMap;
4use rustc_middle::ty::{self, Instance, Ty};
5use rustc_session::Session;
6use rustc_span::Symbol;
7
8use super::BackendTypes;
9
10/// Strategy for incorporating address-based diversity into PAC computation.
11#[derive(#[automatically_derived]
impl ::core::default::Default for AddressDiversity {
    #[inline]
    fn default() -> AddressDiversity { Self::None }
}Default)]
12pub enum AddressDiversity {
13    /// No address diversity is applied.
14    #[default]
15    None,
16    /// Use the actual memory address for diversification.
17    Real,
18    /// Use a fixed synthetic value instead of the real address,
19    /// i.e. `1` is used for `.init_array` / `.fini_array`.
20    Synthetic(u64),
21}
22
23/// Metadata used for pointer authentication.
24pub struct PacMetadata {
25    /// The PAC key to use.
26    pub key: u32,
27    /// Discriminator value used to diversify the PAC.
28    pub disc: u64,
29    /// Controls how address diversity is applied when computing the PAC.
30    pub addr_diversity: AddressDiversity,
31}
32
33impl Default for PacMetadata {
34    fn default() -> Self {
35        PacMetadata { key: 0, disc: 0, addr_diversity: AddressDiversity::default() }
36    }
37}
38
39pub trait MiscCodegenMethods<'tcx>: BackendTypes {
40    fn vtables(
41        &self,
42    ) -> &RefCell<FxHashMap<(Ty<'tcx>, Option<ty::ExistentialTraitRef<'tcx>>), Self::Value>>;
43    fn apply_vcall_visibility_metadata(
44        &self,
45        _ty: Ty<'tcx>,
46        _poly_trait_ref: Option<ty::ExistentialTraitRef<'tcx>>,
47        _vtable: Self::Value,
48    ) {
49    }
50    fn get_fn(&self, instance: Instance<'tcx>) -> Self::Function;
51    fn get_fn_addr(&self, instance: Instance<'tcx>, pac: Option<PacMetadata>) -> Self::Value;
52    fn eh_personality(&self) -> Self::Function;
53    fn sess(&self) -> &Session;
54    fn set_frame_pointer_type(&self, llfn: Self::Function);
55    fn apply_target_cpu_attr(&self, llfn: Self::Function);
56    /// Declares the extern "C" main function for the entry point. Returns None if the symbol
57    /// already exists.
58    fn declare_c_main(&self, fn_type: Self::FunctionSignature) -> Option<Self::Function>;
59
60    /// Whether `codegen_intrinsic_call` expects to always have a `place_value`
61    /// when emitting code for the intrinsic `name`.
62    ///
63    /// This is discouraged, but here for now to simplify migration to using OperandValues
64    fn intrinsic_call_expects_place_always(&self, name: Symbol) -> bool;
65}