Skip to content

A thread_local! with a const initializer and a panicking drop impl unwinds through an extern "C" frame #112285

Closed
@saethlin

Description

Miri detects UB when running the following program:

pub struct NoisyDrop {}

impl Drop for NoisyDrop {
    fn drop(&mut self) {
        panic!("ow");
    }
}

thread_local! {
    pub static NOISY: NoisyDrop = const { NoisyDrop {} };
}

fn main() {
    NOISY.with(|_| ());
}

With --target=x86_64-unknown-linux-gnu and --target=aarch64-apple-darwin

thread '<unnamed>' panicked at 'ow', src/main.rs:5:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: Undefined Behavior: unwinding past a stack frame that does not allow unwinding
  --> /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/thread_local_dtor.rs:43:17
   |
43 |                 dtor(ptr);
   |                 ^^^^^^^^^ unwinding past a stack frame that does not allow unwinding
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
   = note: BACKTRACE:
   = note: inside `std::sys_common::thread_local_dtor::register_dtor_fallback::run_dtors` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/thread_local_dtor.rs:43:17: 43:26

With --target=x86_64-pc-windows-msvc

thread 'main' panicked at 'ow', src/main.rs:5:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: Undefined Behavior: unwinding past a stack frame that does not allow unwinding
  --> /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/windows/thread_local_dtor.rs:28:9
   |
28 |         (dtor)(ptr);
   |         ^^^^^^^^^^^ unwinding past a stack frame that does not allow unwinding
   |
   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
   = note: BACKTRACE:
   = note: inside `std::sys::windows::thread_local_dtor::run_keyless_dtors` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/windows/thread_local_dtor.rs:28:9: 28:20
   = note: inside `std::sys::windows::thread_local_key::on_tls_callback` at /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/windows/thread_local_key.rs:246:9: 246:54

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions