This commit is contained in:
nora 2025-02-02 12:54:45 +01:00
parent 8c23716f8f
commit db8823e0ad
4 changed files with 66 additions and 4 deletions

View file

@ -1,14 +1,14 @@
SHELL = bash
RUSTC = rustc --target x86_64-pc-windows-msvc -Copt-level=3 -Cpanic=abort -Clinker=lld-link -Clink-arg=/NODEFAULTLIB -Clink-arg=/debug:none -Cdebuginfo=0
build: empty_exe.exe one_dll.exe two_dll.exe constant_data.exe
build: empty_exe.exe one_dll.exe two_dll.exe tls_exe.exe
tls_exe.exe: tls_exe.rs
$(RUSTC) tls_exe.rs
empty_exe.exe: empty_exe.rs
$(RUSTC) empty_exe.rs
constant_data.exe: constant_data.rs
$(RUSTC) constant_data.rs
one_dll.exe: one_dll.rs small_dll.dll
$(RUSTC) one_dll.rs

30
test2/tls_exe.rs Normal file
View file

@ -0,0 +1,30 @@
#![feature(thread_local)]
#![no_std]
#![no_main]
#![windows_subsystem = "console"]
#[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 mainCRTStartup() -> u32 {
// Use some indirection to actually force TLS to happen
set_tls(14);
unsafe { A_THREAD_LOCAL + ANOTHER_THREAD_LOCAL }
}
#[no_mangle]
pub extern "stdcall" fn _tls_index() {}