authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-10-28 22:15:44+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-02 10:44:18+01:00
log8a2d960627dc5362da2aa4093f58665adb6b9b4b
treee2eab1f2bf47efa5fcf3487220f503fc051b9ee8
parentbaf60426d48adbd938406f07bbbd0dfdf012943b
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

start: Fix a calling convention check to use eql().

Also modernize some callconv uses. Closes #21813.

1 files changed, 15 insertions(+), 15 deletions(-)

lib/std/start.zig+15-15
...@@ -29,7 +29,7 @@ comptime {...@@ -29,7 +29,7 @@ comptime {
29 if (simplified_logic) {29 if (simplified_logic) {
30 if (builtin.output_mode == .Exe) {30 if (builtin.output_mode == .Exe) {
31 if ((builtin.link_libc or builtin.object_format == .c) and @hasDecl(root, "main")) {31 if ((builtin.link_libc or builtin.object_format == .c) and @hasDecl(root, "main")) {
32 if (@typeInfo(@TypeOf(root.main)).@"fn".calling_convention != .C) {32 if (!@typeInfo(@TypeOf(root.main)).@"fn".calling_convention.eql(.c)) {
33 @export(&main2, .{ .name = "main" });33 @export(&main2, .{ .name = "main" });
34 }34 }
35 } else if (builtin.os.tag == .windows) {35 } else if (builtin.os.tag == .windows) {
...@@ -96,7 +96,7 @@ comptime {...@@ -96,7 +96,7 @@ comptime {
9696
97// Simplified start code for stage2 until it supports more language features ///97// Simplified start code for stage2 until it supports more language features ///
9898
99fn main2() callconv(.C) c_int {99fn main2() callconv(.c) c_int {
100 root.main();100 root.main();
101 return 0;101 return 0;
102}102}
...@@ -110,11 +110,11 @@ fn callMain2() noreturn {...@@ -110,11 +110,11 @@ fn callMain2() noreturn {
110 exit2(0);110 exit2(0);
111}111}
112112
113fn spirvMain2() callconv(.Kernel) void {113fn spirvMain2() callconv(.kernel) void {
114 root.main();114 root.main();
115}115}
116116
117fn wWinMainCRTStartup2() callconv(.C) noreturn {117fn wWinMainCRTStartup2() callconv(.c) noreturn {
118 root.main();118 root.main();
119 exit2(0);119 exit2(0);
120}120}
...@@ -172,7 +172,7 @@ fn _DllMainCRTStartup(...@@ -172,7 +172,7 @@ fn _DllMainCRTStartup(
172 hinstDLL: std.os.windows.HINSTANCE,172 hinstDLL: std.os.windows.HINSTANCE,
173 fdwReason: std.os.windows.DWORD,173 fdwReason: std.os.windows.DWORD,
174 lpReserved: std.os.windows.LPVOID,174 lpReserved: std.os.windows.LPVOID,
175) callconv(std.os.windows.WINAPI) std.os.windows.BOOL {175) callconv(.winapi) std.os.windows.BOOL {
176 if (!builtin.single_threaded and !builtin.link_libc) {176 if (!builtin.single_threaded and !builtin.link_libc) {
177 _ = @import("os/windows/tls.zig");177 _ = @import("os/windows/tls.zig");
178 }178 }
...@@ -184,13 +184,13 @@ fn _DllMainCRTStartup(...@@ -184,13 +184,13 @@ fn _DllMainCRTStartup(
184 return std.os.windows.TRUE;184 return std.os.windows.TRUE;
185}185}
186186
187fn wasm_freestanding_start() callconv(.C) void {187fn wasm_freestanding_start() callconv(.c) void {
188 // This is marked inline because for some reason LLVM in188 // This is marked inline because for some reason LLVM in
189 // release mode fails to inline it, and we want fewer call frames in stack traces.189 // release mode fails to inline it, and we want fewer call frames in stack traces.
190 _ = @call(.always_inline, callMain, .{});190 _ = @call(.always_inline, callMain, .{});
191}191}
192192
193fn wasi_start() callconv(.C) void {193fn wasi_start() callconv(.c) void {
194 // The function call is marked inline because for some reason LLVM in194 // The function call is marked inline because for some reason LLVM in
195 // release mode fails to inline it, and we want fewer call frames in stack traces.195 // release mode fails to inline it, and we want fewer call frames in stack traces.
196 switch (builtin.wasi_exec_model) {196 switch (builtin.wasi_exec_model) {
...@@ -199,7 +199,7 @@ fn wasi_start() callconv(.C) void {...@@ -199,7 +199,7 @@ fn wasi_start() callconv(.C) void {
199 }199 }
200}200}
201201
202fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.C) usize {202fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.c) usize {
203 uefi.handle = handle;203 uefi.handle = handle;
204 uefi.system_table = system_table;204 uefi.system_table = system_table;
205205
...@@ -221,7 +221,7 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv...@@ -221,7 +221,7 @@ fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv
221 }221 }
222}222}
223223
224fn _start() callconv(.Naked) noreturn {224fn _start() callconv(.naked) noreturn {
225 // TODO set Top of Stack on non x86_64-plan9225 // TODO set Top of Stack on non x86_64-plan9
226 if (native_os == .plan9 and native_arch == .x86_64) {226 if (native_os == .plan9 and native_arch == .x86_64) {
227 // from /sys/src/libc/amd64/main9.s227 // from /sys/src/libc/amd64/main9.s
...@@ -447,7 +447,7 @@ fn wWinMainCRTStartup() callconv(.withStackAlign(.winapi, 1)) noreturn {...@@ -447,7 +447,7 @@ fn wWinMainCRTStartup() callconv(.withStackAlign(.winapi, 1)) noreturn {
447 std.os.windows.ntdll.RtlExitUserProcess(@as(std.os.windows.UINT, @bitCast(result)));447 std.os.windows.ntdll.RtlExitUserProcess(@as(std.os.windows.UINT, @bitCast(result)));
448}448}
449449
450fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn {450fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn {
451 // We're not ready to panic until thread local storage is initialized.451 // We're not ready to panic until thread local storage is initialized.
452 @setRuntimeSafety(false);452 @setRuntimeSafety(false);
453 // Code coverage instrumentation might try to use thread local variables.453 // Code coverage instrumentation might try to use thread local variables.
...@@ -514,11 +514,11 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn {...@@ -514,11 +514,11 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn {
514 // to ask for more stack space.514 // to ask for more stack space.
515 expandStackSize(phdrs);515 expandStackSize(phdrs);
516516
517 const opt_init_array_start = @extern([*]*const fn () callconv(.C) void, .{517 const opt_init_array_start = @extern([*]*const fn () callconv(.c) void, .{
518 .name = "__init_array_start",518 .name = "__init_array_start",
519 .linkage = .weak,519 .linkage = .weak,
520 });520 });
521 const opt_init_array_end = @extern([*]*const fn () callconv(.C) void, .{521 const opt_init_array_end = @extern([*]*const fn () callconv(.c) void, .{
522 .name = "__init_array_end",522 .name = "__init_array_end",
523 .linkage = .weak,523 .linkage = .weak,
524 });524 });
...@@ -577,7 +577,7 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {...@@ -577,7 +577,7 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
577 return callMain();577 return callMain();
578}578}
579579
580fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.C) c_int {580fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) callconv(.c) c_int {
581 var env_count: usize = 0;581 var env_count: usize = 0;
582 while (c_envp[env_count] != null) : (env_count += 1) {}582 while (c_envp[env_count] != null) : (env_count += 1) {}
583 const envp = @as([*][*:0]u8, @ptrCast(c_envp))[0..env_count];583 const envp = @as([*][*:0]u8, @ptrCast(c_envp))[0..env_count];
...@@ -592,7 +592,7 @@ fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) cal...@@ -592,7 +592,7 @@ fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) cal
592 return callMainWithArgs(@as(usize, @intCast(c_argc)), @as([*][*:0]u8, @ptrCast(c_argv)), envp);592 return callMainWithArgs(@as(usize, @intCast(c_argc)), @as([*][*:0]u8, @ptrCast(c_argv)), envp);
593}593}
594594
595fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.C) c_int {595fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int {
596 std.os.argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@as(usize, @intCast(c_argc))];596 std.os.argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@as(usize, @intCast(c_argc))];
597 return callMain();597 return callMain();
598}598}
...@@ -702,4 +702,4 @@ fn maybeIgnoreSigpipe() void {...@@ -702,4 +702,4 @@ fn maybeIgnoreSigpipe() void {
702 }702 }
703}703}
704704
705fn noopSigHandler(_: i32) callconv(.C) void {}705fn noopSigHandler(_: i32) callconv(.c) void {}