authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-19 14:05:57+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-19 14:05:57+02:00
logc9b6f1bf907a0083f1fb0eba2f6969fd8f7f3b64
treecf688a9ca34012cf18376f6e1a9beb96040d4acc
parent27572373325b22b06767bc42cb7e270bf619f0a9

std: enable default panic handler for stage2 LLVM on Linux


4 files changed, 41 insertions(+), 17 deletions(-)

lib/std/builtin.zig+3-1
...@@ -753,7 +753,9 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn...@@ -753,7 +753,9 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace) noreturn
753 @setCold(true);753 @setCold(true);
754 // Until self-hosted catches up with stage1 language features, we have a simpler754 // Until self-hosted catches up with stage1 language features, we have a simpler
755 // default panic function:755 // default panic function:
756 if (builtin.zig_backend != .stage1) {756 const panic_works = builtin.zig_backend == .stage1 or
757 (builtin.zig_backend == .stage2_llvm and builtin.os.tag == .linux);
758 if (!panic_works) {
757 while (true) {759 while (true) {
758 @breakpoint();760 @breakpoint();
759 }761 }
lib/std/debug.zig-1
...@@ -1541,7 +1541,6 @@ pub const ModuleDebugInfo = switch (native_os) {...@@ -1541,7 +1541,6 @@ pub const ModuleDebugInfo = switch (native_os) {
1541 .symbol_name = o_file_di.getSymbolName(relocated_address_o) orelse "???",1541 .symbol_name = o_file_di.getSymbolName(relocated_address_o) orelse "???",
1542 .compile_unit_name = compile_unit.die.getAttrString(o_file_di, DW.AT.name) catch |err| switch (err) {1542 .compile_unit_name = compile_unit.die.getAttrString(o_file_di, DW.AT.name) catch |err| switch (err) {
1543 error.MissingDebugInfo, error.InvalidDebugInfo => "???",1543 error.MissingDebugInfo, error.InvalidDebugInfo => "???",
1544 else => return err,
1545 },1544 },
1546 .line_info = o_file_di.getLineNumberInfo(compile_unit.*, relocated_address_o + addr_off) catch |err| switch (err) {1545 .line_info = o_file_di.getLineNumberInfo(compile_unit.*, relocated_address_o + addr_off) catch |err| switch (err) {
1547 error.MissingDebugInfo, error.InvalidDebugInfo => null,1546 error.MissingDebugInfo, error.InvalidDebugInfo => null,
lib/std/heap/general_purpose_allocator.zig+2-2
...@@ -341,7 +341,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -341,7 +341,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
341 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);341 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
342 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);342 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
343 const addr = bucket.page + slot_index * size_class;343 const addr = bucket.page + slot_index * size_class;
344 if (builtin.zig_backend == .stage1) {344 if (builtin.zig_backend == .stage1 or builtin.os.tag == .linux) {
345 log.err("memory address 0x{x} leaked: {s}", .{345 log.err("memory address 0x{x} leaked: {s}", .{
346 @ptrToInt(addr), stack_trace,346 @ptrToInt(addr), stack_trace,
347 });347 });
...@@ -379,7 +379,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {...@@ -379,7 +379,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
379 while (it.next()) |large_alloc| {379 while (it.next()) |large_alloc| {
380 if (config.retain_metadata and large_alloc.freed) continue;380 if (config.retain_metadata and large_alloc.freed) continue;
381 const stack_trace = large_alloc.getStackTrace(.alloc);381 const stack_trace = large_alloc.getStackTrace(.alloc);
382 if (builtin.zig_backend == .stage1) {382 if (builtin.zig_backend == .stage1 or builtin.os.tag == .linux) {
383 log.err("memory address 0x{x} leaked: {s}", .{383 log.err("memory address 0x{x} leaked: {s}", .{
384 @ptrToInt(large_alloc.bytes.ptr), stack_trace,384 @ptrToInt(large_alloc.bytes.ptr), stack_trace,
385 });385 });
lib/std/os/linux.zig+36-13
...@@ -1080,12 +1080,19 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact...@@ -1080,12 +1080,19 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
1080 const mask_size = @sizeOf(@TypeOf(ksa.mask));1080 const mask_size = @sizeOf(@TypeOf(ksa.mask));
10811081
1082 if (act) |new| {1082 if (act) |new| {
1083 const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) restore_rt else restore;1083 const restore_rt_ptr = if (builtin.zig_backend == .stage1) restore_rt else &syscall_bits.restore_rt;
1084 // TODO https://github.com/ziglang/zig/issues/11227
1085 const restore_ptr = if (builtin.zig_backend == .stage1) restore else switch (native_arch) {
1086 .arm, .thumb, .mips, .mipsel, .i386 => &syscall_bits.restore,
1087 .x86_64, .aarch64, .riscv64, .sparcv9, .powerpc, .powerpc64, .powerpc64le => &syscall_bits.restore_rt,
1088 else => unreachable,
1089 };
1090 const restorer_fn = if ((new.flags & SA.SIGINFO) != 0) restore_rt_ptr else restore_ptr;
1084 ksa = k_sigaction{1091 ksa = k_sigaction{
1085 .handler = new.handler.handler,1092 .handler = new.handler.handler,
1086 .flags = new.flags | SA.RESTORER,1093 .flags = new.flags | SA.RESTORER,
1087 .mask = undefined,1094 .mask = undefined,
1088 .restorer = @ptrCast(fn () callconv(.C) void, restorer_fn),1095 .restorer = @ptrCast(k_sigaction_funcs.restorer, restorer_fn),
1089 };1096 };
1090 @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &new.mask), mask_size);1097 @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &new.mask), mask_size);
1091 }1098 }
...@@ -3047,39 +3054,55 @@ pub const sigset_t = [1024 / 32]u32;...@@ -3047,39 +3054,55 @@ pub const sigset_t = [1024 / 32]u32;
3047pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;3054pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;
3048pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;3055pub const app_mask: sigset_t = [2]u32{ 0xfffffffc, 0x7fffffff } ++ [_]u32{0xffffffff} ** 30;
30493056
3057const k_sigaction_funcs = if (builtin.zig_backend == .stage1) struct {
3058 const handler = ?fn (c_int) callconv(.C) void;
3059 const restorer = fn () callconv(.C) void;
3060} else struct {
3061 const handler = ?*const fn (c_int) callconv(.C) void;
3062 const restorer = *const fn () callconv(.C) void;
3063};
3064
3050pub const k_sigaction = switch (native_arch) {3065pub const k_sigaction = switch (native_arch) {
3051 .mips, .mipsel => extern struct {3066 .mips, .mipsel => extern struct {
3052 flags: c_uint,3067 flags: c_uint,
3053 handler: ?fn (c_int) callconv(.C) void,3068 handler: k_sigaction_funcs.handler,
3054 mask: [4]c_ulong,3069 mask: [4]c_ulong,
3055 restorer: fn () callconv(.C) void,3070 restorer: k_sigaction_funcs.restorer,
3056 },3071 },
3057 .mips64, .mips64el => extern struct {3072 .mips64, .mips64el => extern struct {
3058 flags: c_uint,3073 flags: c_uint,
3059 handler: ?fn (c_int) callconv(.C) void,3074 handler: k_sigaction_funcs.handler,
3060 mask: [2]c_ulong,3075 mask: [2]c_ulong,
3061 restorer: fn () callconv(.C) void,3076 restorer: k_sigaction_funcs.restorer,
3062 },3077 },
3063 else => extern struct {3078 else => extern struct {
3064 handler: ?fn (c_int) callconv(.C) void,3079 handler: k_sigaction_funcs.handler,
3065 flags: c_ulong,3080 flags: c_ulong,
3066 restorer: fn () callconv(.C) void,3081 restorer: k_sigaction_funcs.restorer,
3067 mask: [2]c_uint,3082 mask: [2]c_uint,
3068 },3083 },
3069};3084};
30703085
3071/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.3086/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
3072pub const Sigaction = extern struct {3087pub const Sigaction = extern struct {
3073 pub const handler_fn = fn (c_int) callconv(.C) void;3088 pub usingnamespace if (builtin.zig_backend == .stage1) struct {
3074 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;3089 pub const handler_fn = fn (c_int) callconv(.C) void;
3090 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
3091 } else struct {
3092 pub const handler_fn = *const fn (c_int) callconv(.C) void;
3093 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
3094 };
30753095
3076 handler: extern union {3096 handler: extern union {
3077 handler: ?handler_fn,3097 handler: ?Sigaction.handler_fn,
3078 sigaction: ?sigaction_fn,3098 sigaction: ?Sigaction.sigaction_fn,
3079 },3099 },
3080 mask: sigset_t,3100 mask: sigset_t,
3081 flags: c_uint,3101 flags: c_uint,
3082 restorer: ?fn () callconv(.C) void = null,3102 restorer: ?if (builtin.zig_backend == .stage1)
3103 fn () callconv(.C) void
3104 else
3105 *const fn () callconv(.C) void = null,
3083};3106};
30843107
3085pub const empty_sigset = [_]u32{0} ** @typeInfo(sigset_t).Array.len;3108pub const empty_sigset = [_]u32{0} ** @typeInfo(sigset_t).Array.len;