Skip to content

Commit 25d235d

Browse files
committed
default_panic: handle ".other" OS like ".freestanding"
The default panic handler needs to handle .other like .freestanding (i.e., infinite loop), as it cannot expect any of the std.debug.panicImpl code to work (which brings in Locks, Threads and Progress, etc). Also, update the unwind_freestanding.zig test case to also run on the .other OS target, too. This should keep the stacktrace generation in debug.zig working with that target.
1 parent 0a9d92c commit 25d235d

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

lib/std/builtin.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr
781781
}
782782

783783
switch (builtin.os.tag) {
784-
.freestanding => {
784+
.freestanding, .other => {
785785
while (true) {
786786
@breakpoint();
787787
}

test/standalone/stack_iterator/build.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,14 @@ pub fn build(b: *std.Build) void {
9898
// Unwinding without libc/posix
9999
//
100100
// No "getcontext" or "ucontext_t"
101-
{
101+
const no_os_targets = [_]std.Target.Os.Tag{ .freestanding, .other };
102+
inline for (no_os_targets) |os_tag| {
102103
const exe = b.addExecutable(.{
103104
.name = "unwind_freestanding",
104105
.root_source_file = b.path("unwind_freestanding.zig"),
105106
.target = b.resolveTargetQuery(.{
106107
.cpu_arch = .x86_64,
107-
.os_tag = .freestanding,
108+
.os_tag = os_tag,
108109
}),
109110
.optimize = optimize,
110111
.unwind_tables = null,

test/standalone/stack_iterator/unwind_freestanding.zig

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void {
3636
frame1(expected, unwound);
3737
}
3838

39-
// Freestanding entrypoint
39+
// No-OS entrypoint
4040
export fn _start() callconv(.C) noreturn {
4141
var expected: [4]usize = undefined;
4242
var unwound: [4]usize = undefined;
@@ -50,8 +50,9 @@ export fn _start() callconv(.C) noreturn {
5050
}
5151
}
5252

53-
// Need to compile as "freestanding" to exercise the StackIterator code, but when run as a
54-
// regression test need to actually exit. So assume we're running on x86_64-linux ...
53+
// Need to compile with the target OS as "freestanding" or "other" to
54+
// exercise the StackIterator code, but when run as a regression test
55+
// need to actually exit. So assume we're running on x86_64-linux ...
5556
asm volatile (
5657
\\movl $60, %%eax
5758
\\syscall

0 commit comments

Comments
 (0)