Closed
Description
Note: this is currently blocked on rust-lang/rust#70685
Currently Miri has only partial support for deallocation of thread-locals. It runs destructors of the library thread locals (src/shims/tls.rs
), but it does not deallocate the thread-local statics #[thread_local]
. As a result, Miri misses undefined behaviour in the following program:
#![feature(thread_local)]
use std::thread;
#[thread_local]
static mut A: u8 = 0;
struct Sender(*const u8);
unsafe impl Send for Sender {}
fn main() {
let handle = thread::spawn(|| {
let ptr = unsafe { &mut A as *mut u8 };
assert_eq!(unsafe { *ptr }, 0);
unsafe { *ptr = 5; }
Sender(ptr)
});
let ptr = handle.join().unwrap().0;
let x = unsafe { *ptr }; // This should be UB.
let y = x + 1;
}
Fixing this issue before rust-lang/rust#70685 is very hard because currently we allocate thread local statics in tcx.alloc_map
, which allows adding elements, but does not allow removing them.