about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorMatthew Maurer <matthew.r.maurer@gmail.com>2023-12-12 13:37:04 -0800
committerFlorian Schmiderer <florian.schmiderer@posteo.net>2024-06-25 18:23:41 +0200
commit9b0ae75ecc485d668232c9c85f0090fb85668312 (patch)
tree2ad4a6f802fb5eef10f7d15d6fe948a7499b72f8 /compiler/rustc_codegen_ssa/src
parentac7595fdb1ee2aafecdd99cd8a3e56192639ada6 (diff)
downloadrust-9b0ae75ecc485d668232c9c85f0090fb85668312.tar.gz
rust-9b0ae75ecc485d668232c9c85f0090fb85668312.zip
Support `#[patchable_function_entries]`
See [RFC](https://github.com/maurer/rust-rfcs/blob/patchable-function-entry/text/0000-patchable-function-entry.md) (yet to be numbered)

TODO before submission:
* Needs an RFC
* Improve error reporting for malformed attributes
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/codegen_attrs.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
index fb71cdaa8ff..8924ddb2aed 100644
--- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
+++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
@@ -5,7 +5,9 @@ use rustc_hir as hir;
 use rustc_hir::def::DefKind;
 use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
 use rustc_hir::{lang_items, weak_lang_items::WEAK_LANG_ITEMS, LangItem};
-use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
+use rustc_middle::middle::codegen_fn_attrs::{
+    CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry,
+};
 use rustc_middle::mir::mono::Linkage;
 use rustc_middle::query::Providers;
 use rustc_middle::ty::{self as ty, TyCtxt};
@@ -463,6 +465,28 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
                     None
                 };
             }
+            sym::patchable_function_entry => {
+                codegen_fn_attrs.patchable_function_entry = attr.meta_item_list().and_then(|l| {
+                    let mut prefix = 0;
+                    let mut entry = 0;
+                    for item in l {
+                        if let Some((sym, lit)) = item.name_value_literal() {
+                            let val = match lit.kind {
+                                // FIXME emit error if too many nops requested
+                                rustc_ast::LitKind::Int(i, _) => i as u8,
+                                _ => continue,
+                            };
+                            match sym {
+                                sym::prefix => prefix = val,
+                                sym::entry => entry = val,
+                                // FIXME possibly emit error here?
+                                _ => continue,
+                            }
+                        }
+                    }
+                    Some(PatchableFunctionEntry::from_prefix_and_entry(prefix, entry))
+                })
+            }
             _ => {}
         }
     }