From 231ce2da59cd93b4e8d8a90daca2d2111fc3ecf8 Mon Sep 17 00:00:00 2001 From: Jon Lipstate Date: Fri, 29 Aug 2025 12:41:38 -0700 Subject: windows i386 support --- base/runtime/core_builtin.odin | 7 ++++++- base/runtime/entry_windows.odin | 14 +++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'base') diff --git a/base/runtime/core_builtin.odin b/base/runtime/core_builtin.odin index 3a51d71fb..33b600c3e 100644 --- a/base/runtime/core_builtin.odin +++ b/base/runtime/core_builtin.odin @@ -54,7 +54,12 @@ container_of :: #force_inline proc "contextless" (ptr: $P/^$Field_Type, $T: type when !NO_DEFAULT_TEMP_ALLOCATOR { - @thread_local global_default_temp_allocator_data: Default_Temp_Allocator + when ODIN_ARCH == .i386 && ODIN_OS == .Windows { + // Thread-local storage is problematic on Windows i386 + global_default_temp_allocator_data: Default_Temp_Allocator + } else { + @thread_local global_default_temp_allocator_data: Default_Temp_Allocator + } } @(builtin, disabled=NO_DEFAULT_TEMP_ALLOCATOR) diff --git a/base/runtime/entry_windows.odin b/base/runtime/entry_windows.odin index 8eb4cc7d1..dc8e9b82c 100644 --- a/base/runtime/entry_windows.odin +++ b/base/runtime/entry_windows.odin @@ -28,7 +28,19 @@ when ODIN_BUILD_MODE == .Dynamic { return true } } else when !ODIN_TEST && !ODIN_NO_ENTRY_POINT { - when ODIN_ARCH == .i386 || ODIN_NO_CRT { + when ODIN_ARCH == .i386 && !ODIN_NO_CRT { + // Windows i386 with CRT: libcmt provides mainCRTStartup which calls _main + // Note: "c" calling convention adds underscore prefix automatically on i386 + @(link_name="main", linkage="strong", require) + main :: proc "c" (argc: i32, argv: [^]cstring) -> i32 { + args__ = argv[:argc] + context = default_context() + #force_no_inline _startup_runtime() + intrinsics.__entry_point() + #force_no_inline _cleanup_runtime() + return 0 + } + } else when ODIN_NO_CRT { @(link_name="mainCRTStartup", linkage="strong", require) mainCRTStartup :: proc "system" () -> i32 { context = default_context() -- cgit v1.2.3 From e0c4c5336241cb3106910bec64369888b937132b Mon Sep 17 00:00:00 2001 From: Jon Lipstate Date: Wed, 3 Sep 2025 22:32:33 -0700 Subject: add tls when we have crt --- base/runtime/core_builtin.odin | 4 ++-- core/testing/signal_handler_libc.odin | 4 ++-- src/main.cpp | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'base') diff --git a/base/runtime/core_builtin.odin b/base/runtime/core_builtin.odin index 33b600c3e..7e96c6784 100644 --- a/base/runtime/core_builtin.odin +++ b/base/runtime/core_builtin.odin @@ -54,8 +54,8 @@ container_of :: #force_inline proc "contextless" (ptr: $P/^$Field_Type, $T: type when !NO_DEFAULT_TEMP_ALLOCATOR { - when ODIN_ARCH == .i386 && ODIN_OS == .Windows { - // Thread-local storage is problematic on Windows i386 + when ODIN_ARCH == .i386 && ODIN_OS == .Windows && ODIN_NO_CRT { + // Thread-local storage doesn't work on Windows i386 without CRT global_default_temp_allocator_data: Default_Temp_Allocator } else { @thread_local global_default_temp_allocator_data: Default_Temp_Allocator diff --git a/core/testing/signal_handler_libc.odin b/core/testing/signal_handler_libc.odin index 961f5c7ce..7c50fbb09 100644 --- a/core/testing/signal_handler_libc.odin +++ b/core/testing/signal_handler_libc.odin @@ -24,8 +24,8 @@ import "core:terminal/ansi" @(private="file") stop_test_passed: libc.sig_atomic_t @(private="file") stop_test_alert: libc.sig_atomic_t -when ODIN_ARCH == .i386 && ODIN_OS == .Windows { - // Thread-local storage is problematic on Windows i386 +when ODIN_ARCH == .i386 && ODIN_OS == .Windows && ODIN_NO_CRT { + // Thread-local storage doesn't work on Windows i386 without CRT @(private="file") local_test_index: libc.sig_atomic_t @(private="file") diff --git a/src/main.cpp b/src/main.cpp index c4646bc9f..198706de2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3619,8 +3619,9 @@ int main(int arg_count, char const **arg_ptr) { // } // Warn about Windows i386 thread-local storage limitations - if (build_context.metrics.arch == TargetArch_i386 && build_context.metrics.os == TargetOs_windows) { - gb_printf_err("Warning: Thread-local storage is disabled on Windows i386.\n"); + if (build_context.metrics.arch == TargetArch_i386 && build_context.metrics.os == TargetOs_windows && build_context.no_crt) { + gb_printf_err("Warning: Thread-local storage is not supported on Windows i386 with -no-crt.\n"); + gb_printf_err(" Multi-threaded code will not work correctly.\n"); } // Check chosen microarchitecture. If not found or ?, print list. -- cgit v1.2.3 From 57bc45ae30736a891e4b65c7047a091e53cf60e3 Mon Sep 17 00:00:00 2001 From: Jon Lipstate Date: Wed, 3 Sep 2025 22:51:28 -0700 Subject: revert to working build --- base/runtime/core_builtin.odin | 4 ++-- core/testing/signal_handler_libc.odin | 4 ++-- src/main.cpp | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to 'base') diff --git a/base/runtime/core_builtin.odin b/base/runtime/core_builtin.odin index 7e96c6784..33b600c3e 100644 --- a/base/runtime/core_builtin.odin +++ b/base/runtime/core_builtin.odin @@ -54,8 +54,8 @@ container_of :: #force_inline proc "contextless" (ptr: $P/^$Field_Type, $T: type when !NO_DEFAULT_TEMP_ALLOCATOR { - when ODIN_ARCH == .i386 && ODIN_OS == .Windows && ODIN_NO_CRT { - // Thread-local storage doesn't work on Windows i386 without CRT + when ODIN_ARCH == .i386 && ODIN_OS == .Windows { + // Thread-local storage is problematic on Windows i386 global_default_temp_allocator_data: Default_Temp_Allocator } else { @thread_local global_default_temp_allocator_data: Default_Temp_Allocator diff --git a/core/testing/signal_handler_libc.odin b/core/testing/signal_handler_libc.odin index 7c50fbb09..961f5c7ce 100644 --- a/core/testing/signal_handler_libc.odin +++ b/core/testing/signal_handler_libc.odin @@ -24,8 +24,8 @@ import "core:terminal/ansi" @(private="file") stop_test_passed: libc.sig_atomic_t @(private="file") stop_test_alert: libc.sig_atomic_t -when ODIN_ARCH == .i386 && ODIN_OS == .Windows && ODIN_NO_CRT { - // Thread-local storage doesn't work on Windows i386 without CRT +when ODIN_ARCH == .i386 && ODIN_OS == .Windows { + // Thread-local storage is problematic on Windows i386 @(private="file") local_test_index: libc.sig_atomic_t @(private="file") diff --git a/src/main.cpp b/src/main.cpp index 198706de2..c4646bc9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3619,9 +3619,8 @@ int main(int arg_count, char const **arg_ptr) { // } // Warn about Windows i386 thread-local storage limitations - if (build_context.metrics.arch == TargetArch_i386 && build_context.metrics.os == TargetOs_windows && build_context.no_crt) { - gb_printf_err("Warning: Thread-local storage is not supported on Windows i386 with -no-crt.\n"); - gb_printf_err(" Multi-threaded code will not work correctly.\n"); + if (build_context.metrics.arch == TargetArch_i386 && build_context.metrics.os == TargetOs_windows) { + gb_printf_err("Warning: Thread-local storage is disabled on Windows i386.\n"); } // Check chosen microarchitecture. If not found or ?, print list. -- cgit v1.2.3