Skip to content

Commit 55e0668

Browse files
authored
Rollup merge of rust-lang#123649 - maurer:kcfi-v0, r=compiler-errors
KCFI: Use legal charset in shim encoding To separate `ReifyReason::FnPtr` from `ReifyReason::VTable`, we hyphenated the shims. Hyphens are not actually legal, but underscores are, so use those instead. r? `@compiler-errors`
2 parents 727c31a + 233d94e commit 55e0668

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

compiler/rustc_symbol_mangling/src/v0.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ pub(super) fn mangle<'tcx>(
4545
ty::InstanceDef::ThreadLocalShim(_) => Some("tls"),
4646
ty::InstanceDef::VTableShim(_) => Some("vtable"),
4747
ty::InstanceDef::ReifyShim(_, None) => Some("reify"),
48-
ty::InstanceDef::ReifyShim(_, Some(ReifyReason::FnPtr)) => Some("reify-fnptr"),
49-
ty::InstanceDef::ReifyShim(_, Some(ReifyReason::Vtable)) => Some("reify-vtable"),
48+
ty::InstanceDef::ReifyShim(_, Some(ReifyReason::FnPtr)) => Some("reify_fnptr"),
49+
ty::InstanceDef::ReifyShim(_, Some(ReifyReason::Vtable)) => Some("reify_vtable"),
5050

5151
ty::InstanceDef::ConstructCoroutineInClosureShim { .. }
5252
| ty::InstanceDef::CoroutineKindShim { .. } => Some("fn_once"),

tests/ui/sanitizer/kcfi-mangling.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Check KCFI extra mangling works correctly on v0
2+
3+
//@ needs-sanitizer-kcfi
4+
//@ no-prefer-dynamic
5+
//@ compile-flags: -C panic=abort -Zsanitizer=kcfi -C symbol-mangling-version=v0
6+
//@ build-pass
7+
8+
trait Foo {
9+
fn foo(&self);
10+
}
11+
12+
struct Bar;
13+
impl Foo for Bar {
14+
fn foo(&self) {}
15+
}
16+
17+
struct Baz;
18+
impl Foo for Baz {
19+
#[track_caller]
20+
fn foo(&self) {}
21+
}
22+
23+
fn main() {
24+
// Produces `ReifyShim(_, ReifyReason::FnPtr)`
25+
let f: fn(&Bar) = Bar::foo;
26+
f(&Bar);
27+
// Produces `ReifyShim(_, ReifyReason::Vtable)`
28+
let v: &dyn Foo = &Baz as _;
29+
v.foo();
30+
}

0 commit comments

Comments
 (0)