authorgravatar for pat.github@tullmann.orgPat Tullmann <pat.github@tullmann.org> 2024-07-28 13:14:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-11-29 15:30:05-05:00
log5e1a83ad2975afdca4f3c9d11ace61fa5dad205a
treedbe969d38e964e3127ff4831363f01b7e08de780
parenta47aa9dd9d7f950427aacc360f1302e636234bc2

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.

4 files changed, 9 insertions(+), 7 deletions(-)

lib/std/debug.zig+1-1
...@@ -480,7 +480,7 @@ pub fn defaultPanic(...@@ -480,7 +480,7 @@ pub fn defaultPanic(
480 }480 }
481481
482 switch (builtin.os.tag) {482 switch (builtin.os.tag) {
483 .freestanding => {483 .freestanding, .other => {
484 @trap();484 @trap();
485 },485 },
486 .uefi => {486 .uefi => {
lib/std/debug/MemoryAccessor.zig+1-1
...@@ -80,7 +80,7 @@ pub fn load(ma: *MemoryAccessor, comptime Type: type, address: usize) ?Type {...@@ -80,7 +80,7 @@ pub fn load(ma: *MemoryAccessor, comptime Type: type, address: usize) ?Type {
8080
81pub fn isValidMemory(address: usize) bool {81pub fn isValidMemory(address: usize) bool {
82 // We are unable to determine validity of memory for freestanding targets82 // We are unable to determine validity of memory for freestanding targets
83 if (native_os == .freestanding or native_os == .uefi) return true;83 if (native_os == .freestanding or native_os == .other or native_os == .uefi) return true;
8484
85 const aligned_address = address & ~@as(usize, @intCast((page_size - 1)));85 const aligned_address = address & ~@as(usize, @intCast((page_size - 1)));
86 if (aligned_address == 0) return false;86 if (aligned_address == 0) return false;
test/standalone/stack_iterator/build.zig+3-2
...@@ -113,13 +113,14 @@ pub fn build(b: *std.Build) void {...@@ -113,13 +113,14 @@ pub fn build(b: *std.Build) void {
113 // Unwinding without libc/posix113 // Unwinding without libc/posix
114 //114 //
115 // No "getcontext" or "ucontext_t"115 // No "getcontext" or "ucontext_t"
116 {116 const no_os_targets = [_]std.Target.Os.Tag{ .freestanding, .other };
117 inline for (no_os_targets) |os_tag| {
117 const exe = b.addExecutable(.{118 const exe = b.addExecutable(.{
118 .name = "unwind_freestanding",119 .name = "unwind_freestanding",
119 .root_source_file = b.path("unwind_freestanding.zig"),120 .root_source_file = b.path("unwind_freestanding.zig"),
120 .target = b.resolveTargetQuery(.{121 .target = b.resolveTargetQuery(.{
121 .cpu_arch = .x86_64,122 .cpu_arch = .x86_64,
122 .os_tag = .freestanding,123 .os_tag = os_tag,
123 }),124 }),
124 .optimize = optimize,125 .optimize = optimize,
125 .unwind_tables = null,126 .unwind_tables = null,
test/standalone/stack_iterator/unwind_freestanding.zig+4-3
...@@ -36,7 +36,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void {...@@ -36,7 +36,7 @@ noinline fn frame0(expected: *[4]usize, unwound: *[4]usize) void {
36 frame1(expected, unwound);36 frame1(expected, unwound);
37}37}
3838
39// Freestanding entrypoint39// No-OS entrypoint
40export fn _start() callconv(.C) noreturn {40export fn _start() callconv(.C) noreturn {
41 var expected: [4]usize = undefined;41 var expected: [4]usize = undefined;
42 var unwound: [4]usize = undefined;42 var unwound: [4]usize = undefined;
...@@ -50,8 +50,9 @@ export fn _start() callconv(.C) noreturn {...@@ -50,8 +50,9 @@ export fn _start() callconv(.C) noreturn {
50 }50 }
51 }51 }
5252
53 // Need to compile as "freestanding" to exercise the StackIterator code, but when run as a53 // Need to compile with the target OS as "freestanding" or "other" to
54 // regression test need to actually exit. So assume we're running on x86_64-linux ...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 ...
55 asm volatile (56 asm volatile (
56 \\movl $60, %%eax57 \\movl $60, %%eax
57 \\syscall58 \\syscall