| author | |
| committer | |
| log | b37acc4d6870a090c3501d81d3f647bc30220e4b |
| tree | 5b906c0cc4c9bb358d64324b25492a4b6cabd48a |
| parent | 81f1f72197113a45e827d5c984e219a28aa28083 |
| signature | Commit is signed but in an unrecognized format. |
Also:
* Expose `std.start.callMain`.
* Other fixes added to fix issues found in development.6 files changed, 25 insertions(+), 18 deletions(-)
lib/std/builtin.zig+4| ... | @@ -424,6 +424,10 @@ pub const panic: PanicFn = if (@hasDecl(root, "panic")) root.panic else default_ | ... | @@ -424,6 +424,10 @@ pub const panic: PanicFn = if (@hasDecl(root, "panic")) root.panic else default_ |
| 424 | /// therefore must be kept in sync with the compiler implementation. | 424 | /// therefore must be kept in sync with the compiler implementation. |
| 425 | pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn { | 425 | pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn { |
| 426 | @setCold(true); | 426 | @setCold(true); |
| 427 | if (@hasDecl(root, "os") and @hasDecl(root.os, "panic")) { | ||
| 428 | root.os.panic(msg, error_return_trace); | ||
| 429 | unreachable; | ||
| 430 | } | ||
| 427 | switch (os) { | 431 | switch (os) { |
| 428 | .freestanding => { | 432 | .freestanding => { |
| 429 | while (true) { | 433 | while (true) { |
lib/std/os.zig+12-8| ... | @@ -187,19 +187,23 @@ pub fn abort() noreturn { | ... | @@ -187,19 +187,23 @@ pub fn abort() noreturn { |
| 187 | } | 187 | } |
| 188 | windows.kernel32.ExitProcess(3); | 188 | windows.kernel32.ExitProcess(3); |
| 189 | } | 189 | } |
| 190 | if (builtin.link_libc) { | 190 | if (!builtin.link_libc and builtin.os == .linux) { |
| 191 | system.abort(); | 191 | raise(SIGABRT) catch {}; |
| 192 | |||
| 193 | // TODO the rest of the implementation of abort() from musl libc here | ||
| 194 | |||
| 195 | raise(SIGKILL) catch {}; | ||
| 196 | exit(127); | ||
| 192 | } | 197 | } |
| 193 | if (builtin.os == .uefi) { | 198 | if (builtin.os == .uefi) { |
| 194 | exit(0); // TODO choose appropriate exit code | 199 | exit(0); // TODO choose appropriate exit code |
| 195 | } | 200 | } |
| 201 | if (builtin.os == .wasi) { | ||
| 202 | @breakpoint(); | ||
| 203 | exit(1); | ||
| 204 | } | ||
| 196 | 205 | ||
| 197 | raise(SIGABRT) catch {}; | 206 | system.abort(); |
| 198 | |||
| 199 | // TODO the rest of the implementation of abort() from musl libc here | ||
| 200 | |||
| 201 | raise(SIGKILL) catch {}; | ||
| 202 | exit(127); | ||
| 203 | } | 207 | } |
| 204 | 208 | ||
| 205 | pub const RaiseError = UnexpectedError; | 209 | pub const RaiseError = UnexpectedError; |
lib/std/special.zig created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | pub const start = @import("special/start.zig"); | ||
lib/std/special/c.zig+1-1| ... | @@ -83,7 +83,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn | ... | @@ -83,7 +83,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn |
| 83 | @setCold(true); | 83 | @setCold(true); |
| 84 | std.debug.panic("{}", msg); | 84 | std.debug.panic("{}", msg); |
| 85 | } | 85 | } |
| 86 | if (builtin.os != .freestanding) { | 86 | if (builtin.os != .freestanding and builtin.os != .other) { |
| 87 | std.os.abort(); | 87 | std.os.abort(); |
| 88 | } | 88 | } |
| 89 | while (true) {} | 89 | while (true) {} |
lib/std/special/start.zig+6-9| ... | @@ -17,6 +17,7 @@ const is_mips = switch (builtin.arch) { | ... | @@ -17,6 +17,7 @@ const is_mips = switch (builtin.arch) { |
| 17 | .mips, .mipsel, .mips64, .mips64el => true, | 17 | .mips, .mipsel, .mips64, .mips64el => true, |
| 18 | else => false, | 18 | else => false, |
| 19 | }; | 19 | }; |
| 20 | const start_sym_name = if (is_mips) "__start" else "_start"; | ||
| 20 | 21 | ||
| 21 | comptime { | 22 | comptime { |
| 22 | if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { | 23 | if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { |
| ... | @@ -34,14 +35,10 @@ comptime { | ... | @@ -34,14 +35,10 @@ comptime { |
| 34 | } | 35 | } |
| 35 | } else if (builtin.os == .uefi) { | 36 | } else if (builtin.os == .uefi) { |
| 36 | if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong); | 37 | if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong); |
| 37 | } else if (builtin.os != .freestanding) { | 38 | } else if (is_wasm and builtin.os == .freestanding) { |
| 38 | if (is_mips) { | 39 | if (!@hasDecl(root, start_sym_name)) @export(start_sym_name, wasm_freestanding_start, .Strong); |
| 39 | if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong); | 40 | } else if (builtin.os != .other and builtin.os != .freestanding) { |
| 40 | } else { | 41 | if (!@hasDecl(root, start_sym_name)) @export(start_sym_name, _start, .Strong); |
| 41 | if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong); | ||
| 42 | } | ||
| 43 | } else if (is_wasm) { | ||
| 44 | if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong); | ||
| 45 | } | 42 | } |
| 46 | } | 43 | } |
| 47 | } | 44 | } |
| ... | @@ -247,7 +244,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 { | ... | @@ -247,7 +244,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 { |
| 247 | 244 | ||
| 248 | // This is not marked inline because it is called with @asyncCall when | 245 | // This is not marked inline because it is called with @asyncCall when |
| 249 | // there is an event loop. | 246 | // there is an event loop. |
| 250 | fn callMain() u8 { | 247 | pub fn callMain() u8 { |
| 251 | switch (@typeInfo(@TypeOf(root.main).ReturnType)) { | 248 | switch (@typeInfo(@TypeOf(root.main).ReturnType)) { |
| 252 | .NoReturn => { | 249 | .NoReturn => { |
| 253 | root.main(); | 250 | root.main(); |
lib/std/std.zig+1| ... | @@ -65,6 +65,7 @@ pub const time = @import("time.zig"); | ... | @@ -65,6 +65,7 @@ pub const time = @import("time.zig"); |
| 65 | pub const unicode = @import("unicode.zig"); | 65 | pub const unicode = @import("unicode.zig"); |
| 66 | pub const valgrind = @import("valgrind.zig"); | 66 | pub const valgrind = @import("valgrind.zig"); |
| 67 | pub const zig = @import("zig.zig"); | 67 | pub const zig = @import("zig.zig"); |
| 68 | pub const special = @import("special.zig"); | ||
| 68 | 69 | ||
| 69 | test "" { | 70 | test "" { |
| 70 | meta.refAllDecls(@This()); | 71 | meta.refAllDecls(@This()); |