Skip to content

Commit 275f6a7

Browse files
committed
CFI: Don't count CFI shim def_ids in locally codegenned
CFI shims are currently always provided by the crate that creates the trait object in question, as that is when the vtable is allocated. This means that seeing a CFI shim for a given def_id should *not* indicate that the def_id is available locally - the implementor of the trait may be in another crate.
1 parent d9f7518 commit 275f6a7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/rustc_monomorphize/src/partitioning.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,12 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co
11431143
let mono_items: DefIdSet = items
11441144
.iter()
11451145
.filter_map(|mono_item| match *mono_item {
1146-
MonoItem::Fn(ref instance) => Some(instance.def_id()),
1146+
// Don't count CfiShim's def_id, that resolves to a child instance
1147+
MonoItem::Fn(ref instance)
1148+
if !matches!(instance.def, ty::InstanceDef::CfiShim { .. }) =>
1149+
{
1150+
Some(instance.def_id())
1151+
}
11471152
MonoItem::Static(def_id) => Some(def_id),
11481153
_ => None,
11491154
})

tests/ui/sanitizer/cfi-dylib-test.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Check for the ability to drop when linking across dylib lines
2+
3+
//@ needs-sanitizer-cfi
4+
//@ compile-flags: -Clinker-plugin-lto -C link-args=-fuse-ld=lld -Zsanitizer=cfi -C codegen-units=1 -C opt-level=0 --test
5+
//@ run-pass
6+
7+
#[test]
8+
fn foo() {
9+
std::fs::File::open("boom").expect_err("baboom");
10+
}

0 commit comments

Comments
 (0)