Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
fba4177
Simplify assignments.
cjgillot Jun 23, 2025
ac70dc8
Introduce Value::RawPtr as it behaves differently from other aggregates.
cjgillot Jun 30, 2025
be41333
Store a full Ty with each Value.
cjgillot Jun 30, 2025
4750dff
Remove extraneous types.
cjgillot Jun 30, 2025
cbc3cf7
Avoid computing layouts inside coroutines.
cjgillot Jul 1, 2025
4a95b16
Move crashes tests.
cjgillot Jul 2, 2025
92144e1
Remove `josh-sync` tooling and update README
Kobzol Jul 4, 2025
13dca5e
Update CI workflow to use rustc-josh-sync
Kobzol Jul 4, 2025
9d83749
Document `rustc-josh-sync`
Kobzol Jul 4, 2025
dbad976
Merge pull request #2491 from Kobzol/switch-to-rustc-josh-sync
jieyouxu Jul 4, 2025
f167f9b
external-repos.md: small fixes
tshepang Jul 4, 2025
33c70d9
Merge pull request #2492 from rust-lang/tshepang-patch-1
tshepang Jul 4, 2025
922ee88
Mention that stdarch is managed by josh-sync
Kobzol Jul 8, 2025
342d78d
Merge pull request #2495 from Kobzol/josh-sync-stdarch
jieyouxu Jul 8, 2025
24a25db
Revert `tests/run-make/mte-ffi` changes
jieyouxu Jun 10, 2025
37136dd
Disable `tests/run-make/mte-ffi`
jieyouxu Jul 8, 2025
6b8bc68
use a consistent (and recommended) invocation
tshepang Jul 9, 2025
120a361
Merge pull request #2496 from rust-lang/tshepang-a-convenience
tshepang Jul 9, 2025
7b394d2
tweak some git clone commands
tshepang Jul 9, 2025
42472f2
add missing word
tshepang Jul 9, 2025
d99af0b
distcheck had only one possible invocation
tshepang Jul 9, 2025
99fc05b
do not invent a name
tshepang Jul 9, 2025
1a6e543
Merge pull request #2498 from rust-lang/tshepang-patch-1
Noratrieb Jul 10, 2025
7c76abc
Merge pull request #2500 from rust-lang/tshepang-patch-3
Noratrieb Jul 10, 2025
1ef0072
Merge pull request #2499 from rust-lang/tshepang-patch-2
Noratrieb Jul 10, 2025
f1ae43f
Mention that compiler-builtins is now using `rustc-josh-sync`
Kobzol Jul 10, 2025
c6bedc1
Migrate rustc-pull to CI workflow from `josh-sync`
Kobzol Jul 10, 2025
c7cdd14
Merge pull request #2501 from Kobzol/compiler-builtins-josh
jieyouxu Jul 10, 2025
c46e385
Merge pull request #2502 from Kobzol/rustc-josh-sync-ci
jieyouxu Jul 11, 2025
7803c25
directives.md: build-aux-docs does not work with aux-crate
lolbinarycat Jul 11, 2025
f58accb
pass --gc-sections if -Zexport-executable-symbols is enabled and impr…
usamoi Jul 12, 2025
c9bdba3
So many test updates x_x
scottmcm Jul 12, 2025
faa6ded
Update cranelift tests
scottmcm Jul 13, 2025
d53b104
Update Miri Tests
scottmcm Jul 13, 2025
fa7734a
Ban projecting into SIMD types [MCP838]
scottmcm Mar 7, 2025
39f269c
Merge pull request #2497 from rust-lang/tshepang-git-clone
ZuseZ4 Jul 14, 2025
8ec7e6f
Merge pull request #2504 from lolbinarycat/lolbinarycat-patch-2
jieyouxu Jul 15, 2025
aa87845
`SmirCtxt` to `CompilerCtxt`, `SmirInterface` to `CompilerInterface`
makai410 Jul 15, 2025
ea3bb05
`SmirContainer` to `Container`
makai410 Jul 15, 2025
26eca4c
use "helper" as a more descriptive name
makai410 Jul 15, 2025
a5e450d
rename `ui-fulldeps/stable-mir`
makai410 Jul 15, 2025
7831a1f
rename `ui/stable-mir-print`
makai410 Jul 15, 2025
922b034
`SmirError` to `Error`
makai410 Jul 15, 2025
7bd295e
Update docs in `rustc_public_bridge`
makai410 Jul 15, 2025
6a87e95
Update docs in `rustc_public`
makai410 Jul 15, 2025
b7b8b75
use `RustcPublic` instead of `StableMir`
makai410 Jul 15, 2025
0e423f4
Boostrap: add warning on `optimize = false`
xdoardo Jul 16, 2025
4e054fc
Port `#[coverage]` to the new attribute system
scrabsha Jul 13, 2025
af39c0c
Emit warning when there is no space between `-o` and confusing arg
xizheyin Jul 10, 2025
dd48e56
tests: Test line number in debuginfo for diverging function calls
Enselic Jul 16, 2025
9ef3be2
go over invariants again :3
lcnr Jul 16, 2025
6237eaf
Merge pull request #2506 from lcnr/type-system-invariants
lcnr Jul 16, 2025
f100767
fix `-Zsanitizer=kcfi` on `#[naked]` functions
folkertdev Jul 1, 2025
ec0ff72
add `codegen_instance_attrs` query
folkertdev Jul 2, 2025
9c8ab89
use `codegen_instance_attrs` where an instance is (easily) available
folkertdev Jul 2, 2025
fad8dec
fix: false positive double_negations when it jumps macro boundary
anatawa12 Jul 16, 2025
8df6a1d
some improvements to "Invariants of the type system"
tshepang Jul 17, 2025
c113a60
Merge pull request #2507 from rust-lang/tshepang-misc
tshepang Jul 17, 2025
2faf5ed
Prepare for merging from rust-lang/rust
invalid-email-address Jul 17, 2025
ce0de76
Merge ref 'fd2eb391d032' from rust-lang/rust
invalid-email-address Jul 17, 2025
b2474c8
Merge pull request #2508 from rust-lang/rustc-pull
tshepang Jul 17, 2025
dd364bd
copy-paste convenience
tshepang Jul 17, 2025
41c0c5b
Merge pull request #2510 from rust-lang/tshepang-patch-1
tshepang Jul 17, 2025
5bb6b9d
remove no_gc_sections
usamoi Jul 14, 2025
6645bf5
Copy GCC sources into the build directory even outside CI
Kobzol Jul 17, 2025
853333d
constify `Option` methods
oli-obk Jul 15, 2025
6932687
parse `const trait Trait`
fee1-dead Jul 13, 2025
106802b
Rollup merge of #142300 - jieyouxu:exp-partial-revert-141576, r=Waffl…
fmease Jul 17, 2025
6dbbc27
Rollup merge of #143271 - cjgillot:gvn-types, r=oli-obk
fmease Jul 17, 2025
d62da83
Rollup merge of #143293 - folkertdev:naked-function-kcfi, r=compiler-…
fmease Jul 17, 2025
db14157
Rollup merge of #143719 - xizheyin:142812-1, r=jieyouxu
fmease Jul 17, 2025
de1bb37
Rollup merge of #143833 - scottmcm:final-mcp-838, r=compiler-errors
fmease Jul 17, 2025
48bd693
Rollup merge of #143846 - usamoi:gc, r=bjorn3
fmease Jul 17, 2025
1b8b8af
Rollup merge of #143879 - fee1-dead-contrib:push-lrlpoouyqqry, r=fmease
fmease Jul 17, 2025
e472f24
Rollup merge of #143891 - scrabsha:push-xxtttopqoprr, r=jdonszelmann
fmease Jul 17, 2025
ffb9a68
Rollup merge of #143967 - oli-obk:const-option-methods, r=fee1-dead
fmease Jul 17, 2025
9e5154c
Rollup merge of #143985 - makai410:rp-rename, r=oli-obk
fmease Jul 17, 2025
7e54dc9
Rollup merge of #144008 - anatawa12:fix-double-negations, r=compiler-…
fmease Jul 17, 2025
b835e0d
Rollup merge of #144010 - xdoardo:bootstrap-warning-optimize-false, r…
fmease Jul 17, 2025
20adadf
Rollup merge of #144034 - Enselic:diverging-function-call-debuginfo, …
fmease Jul 17, 2025
f746f62
Rollup merge of #144049 - tshepang:rust-push, r=jieyouxu
fmease Jul 17, 2025
ba0656f
Rollup merge of #144056 - Kobzol:gcc-build-src, r=nikic
fmease Jul 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add codegen_instance_attrs query
and use it for naked functions
  • Loading branch information
folkertdev committed Jul 16, 2025
commit ec0ff720d1a89cb51edd90116c6e70051affa95f
8 changes: 2 additions & 6 deletions compiler/rustc_codegen_cranelift/src/driver/aot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,8 @@ fn codegen_cgu_content(
for (mono_item, item_data) in mono_items {
match mono_item {
MonoItem::Fn(instance) => {
// Other `InstanceKind`s (e.g. `ReifyShim` generated by indirect calls) should be
// codegened like a normal function.
let is_item_instance = matches!(instance.def, InstanceKind::Item(_));

let flags = tcx.codegen_fn_attrs(instance.def_id()).flags;
if is_item_instance && flags.contains(CodegenFnAttrFlags::NAKED) {
let flags = tcx.codegen_instance_attrs(instance.def).flags;
if flags.contains(CodegenFnAttrFlags::NAKED) {
rustc_codegen_ssa::mir::naked_asm::codegen_naked_asm(
&mut GlobalAsmContext { tcx, global_asm: &mut cx.global_asm },
instance,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
codegen_fn_attrs.export_name = Some(*name);
}
AttributeKind::Naked(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,

AttributeKind::Align { align, .. } => codegen_fn_attrs.alignment = Some(*align),
AttributeKind::LinkName { name, .. } => codegen_fn_attrs.link_name = Some(*name),
AttributeKind::LinkSection { name, .. } => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
LocalRef::Operand(operand) => {
// Don't spill operands onto the stack in naked functions.
// See: https://github.com/rust-lang/rust/issues/42779
let attrs = bx.tcx().codegen_fn_attrs(self.instance.def_id());
let attrs = bx.tcx().codegen_instance_attrs(self.instance.def);
if attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
return;
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,8 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(

let mut num_untupled = None;

let codegen_fn_attrs = bx.tcx().codegen_fn_attrs(fx.instance.def_id());
let naked = codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED);
if naked {
let codegen_fn_attrs = bx.tcx().codegen_instance_attrs(fx.instance.def);
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) {
return vec![];
}

Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_codegen_ssa/src/mono_item.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::mono::{Linkage, MonoItem, MonoItemData, Visibility};
use rustc_middle::ty::InstanceKind;
use rustc_middle::ty::layout::HasTyCtxt;
use tracing::debug;

Expand Down Expand Up @@ -42,12 +41,8 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> {
base::codegen_global_asm(cx, item_id);
}
MonoItem::Fn(instance) => {
// Other `InstanceKind`s (e.g. `ReifyShim` generated by indirect calls) should be
// codegened like a normal function.
let is_item_instance = matches!(instance.def, InstanceKind::Item(_));

let flags = cx.tcx().codegen_fn_attrs(instance.def_id()).flags;
if is_item_instance && flags.contains(CodegenFnAttrFlags::NAKED) {
let flags = cx.tcx().codegen_instance_attrs(instance.def).flags;
if flags.contains(CodegenFnAttrFlags::NAKED) {
naked_asm::codegen_naked_asm::<Bx::CodegenCx>(cx, instance, item_data);
} else {
base::codegen_instance::<Bx>(cx, instance);
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_middle/src/middle/codegen_fn_attrs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use rustc_abi::Align;
use rustc_ast::expand::autodiff_attrs::AutoDiffAttrs;
use rustc_attr_data_structures::{InlineAttr, InstructionSetAttr, OptimizeAttr};
Expand All @@ -6,6 +8,24 @@ use rustc_span::Symbol;
use rustc_target::spec::SanitizerSet;

use crate::mir::mono::Linkage;
use crate::ty::{InstanceKind, TyCtxt};

impl<'tcx> TyCtxt<'tcx> {
pub fn codegen_instance_attrs(
self,
instance_kind: InstanceKind<'_>,
) -> Cow<'tcx, CodegenFnAttrs> {
let mut attrs = Cow::Borrowed(self.codegen_fn_attrs(instance_kind.def_id()));

// Drop the `#[naked]` attribute on non-item `InstanceKind`s, like the shims that
// are generated for indirect function calls.
if !matches!(instance_kind, InstanceKind::Item(_)) {
attrs.to_mut().flags.remove(CodegenFnAttrFlags::NAKED);
}

attrs
}
}

#[derive(Clone, TyEncodable, TyDecodable, HashStable, Debug)]
pub struct CodegenFnAttrs {
Expand Down
12 changes: 6 additions & 6 deletions tests/codegen/sanitizer/kcfi/naked-function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ trait MyTrait {
}
impl MyTrait for Thing {}

// the shim calls the real function
// CHECK-LABEL: define
// CHECK-SAME: my_naked_function
// CHECK-SAME: reify.shim.fnptr

// CHECK-LABEL: main
#[unsafe(no_mangle)]
pub fn main() {
// Trick the compiler into generating an indirect call.
const F: extern "C" fn() = Thing::my_naked_function;

// main calls the shim function
// CHECK: call
// CHECK: call void
// CHECK-SAME: my_naked_function
// CHECK-SAME: reify.shim.fnptr
(F)();
}

// the shim calls the real function
// CHECK: define
// CHECK-SAME: my_naked_function
// CHECK-SAME: reify.shim.fnptr

// CHECK: declare !kcfi_type
// CHECK-SAME: my_naked_function