commit 5aeeb6a0a496b962638fdfd6d20d289e27f10112 (tree)
parent 845b6a8efe5ac71c9df02373fe3716814cb7b92d
Author: Ryan Liptak <squeek502@hotmail.com>
Date: Fri, 1 May 2026 17:07:18 -0700
Conditionally export wrapper around Zig-defined DllMain function when linking libc
This logic exists for other main functions, so it makes sense to do it for DllMain, too.
Diffstat:
1 file changed, 12 insertions(+), 0 deletions(-)
diff --git a/lib/std/start.zig b/lib/std/start.zig
@@ -23,6 +23,10 @@ comptime {
const dll_main_crt_startup = if (builtin.abi.isGnu()) "DllMainCRTStartup" else "_DllMainCRTStartup";
if (native_os == .windows and !builtin.link_libc and !@hasDecl(root, dll_main_crt_startup)) {
@export(&DllMainCRTStartup, .{ .name = dll_main_crt_startup });
+ } else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "DllMain")) {
+ if (!@typeInfo(@TypeOf(root.DllMain)).@"fn".calling_convention.eql(.winapi)) {
+ @export(&DllMain, .{ .name = "DllMain" });
+ }
}
} else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
if (builtin.link_libc and @hasDecl(root, "main")) {
@@ -88,6 +92,14 @@ fn DllMainCRTStartup(
return .TRUE;
}
+fn DllMain(
+ hinstDLL: std.os.windows.HINSTANCE,
+ fdwReason: std.os.windows.DWORD,
+ lpReserved: std.os.windows.LPVOID,
+) callconv(.winapi) std.os.windows.BOOL {
+ return root.DllMain(hinstDLL, fdwReason, lpReserved);
+}
+
fn wasm_freestanding_start() callconv(.c) void {
// This is marked inline because for some reason LLVM in
// release mode fails to inline it, and we want fewer call frames in stack traces.