rust/compiler/rustc_middle/src
Matthias Krüger accf61dd42
Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errors
fix `-Zsanitizer=kcfi` on `#[naked]` functions

fixes https://github.com/rust-lang/rust/issues/143266

With `-Zsanitizer=kcfi`, indirect calls happen via generated intermediate shim that forwards the call. The generated shim preserves the attributes of the original, including `#[unsafe(naked)]`. The shim is not a naked function though, and violates its invariants (like having a body that consists of a single `naked_asm!` call).

My fix here is to match on the `InstanceKind`, and only use `codegen_naked_asm` when the instance is not a `ReifyShim`. That does beg the question whether there are other `InstanceKind`s that could come up. As far as I can tell the answer is no: calling via `dyn` seems to work find, and `#[track_caller]` is disallowed in combination with `#[naked]`.

r? codegen
````@rustbot```` label +A-naked
cc ````@maurer```` ````@rcvalle````
2025-07-18 04:27:51 +02:00
..
dep_graph Reuse metadata file from work products. 2025-07-04 14:02:17 +00:00
hir parse const trait Trait 2025-07-17 18:06:26 +08:00
hooks Move naked fn checks to hir_typeck 2025-05-30 16:08:44 +00:00
infer yeet CanonicalVarInfo 2025-05-23 12:10:53 +00:00
middle use codegen_instance_attrs where an instance is (easily) available 2025-07-16 23:24:32 +02:00
mir Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errors 2025-07-18 04:27:51 +02:00
query Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-errors 2025-07-18 04:27:51 +02:00
thir loop match: run exhaustiveness check 2025-07-01 15:53:50 +02:00
traits Auto merge of #142911 - mejrs:unsized, r=compiler-errors 2025-07-11 05:27:32 +00:00
ty Auto merge of #141762 - compiler-errors:witnesser, r=lcnr 2025-07-17 20:02:22 +00:00
util Remove attribute #[rustc_error] 2025-03-30 01:32:21 +03:00
arena.rs Define datastructures for #[cfg] attribute, move StrippedCfgItem 2025-07-15 09:01:00 +02:00
error.rs const-eval: allow constants to refer to mutable/external memory, but reject such constants as patterns 2025-06-26 18:09:47 +02:00
lib.rs Update cfg(bootstrap) 2025-07-01 10:55:49 -07:00
lint.rs decouple "reporting in deps" from future incompatibility reason 2025-06-03 10:49:22 +02:00
macros.rs Fold visit into ty 2025-03-15 06:34:36 +00:00
metadata.rs Re-export more rustc_span::symbol things from rustc_span. 2024-12-18 13:38:53 +11:00
tests.rs Give an item related to issue 27438 a more meaningful name 2024-04-30 22:27:19 +02:00
thir.rs loop match: run exhaustiveness check 2025-07-01 15:53:50 +02:00
values.rs Use search_for_cycle_permutation to look for variances_of 2025-04-27 09:38:18 +02:00