authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-01 21:34:14-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-04 00:27:08-08:00
log0ca83dd9d2d3fb38bc1e7baf773fb67a37a2bd2a
treef2ee2ca7bb2bfb01c4f73c9d6ebb0d9c311f3e32
parent85fe35d246d0076d403fc5ee90f4434da7206fd5

start: fix compilation with -lc on windows


1 files changed, 19 insertions(+), 8 deletions(-)

lib/std/start.zig+19-8
...@@ -623,22 +623,33 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [:null]?[*:0]u8)...@@ -623,22 +623,33 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [:null]?[*:0]u8)
623 return callMain(argv[0..argc], envp);623 return callMain(argv[0..argc], envp);
624}624}
625625
626fn main(c_argc: c_int, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) callconv(.c) c_int {626fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.c) c_int {
627 var env_count: usize = 0;627 var env_count: usize = 0;
628 while (c_envp[env_count] != null) : (env_count += 1) {}628 while (c_envp[env_count] != null) : (env_count += 1) {}
629 const envp = c_envp[0..env_count :null];629 const envp = c_envp[0..env_count :null];
630630
631 if (builtin.os.tag == .linux) {631 switch (builtin.os.tag) {
632 const at_phdr = std.c.getauxval(elf.AT_PHDR);632 .linux => {
633 const at_phnum = std.c.getauxval(elf.AT_PHNUM);633 const at_phdr = std.c.getauxval(elf.AT_PHDR);
634 const phdrs = (@as([*]elf.Phdr, @ptrFromInt(at_phdr)))[0..at_phnum];634 const at_phnum = std.c.getauxval(elf.AT_PHNUM);
635 expandStackSize(phdrs);635 const phdrs = (@as([*]elf.Phdr, @ptrFromInt(at_phdr)))[0..at_phnum];
636 expandStackSize(phdrs);
637 },
638 .windows => {
639 // On Windows, we ignore libc environment and argv and get those
640 // values in their intended encoding from the PEB instead.
641 std.debug.maybeEnableSegfaultHandler();
642 const cmd_line = std.os.windows.peb().ProcessParameters.CommandLine;
643 const cmd_line_w = cmd_line.Buffer.?[0..@divExact(cmd_line.Length, 2)];
644 return callMain(cmd_line_w, {});
645 },
646 else => {},
636 }647 }
637648
638 return callMainWithArgs(@as(usize, @intCast(c_argc)), @as([*][*:0]u8, @ptrCast(c_argv)), envp);649 return callMainWithArgs(@as(usize, @intCast(c_argc)), @as([*][*:0]u8, @ptrCast(c_argv)), @ptrCast(envp));
639}650}
640651
641fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]u8) callconv(.c) c_int {652fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int {
642 const argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@intCast(c_argc)];653 const argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@intCast(c_argc)];
643 if (@sizeOf(std.Io.Threaded.Argv0) != 0) {654 if (@sizeOf(std.Io.Threaded.Argv0) != 0) {
644 if (std.Options.debug_threaded_io) |t| t.argv0.value = argv[0];655 if (std.Options.debug_threaded_io) |t| t.argv0.value = argv[0];