diff options
| author | Vexu <git@vexu.eu> | 2019-11-30 15:39:11 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-12-03 12:50:18 -0500 |
| commit | a0ca30ce014f4abd9d31ea335e8860fd1b110495 (patch) | |
| tree | 577b3043e5d720b0916589bf3f9aa07a94b9baa5 /lib/std/special/start.zig | |
| parent | fd7c7be33c95fd1bd77010378b407fc9fb4933e2 (diff) | |
| download | zig-a0ca30ce014f4abd9d31ea335e8860fd1b110495.tar.gz zig-a0ca30ce014f4abd9d31ea335e8860fd1b110495.zip | |
move more startup code to std lib
Diffstat (limited to 'lib/std/special/start.zig')
| -rw-r--r-- | lib/std/special/start.zig | 55 |
1 files changed, 43 insertions, 12 deletions
diff --git a/lib/std/special/start.zig b/lib/std/special/start.zig index 6d99618d2e..478876c689 100644 --- a/lib/std/special/start.zig +++ b/lib/std/special/start.zig @@ -19,21 +19,52 @@ const is_mips = switch (builtin.arch) { }; comptime { - if (builtin.link_libc) { - @export("main", main, .Strong); - } else if (builtin.os == .windows) { - @export("WinMainCRTStartup", WinMainCRTStartup, .Strong); - } else if (is_wasm and builtin.os == .freestanding) { - @export("_start", wasm_freestanding_start, .Strong); - } else if (builtin.os == .uefi) { - @export("EfiMain", EfiMain, .Strong); - } else if (is_mips) { - if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong); - } else { - if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong); + switch (builtin.output_type) { + .Unknown => unreachable, + .Exe => { + if (builtin.link_libc) { + if (!@hasDecl(root, "main") or + @typeInfo(@typeOf(root.main)).Fn.calling_convention != .C) + { + @export("main", main, .Weak); + } + } else if (builtin.os == .windows) { + if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup")) { + @export("WinMainCRTStartup", WinMainCRTStartup, .Strong); + } + } else if (is_wasm and builtin.os == .freestanding) { + if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong); + } else if (builtin.os == .uefi) { + if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong); + } else if (is_mips) { + if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong); + } else { + if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong); + } + }, + .Lib => { + if (builtin.os == .windows and builtin.link_type == .Dynamic and + !@hasDecl(root, "_DllMainCRTStartup")) + { + @export("_DllMainCRTStartup", _DllMainCRTStartup, .Strong); + } + }, + .Obj => {}, } } +stdcallcc fn _DllMainCRTStartup( + hinstDLL: std.os.windows.HINSTANCE, + fdwReason: std.os.windows.DWORD, + lpReserved: std.os.windows.LPVOID, +) std.os.windows.BOOL { + if (@hasDecl(root, "DllMain")) { + return root.DllMain(hinstDLL, fdwReason, lpReserved); + } + + return std.os.windows.TRUE; +} + extern fn wasm_freestanding_start() 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. |
