Skip to content

STATUS_ACCESS_VIOLATION in unstable thread_local feature on windows-gnu #100917

Open
@uselessgoddess

Description

@uselessgoddess

I tried this code:

#![feature(thread_local)]

use std::cell::RefCell;
use std::mem::MaybeUninit;

#[thread_local]
static PLACE: RefCell<usize> = RefCell::new(0);

fn touch(x: usize) {
    *PLACE.borrow_mut() = x;
}

pub fn main() {
    touch(12);
}

But it breaks down inside RefCell:
error: process didn't exit successfully: 'target\debug\sandbox.exe' (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

Debugger comes to here:
image

rustc 1.65.0-nightly (878aef79d 2022-08-20)
binary: rustc
commit-hash: 878aef79dcdf59d19bb8482202dc55e58ceb62ff
commit-date: 2022-08-20
host: x86_64-pc-windows-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0

Activity

mati865

mati865 commented on Sep 24, 2022

@mati865
Member

Quoting myself from #102243 (comment):

[..] EmuTLS used by GCC is just too messed up and causes problems for all languages that use TLS.
I don't think it's possible to workaround this problem in Rust but FWIW windows-gnullvm targets that I added not so long ago are working perfectly fine with it (although they are not tested on CI): #94872 (files) This is because LLVM uses native Windows TLS by default which is not implemented in GCC.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-thread_local`#![feature(thread_local)]`O-windows-gnuToolchain: GNU, Operating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @wesleywiser@mati865@uselessgoddess

        Issue actions

          `STATUS_ACCESS_VIOLATION` in unstable `thread_local` feature on `windows-gnu` · Issue #100917 · rust-lang/rust