Skip to content

Commit e5e7395

Browse files
committed
Auto merge of #99420 - RalfJung:vtable, r=oli-obk
make vtable pointers entirely opaque This implements the scheme discussed in rust-lang/unsafe-code-guidelines#338: vtable pointers should be considered entirely opaque and not even readable by Rust code, similar to function pointers. - We have a new kind of `GlobalAlloc` that symbolically refers to a vtable. - Miri uses that kind of allocation when generating a vtable. - The codegen backends, upon encountering such an allocation, call `vtable_allocation` to obtain an actually dataful allocation for this vtable. - We need new intrinsics to obtain the size and align from a vtable (for some `ptr::metadata` APIs), since direct accesses are UB now. I had to touch quite a bit of code that I am not very familiar with, so some of this might not make much sense... r? `@oli-obk`
2 parents 4f118ce + 59d223d commit e5e7395

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/common.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
201201
GlobalAlloc::Function(fn_instance) => {
202202
self.get_fn_addr(fn_instance)
203203
},
204+
GlobalAlloc::VTable(ty, trait_ref) => {
205+
let alloc = self.tcx.global_alloc(self.tcx.vtable_allocation((ty, trait_ref))).unwrap_memory();
206+
let init = const_alloc_to_gcc(self, alloc);
207+
self.static_addr_of(init, alloc.inner().align, None)
208+
}
204209
GlobalAlloc::Static(def_id) => {
205210
assert!(self.tcx.is_static(def_id));
206211
self.get_static(def_id).get_address(None)

0 commit comments

Comments
 (0)