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.
This commit is contained in:
Ryan Liptak
2026-05-01 17:07:18 -07:00
parent 845b6a8efe
commit 5aeeb6a0a4
+12
View File
@@ -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.