static TLS works for the main exe!!

This commit is contained in:
nora 2025-02-09 20:47:51 +01:00
parent 5c284548bd
commit a6de0298f2
7 changed files with 214 additions and 30 deletions

View file

@ -0,0 +1,26 @@
#![feature(thread_local)]
#![no_std]
#![no_main]
#[panic_handler]
fn handle_panic(_: &core::panic::PanicInfo<'_>) -> ! {
loop {}
}
#[thread_local]
static mut A_THREAD_LOCAL: u32 = 50;
#[thread_local]
static mut ANOTHER_THREAD_LOCAL: u32 = 55;
#[inline(never)]
fn set_tls(value: u32) {
unsafe { A_THREAD_LOCAL = value; }
unsafe { ANOTHER_THREAD_LOCAL = value; }
}
#[no_mangle]
pub extern "stdcall" fn main() -> u32 {
// Use some indirection to actually force TLS to happen
set_tls(14);
unsafe { A_THREAD_LOCAL + ANOTHER_THREAD_LOCAL }
}