aboutsummaryrefslogtreecommitdiff
path: root/lib/std/start.zig
diff options
context:
space:
mode:
authorDavid Rubin <daviru007@icloud.com>2024-04-16 22:44:55 -0700
committerDavid Rubin <daviru007@icloud.com>2024-05-11 02:17:24 -0700
commitffb63a05a3327e64bcf8ec7fd05c6aab8d304480 (patch)
tree5284c825f8126f35d756599f524a2f612620ddd4 /lib/std/start.zig
parent2fd83d8c0a8dd28c2474b26ead8cb24d6bde0901 (diff)
downloadzig-ffb63a05a3327e64bcf8ec7fd05c6aab8d304480.tar.gz
zig-ffb63a05a3327e64bcf8ec7fd05c6aab8d304480.zip
riscv: finally fix bug + `airAggregateInit`
i just hadn't realized that I placed the `riscv_start` branch in the non-simplified starts
Diffstat (limited to 'lib/std/start.zig')
-rw-r--r--lib/std/start.zig26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig
index 5fad443956..ff97e3c8ae 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -22,7 +22,8 @@ pub const simplified_logic =
builtin.zig_backend == .stage2_arm or
builtin.zig_backend == .stage2_sparc64 or
builtin.cpu.arch == .spirv32 or
- builtin.cpu.arch == .spirv64;
+ builtin.cpu.arch == .spirv64 or
+ builtin.zig_backend == .stage2_riscv64;
comptime {
// No matter what, we import the root file, so that any export, test, comptime
@@ -42,6 +43,10 @@ comptime {
} else if (builtin.os.tag == .opencl) {
if (@hasDecl(root, "main"))
@export(spirvMain2, .{ .name = "main" });
+ } else if (native_arch.isRISCV()) {
+ if (!@hasDecl(root, "_start")) {
+ @export(riscv_start, .{ .name = "_start" });
+ }
} else {
if (!@hasDecl(root, "_start")) {
@export(_start2, .{ .name = "_start" });
@@ -60,10 +65,6 @@ comptime {
} else if (@typeInfo(@TypeOf(root.main)).Fn.calling_convention != .C) {
@export(main, .{ .name = "main" });
}
- } else if (native_arch.isRISCV()) {
- if (!@hasDecl(root, "_start")) {
- @export(riscv_start, .{ .name = "_start" });
- }
} else if (native_os == .windows) {
if (!@hasDecl(root, "WinMain") and !@hasDecl(root, "WinMainCRTStartup") and
!@hasDecl(root, "wWinMain") and !@hasDecl(root, "wWinMainCRTStartup"))
@@ -208,7 +209,20 @@ fn wasi_start() callconv(.C) void {
}
fn riscv_start() callconv(.C) noreturn {
- std.process.exit(@call(.always_inline, callMain, .{}));
+ std.process.exit(switch (@typeInfo(@typeInfo(@TypeOf(root.main)).Fn.return_type.?)) {
+ .NoReturn => root.main(),
+ .Void => ret: {
+ root.main();
+ break :ret 0;
+ },
+ .Int => |info| ret: {
+ if (info.bits != 8 or info.signedness == .signed) {
+ @compileError(bad_main_ret);
+ }
+ break :ret root.main();
+ },
+ else => @compileError("expected return type of main to be 'void', 'noreturn', 'u8'"),
+ });
}
fn EfiMain(handle: uefi.Handle, system_table: *uefi.tables.SystemTable) callconv(.C) usize {