diff options
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/builtin.zig | 11 | ||||
| -rw-r--r-- | lib/std/os.zig | 20 | ||||
| -rw-r--r-- | lib/std/special/c.zig | 2 | ||||
| -rw-r--r-- | lib/std/special/test_runner.zig | 6 | ||||
| -rw-r--r-- | lib/std/start.zig (renamed from lib/std/special/start.zig) | 19 | ||||
| -rw-r--r-- | lib/std/start_windows_tls.zig (renamed from lib/std/special/start_windows_tls.zig) | 2 | ||||
| -rw-r--r-- | lib/std/std.zig | 7 |
7 files changed, 44 insertions, 23 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 36fa46e953..687e169bbe 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -414,6 +414,13 @@ pub const CallOptions = struct { /// This function type is used by the Zig language code generation and /// therefore must be kept in sync with the compiler implementation. +pub const TestFn = struct { + name: []const u8, + func: fn()anyerror!void, +}; + +/// This function type is used by the Zig language code generation and +/// therefore must be kept in sync with the compiler implementation. pub const PanicFn = fn ([]const u8, ?*StackTrace) noreturn; /// This function is used by the Zig language code generation and @@ -424,6 +431,10 @@ pub const panic: PanicFn = if (@hasDecl(root, "panic")) root.panic else default_ /// therefore must be kept in sync with the compiler implementation. pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn { @setCold(true); + if (@hasDecl(root, "os") and @hasDecl(root.os, "panic")) { + root.os.panic(msg, error_return_trace); + unreachable; + } switch (os) { .freestanding => { while (true) { diff --git a/lib/std/os.zig b/lib/std/os.zig index 04de59d6e1..6d49bcd38e 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -187,19 +187,23 @@ pub fn abort() noreturn { } windows.kernel32.ExitProcess(3); } - if (builtin.link_libc) { - system.abort(); + if (!builtin.link_libc and builtin.os == .linux) { + raise(SIGABRT) catch {}; + + // TODO the rest of the implementation of abort() from musl libc here + + raise(SIGKILL) catch {}; + exit(127); } if (builtin.os == .uefi) { exit(0); // TODO choose appropriate exit code } + if (builtin.os == .wasi) { + @breakpoint(); + exit(1); + } - raise(SIGABRT) catch {}; - - // TODO the rest of the implementation of abort() from musl libc here - - raise(SIGKILL) catch {}; - exit(127); + system.abort(); } pub const RaiseError = UnexpectedError; diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig index 4c2eb2a958..0895b1e6f9 100644 --- a/lib/std/special/c.zig +++ b/lib/std/special/c.zig @@ -83,7 +83,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn @setCold(true); std.debug.panic("{}", msg); } - if (builtin.os != .freestanding) { + if (builtin.os != .freestanding and builtin.os != .other) { std.os.abort(); } while (true) {} diff --git a/lib/std/special/test_runner.zig b/lib/std/special/test_runner.zig index 7bb53774d3..0335c8562d 100644 --- a/lib/std/special/test_runner.zig +++ b/lib/std/special/test_runner.zig @@ -1,9 +1,9 @@ const std = @import("std"); const io = std.io; const builtin = @import("builtin"); -const test_fn_list = builtin.test_functions; pub fn main() anyerror!void { + const test_fn_list = builtin.test_functions; var ok_count: usize = 0; var skip_count: usize = 0; var progress = std.Progress{}; @@ -16,7 +16,9 @@ pub fn main() anyerror!void { var test_node = root_node.start(test_fn.name, null); test_node.activate(); progress.refresh(); - if (progress.terminal == null) std.debug.warn("{}/{} {}...", .{ i + 1, test_fn_list.len, test_fn.name }); + if (progress.terminal == null) { + std.debug.warn("{}/{} {}...", .{ i + 1, test_fn_list.len, test_fn.name }); + } if (test_fn.func()) |_| { ok_count += 1; test_node.end(); diff --git a/lib/std/special/start.zig b/lib/std/start.zig index 60745dab7f..3c46449949 100644 --- a/lib/std/special/start.zig +++ b/lib/std/start.zig @@ -1,8 +1,8 @@ // This file is included in the compilation unit when exporting an executable. const root = @import("root"); -const std = @import("std"); -const builtin = @import("builtin"); +const std = @import("std.zig"); +const builtin = std.builtin; const assert = std.debug.assert; const uefi = std.os.uefi; @@ -17,6 +17,7 @@ const is_mips = switch (builtin.arch) { .mips, .mipsel, .mips64, .mips64el => true, else => false, }; +const start_sym_name = if (is_mips) "__start" else "_start"; comptime { if (builtin.output_mode == .Lib and builtin.link_mode == .Dynamic) { @@ -34,14 +35,10 @@ comptime { } } else if (builtin.os == .uefi) { if (!@hasDecl(root, "EfiMain")) @export("EfiMain", EfiMain, .Strong); - } else if (builtin.os != .freestanding) { - if (is_mips) { - if (!@hasDecl(root, "__start")) @export("__start", _start, .Strong); - } else { - if (!@hasDecl(root, "_start")) @export("_start", _start, .Strong); - } - } else if (is_wasm) { - if (!@hasDecl(root, "_start")) @export("_start", wasm_freestanding_start, .Strong); + } else if (is_wasm and builtin.os == .freestanding) { + if (!@hasDecl(root, start_sym_name)) @export(start_sym_name, wasm_freestanding_start, .Strong); + } else if (builtin.os != .other and builtin.os != .freestanding) { + if (!@hasDecl(root, start_sym_name)) @export(start_sym_name, _start, .Strong); } } } @@ -247,7 +244,7 @@ async fn callMainAsync(loop: *std.event.Loop) u8 { // This is not marked inline because it is called with @asyncCall when // there is an event loop. -fn callMain() u8 { +pub fn callMain() u8 { switch (@typeInfo(@TypeOf(root.main).ReturnType)) { .NoReturn => { root.main(); diff --git a/lib/std/special/start_windows_tls.zig b/lib/std/start_windows_tls.zig index bfd0e44122..f6dd2bc132 100644 --- a/lib/std/special/start_windows_tls.zig +++ b/lib/std/start_windows_tls.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const builtin = @import("builtin"); +const builtin = std.builtin; export var _tls_index: u32 = std.os.windows.TLS_OUT_OF_INDEXES; export var _tls_start: u8 linksection(".tls") = 0; diff --git a/lib/std/std.zig b/lib/std/std.zig index 09db489604..dd4d968efb 100644 --- a/lib/std/std.zig +++ b/lib/std/std.zig @@ -65,6 +65,13 @@ pub const time = @import("time.zig"); pub const unicode = @import("unicode.zig"); pub const valgrind = @import("valgrind.zig"); pub const zig = @import("zig.zig"); +pub const start = @import("start.zig"); + +// This forces the start.zig file to be imported, and the comptime logic inside that +// file decides whether to export any appropriate start symbols. +comptime { + _ = start; +} test "" { meta.refAllDecls(@This()); |
