-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make vtable pointers entirely opaque #99420
Conversation
Some changes occurred in compiler/rustc_codegen_gcc cc @antoyo Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
@@ -240,6 +240,13 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { | |||
} | |||
Scalar::Ptr(ptr, _size) => { | |||
let (alloc_id, offset) = ptr.into_parts(); | |||
// For vtables, get the underlying data allocation. | |||
let alloc_id = match self.tcx.global_alloc(alloc_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the alternative would be to move the body of the GlobalAlloc::Memory
match arm below into a new function, and also call that from the GlobalAlloc::Vtable
arm. Not sure which is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, I was going to ask about that when I read the 3 copies of this snippet in the various codegen backends. Another alternative is to add a codegen_alloc
function on TyCtxt
that does what this snippet here does. I think I may actually prefer that instead of splitting the logic out into a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I think a function to codegen a &Allocation
would be nicer. It would make sense to have a "follow the symbolic allocation" operation (which follows statics and vtables), but for statics we don't want to follow them in codegen, so that is just the wrong operation. Following only vtables seems rather ad-hoc.
In fact can we make the vtable_allocation
provider return an &Allocation
rather than an AllocId
? And maybe not even have an AllocId
for the "materialized" vtable? That would be best IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preliminary review, will dig into it more later this week
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 88c84b2 with merge 02e4d4082990eb37f535b13a7373b6ba6d7f8250... |
☀️ Try build successful - checks-actions |
Queued 02e4d4082990eb37f535b13a7373b6ba6d7f8250 with parent 144227d, future comparison URL. |
Finished benchmarking commit (02e4d4082990eb37f535b13a7373b6ba6d7f8250): comparison url. Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Footnotes |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with outstanding comments resolved
☀️ Try build successful - checks-actions |
When I download that toolchain, and check out commit 3de6c04269a7d315f7e9864b9013451cd9580a08 of xsv (the thing that failed), everything passes. I also ran a local build of this branch, and ran So maybe it is random, after all? |
☀️ Test successful - checks-actions |
Tested on commit rust-lang/rust@aa01891. Direct link to PR: <rust-lang/rust#99420> 💔 miri on windows: test-pass → build-fail (cc @oli-obk @RalfJung). 💔 miri on linux: test-pass → build-fail (cc @oli-obk @RalfJung).
Finished benchmarking commit (aa01891): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
adjust for symbolic vtables The Miri side of rust-lang/rust#99420
adjust for symbolic vtables The Miri side of rust-lang/rust#99420
Regression is still failing. Related changes: - rust-lang/rust#99420 - rust-lang/rust#99495 - rust-lang/rust#99844 - rust-lang/rust#99058
Regression is still failing. Related changes: - rust-lang/rust#99420 - rust-lang/rust#99495 - rust-lang/rust#99844 - rust-lang/rust#99058
* Fix compilation errors Regression is still failing. Related changes: - rust-lang/rust#99420 - rust-lang/rust#99495 - rust-lang/rust#99844 - rust-lang/rust#99058 * Change test to expect compilation failure The compiler has reverted their fix to Opaque types due to performance degradation. * Fix VTable handling now that it has an Opaque type - Add an implementation for vtable_size and vtable_align intrinsics. - Change how we handled Foreign types. Even though they are unsized, a pointer to foreign types is a thin pointer. Co-authored-by: Daniel Schwartz-Narbonne <danielsn@users.noreply.github.com>
…enkov make NOP dyn casts not require anything about the vtable As suggested [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/dyn-upcasting.20stabilization/near/292151439). This matches what the codegen backends already do, and what Miri did do until rust-lang#99420 when I made it super extra paranoid.
make NOP dyn casts not require anything about the vtable As suggested [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/dyn-upcasting.20stabilization/near/292151439). This matches what the codegen backends already do, and what Miri did do until rust-lang/rust#99420 when I made it super extra paranoid.
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`
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.
GlobalAlloc
that symbolically refers to a vtable.vtable_allocation
to obtain an actually dataful allocation for this vtable.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