aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2025-09-18 22:01:14 +0100
committerGitHub <noreply@github.com>2025-09-18 22:01:14 +0100
commit4d2854f5618c8e6a09bc2ec7bf969eccb01f93c2 (patch)
treeece1e00dd4e8f7bbb1098f4cffbed5b232e7f6e2 /src
parent9cf69576ab8cb220af5802a04a0aa53dc92046a5 (diff)
parent57bc45ae30736a891e4b65c7047a091e53cf60e3 (diff)
Merge pull request #5632 from kalsprite/x386
windows i386 support
Diffstat (limited to 'src')
-rw-r--r--src/linker.cpp6
-rw-r--r--src/llvm_backend.cpp10
-rw-r--r--src/main.cpp5
3 files changed, 19 insertions, 2 deletions
diff --git a/src/linker.cpp b/src/linker.cpp
index 41333a3c9..333cb792e 100644
--- a/src/linker.cpp
+++ b/src/linker.cpp
@@ -281,7 +281,11 @@ try_cross_linking:;
link_settings = gb_string_append_fmt(link_settings, " /NOENTRY");
}
} else {
- link_settings = gb_string_append_fmt(link_settings, " /ENTRY:mainCRTStartup");
+ // For i386 with CRT, libcmt provides the entry point
+ // For other cases or no_crt, we need to specify the entry point
+ if (!(build_context.metrics.arch == TargetArch_i386 && !build_context.no_crt)) {
+ link_settings = gb_string_append_fmt(link_settings, " /ENTRY:mainCRTStartup");
+ }
}
if (build_context.build_paths[BuildPath_Symbols].name != "") {
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index 5d2accd90..77576cfd4 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -2689,8 +2689,15 @@ gb_internal lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *star
params->Tuple.variables[1] = alloc_entity_param(nullptr, make_token_ident("fdwReason"), t_u32, false, true);
params->Tuple.variables[2] = alloc_entity_param(nullptr, make_token_ident("lpReserved"), t_rawptr, false, true);
call_cleanup = false;
- } else if (build_context.metrics.os == TargetOs_windows && (build_context.metrics.arch == TargetArch_i386 || build_context.no_crt)) {
+ } else if (build_context.metrics.os == TargetOs_windows && build_context.no_crt) {
name = str_lit("mainCRTStartup");
+ } else if (build_context.metrics.os == TargetOs_windows && build_context.metrics.arch == TargetArch_i386 && !build_context.no_crt) {
+ // Windows i386 with CRT: libcmt expects _main (main with underscore prefix)
+ name = str_lit("main");
+ has_args = true;
+ slice_init(&params->Tuple.variables, permanent_allocator(), 2);
+ params->Tuple.variables[0] = alloc_entity_param(nullptr, make_token_ident("argc"), t_i32, false, true);
+ params->Tuple.variables[1] = alloc_entity_param(nullptr, make_token_ident("argv"), t_ptr_cstring, false, true);
} else if (is_arch_wasm()) {
name = str_lit("_start");
call_cleanup = false;
@@ -3166,6 +3173,7 @@ gb_internal bool lb_generate_code(lbGenerator *gen) {
String link_name = e->Procedure.link_name;
if (e->pkg->kind == Package_Runtime) {
if (link_name == "main" ||
+ link_name == "_main" ||
link_name == "DllMain" ||
link_name == "WinMain" ||
link_name == "wWinMain" ||
diff --git a/src/main.cpp b/src/main.cpp
index bbaf6f23f..be0ea8b82 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3629,6 +3629,11 @@ int main(int arg_count, char const **arg_ptr) {
// print_usage_line(0, "%.*s 32-bit is not yet supported for this platform", LIT(args[0]));
// return 1;
// }
+
+ // 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");
+ }
// Check chosen microarchitecture. If not found or ?, print list.
bool print_microarch_list = true;