aboutsummaryrefslogtreecommitdiff
path: root/lib/std/start.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-07-01 15:52:54 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-07-01 15:52:54 -0700
commitc89dd15e1be4959800dc7092d7dd4375253db7bc (patch)
treeca184ae53592efa21e67128a5f891d642d7f1118 /lib/std/start.zig
parent5466e87fce581f2ef90ac23bb80b1dbc05836fc6 (diff)
parent2360f8c490f3ec684ed64ff28e8c1fade249070b (diff)
downloadzig-c89dd15e1be4959800dc7092d7dd4375253db7bc.tar.gz
zig-c89dd15e1be4959800dc7092d7dd4375253db7bc.zip
Merge remote-tracking branch 'origin/master' into llvm14
Diffstat (limited to 'lib/std/start.zig')
-rw-r--r--lib/std/start.zig32
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig
index a3cc3d00a8..516d6363d7 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -22,7 +22,15 @@ comptime {
// The self-hosted compiler is not fully capable of handling all of this start.zig file.
// Until then, we have simplified logic here for self-hosted. TODO remove this once
// self-hosted is capable enough to handle all of the real start.zig logic.
- if (builtin.zig_backend != .stage1) {
+ if (builtin.zig_backend == .stage2_wasm or
+ builtin.zig_backend == .stage2_c or
+ builtin.zig_backend == .stage2_x86_64 or
+ builtin.zig_backend == .stage2_x86 or
+ builtin.zig_backend == .stage2_aarch64 or
+ builtin.zig_backend == .stage2_arm or
+ builtin.zig_backend == .stage2_riscv64 or
+ builtin.zig_backend == .stage2_sparc64)
+ {
if (builtin.output_mode == .Exe) {
if ((builtin.link_libc or builtin.object_format == .c) and @hasDecl(root, "main")) {
if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
@@ -31,7 +39,7 @@ comptime {
} else if (builtin.os.tag == .windows) {
@export(wWinMainCRTStartup2, .{ .name = "wWinMainCRTStartup" });
} else if (builtin.os.tag == .wasi and @hasDecl(root, "main")) {
- @export(wasmMain2, .{ .name = "_start" });
+ @export(wasiMain2, .{ .name = "_start" });
} else {
if (!@hasDecl(root, "_start")) {
@export(_start2, .{ .name = "_start" });
@@ -100,17 +108,17 @@ fn callMain2() noreturn {
exit2(0);
}
-fn wasmMain2() u8 {
+fn wasiMain2() noreturn {
switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {
.Void => {
root.main();
- return 0;
+ std.os.wasi.proc_exit(0);
},
.Int => |info| {
if (info.bits != 8 or info.signedness == .signed) {
@compileError(bad_main_ret);
}
- return root.main();
+ std.os.wasi.proc_exit(root.main());
},
else => @compileError("Bad return type main"),
}
@@ -156,6 +164,14 @@ fn exit2(code: usize) noreturn {
: "rcx", "r11", "memory"
);
},
+ .sparc64 => {
+ asm volatile ("ta 0x6d"
+ :
+ : [number] "{g1}" (1),
+ [arg1] "{o0}" (code),
+ : "o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7", "memory"
+ );
+ },
else => @compileError("TODO"),
},
// exits(0)
@@ -307,7 +323,7 @@ fn _start() callconv(.Naked) noreturn {
: "r0"
);
},
- .sparcv9 => {
+ .sparc64 => {
// argc is stored after a register window (16 registers) plus stack bias
argc_argv_ptr = asm (
\\ mov %%g0, %%i6
@@ -440,6 +456,10 @@ fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
std.os.argv = argv[0..argc];
std.os.environ = envp;
+ if (builtin.zig_backend == .stage2_llvm) {
+ return @call(.{ .modifier = .always_inline }, callMain, .{});
+ }
+
std.debug.maybeEnableSegfaultHandler();
return initEventLoopAndCallMain();