From 5e1a83ad2975afdca4f3c9d11ace61fa5dad205a Mon Sep 17 00:00:00 2001 From: Pat Tullmann Date: Sun, 28 Jul 2024 13:14:45 -0700 Subject: [PATCH] defaultPanic: @trap on 'other' target The freestanding and other OS targets by default need to just @trap in the default Panic implementation. And `isValidMemory` won't work with freestanding or other targets. Update the unwind_freestanding.zig test case to also run on the 'other' OS target, too. This should keep the Zig's stacktrace generation from regressing on the standalone targets. --- lib/std/debug.zig | 2 +- lib/std/debug/MemoryAccessor.zig | 2 +- test/standalone/stack_iterator/build.zig | 5 +++-- test/standalone/stack_iterator/unwind_freestanding.zig | 7 ++++--- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 0756e456ff59..e8855f5d1ad3 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -480,7 +480,7 @@ pub fn defaultPanic( } switch (builtin.os.tag) { - .freestanding => { + .freestanding, .other => { @trap(); }, .uefi => { diff --git a/lib/std/debug/MemoryAccessor.zig b/lib/std/debug/MemoryAccessor.zig index a420d9cdcf47..9f112262be41 100644 --- a/lib/std/debug/MemoryAccessor.zig +++ b/lib/std/debug/MemoryAccessor.zig @@ -80,7 +80,7 @@ pub fn load(ma: *MemoryAccessor, comptime Type: type, address: usize) ?Type { pub fn isValidMemory(address: usize) bool { // We are unable to determine validity of memory for freestanding targets - if (native_os == .freestanding or native_os == .uefi) return true; + if (native_os == .freestanding or native_os == .other or native_os == .uefi) return true; const aligned_address = address & ~@as(usize, @intCast((page_size - 1))); if (aligned_address == 0) return false; diff --git a/test/standalone/stack_iterator/build.zig b/test/standalone/stack_iterator/build.zig index d69d59091238..ac9a6769304c 100644 --- a/test/standalone/stack_iterator/build.zig +++ b/test/standalone/stack_iterator/build.zig @@ -113,13 +113,14 @@ pub fn build(b: *std.Build) void { // Unwinding without libc/posix // // No "getcontext" or "ucontext_t" - { + const no_os_targets = [_]std.Target.Os.Tag{ .freestanding, .other }; + inline for (no_os_targets) |os_tag| { const exe = b.addExecutable(.{ .name = "unwind_freestanding", .root_source_file = b.path("unwind_freestanding.zig"), .target = b.resolveTargetQuery(.{ .cpu_arch = .x86_64, - .os_tag = .freestanding, + .os_tag = os_tag, }), .optimize = optimize, .unwind_tables = null, diff --git a/test/standalone/stack_iterator/unwind_freestanding.zig b/test/standalone/stack_iterator/unwind_freestanding.zig index b81a8a66e89d..38ec5dd1018f 100644 --- a/test/standalone/stack_iterator/unwind_freestanding.zig +++ b/test/standalone/stack_iterator/unwind_freestanding.zig @@ -36,7 +36,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void { frame1(expected, unwound); } -// Freestanding entrypoint +// No-OS entrypoint export fn _start() callconv(.C) noreturn { var expected: [4]usize = undefined; var unwound: [4]usize = undefined; @@ -50,8 +50,9 @@ export fn _start() callconv(.C) noreturn { } } - // Need to compile as "freestanding" to exercise the StackIterator code, but when run as a - // regression test need to actually exit. So assume we're running on x86_64-linux ... + // Need to compile with the target OS as "freestanding" or "other" to + // exercise the StackIterator code, but when run as a regression test + // need to actually exit. So assume we're running on x86_64-linux ... asm volatile ( \\movl $60, %%eax \\syscall