authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-05-01 17:07:18-07:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-05-02 02:44:26-07:00
log5aeeb6a0a496b962638fdfd6d20d289e27f10112
tree1f5c400823a764392cea7c155bf4365468390b21
parent845b6a8efe5ac71c9df02373fe3716814cb7b92d

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.

1 files changed, 12 insertions(+), 0 deletions(-)

lib/std/start.zig+12
......@@ -23,6 +23,10 @@ comptime {
2323 const dll_main_crt_startup = if (builtin.abi.isGnu()) "DllMainCRTStartup" else "_DllMainCRTStartup";
2424 if (native_os == .windows and !builtin.link_libc and !@hasDecl(root, dll_main_crt_startup)) {
2525 @export(&DllMainCRTStartup, .{ .name = dll_main_crt_startup });
26 } else if (native_os == .windows and builtin.link_libc and @hasDecl(root, "DllMain")) {
27 if (!@typeInfo(@TypeOf(root.DllMain)).@"fn".calling_convention.eql(.winapi)) {
28 @export(&DllMain, .{ .name = "DllMain" });
29 }
2630 }
2731 } else if (builtin.output_mode == .Exe or @hasDecl(root, "main")) {
2832 if (builtin.link_libc and @hasDecl(root, "main")) {
......@@ -88,6 +92,14 @@ fn DllMainCRTStartup(
8892 return .TRUE;
8993}
9094
95fn DllMain(
96 hinstDLL: std.os.windows.HINSTANCE,
97 fdwReason: std.os.windows.DWORD,
98 lpReserved: std.os.windows.LPVOID,
99) callconv(.winapi) std.os.windows.BOOL {
100 return root.DllMain(hinstDLL, fdwReason, lpReserved);
101}
102
91103fn wasm_freestanding_start() callconv(.c) void {
92104 // This is marked inline because for some reason LLVM in
93105 // release mode fails to inline it, and we want fewer call frames in stack traces.