This commit is contained in:
nora 2025-05-29 21:54:34 +02:00
parent 559186088f
commit b7afada251
4 changed files with 54 additions and 42 deletions

View file

@ -1,11 +1,8 @@
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
RUSTC = rustc --target x86_64-pc-windows-msvc -Copt-level=3 -Cpanic=abort -Clinker=lld-link -Clink-arg=/NODEFAULTLIB
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

View file

@ -1,38 +0,0 @@
#![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 }
}
/*
!!!!!!!!!!!!!!!
THIS IS WRONG. WE ARE NOT CREATING THE TLS DIRECTORY. THAT WOULD BE OUR JOB.
!!!!!!!!!!!!!!
*/
extern "stdcall" {
static _tls_index: usize;
}