Skip to content

Commit

Permalink
Auto merge of #128742 - RalfJung:miri-vtable-uniqueness, r=saethlin
Browse files Browse the repository at this point in the history
miri: make vtable addresses not globally unique

Miri currently gives vtables a unique global address. That's not actually matching reality though. So this PR enables Miri to generate different addresses for the same type-trait pair.

To avoid generating an unbounded number of `AllocId` (and consuming unbounded amounts of memory), we use the "salt" technique that we also already use for giving constants non-unique addresses: the cache is keyed on a "salt" value n top of the actually relevant key, and Miri picks a random salt (currently in the range `0..16`) each time it needs to choose an `AllocId` for one of these globals -- that means we'll get up to 16 different addresses for each vtable. The salt scheme is integrated into the global allocation deduplication logic in `tcx`, and also used for functions and string literals. (So this also fixes the problem that casting the same function to a fn ptr over and over will consume unbounded memory.)

r? `@saethlin`
Fixes rust-lang/miri#3737
  • Loading branch information
bors committed Aug 13, 2024
2 parents 95f691a + 199ce2e commit 9a090a2
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 9a090a2

Please sign in to comment.