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
753753 @setCold(true);
754754 // Until self-hosted catches up with stage1 language features, we have a simpler
755755 // 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) {
757759 while (true) {
758760 @breakpoint();
759761 }
lib/std/debug.zig-1
......@@ -1541,7 +1541,6 @@ pub const ModuleDebugInfo = switch (native_os) {
15411541 .symbol_name = o_file_di.getSymbolName(relocated_address_o) orelse "???",
15421542 .compile_unit_name = compile_unit.die.getAttrString(o_file_di, DW.AT.name) catch |err| switch (err) {
15431543 error.MissingDebugInfo, error.InvalidDebugInfo => "???",
1544 else => return err,
15451544 },
15461545 .line_info = o_file_di.getLineNumberInfo(compile_unit.*, relocated_address_o + addr_off) catch |err| switch (err) {
15471546 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 {
341341 const slot_index = @intCast(SlotIndex, used_bits_byte * 8 + bit_index);
342342 const stack_trace = bucketStackTrace(bucket, size_class, slot_index, .alloc);
343343 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) {
345345 log.err("memory address 0x{x} leaked: {s}", .{
346346 @ptrToInt(addr), stack_trace,
347347 });
......@@ -379,7 +379,7 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type {
379379 while (it.next()) |large_alloc| {
380380 if (config.retain_metadata and large_alloc.freed) continue;
381381 const stack_trace = large_alloc.getStackTrace(.alloc);
382 if (builtin.zig_backend == .stage1) {
382 if (builtin.zig_backend == .stage1 or builtin.os.tag == .linux) {
383383 log.err("memory address 0x{x} leaked: {s}", .{
384384 @ptrToInt(large_alloc.bytes.ptr), stack_trace,
385385 });
lib/std/os/linux.zig+36-13
......@@ -1080,12 +1080,19 @@ pub fn sigaction(sig: u6, noalias act: ?*const Sigaction, noalias oact: ?*Sigact
10801080 const mask_size = @sizeOf(@TypeOf(ksa.mask));
10811081
10821082 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;
10841091 ksa = k_sigaction{
10851092 .handler = new.handler.handler,
10861093 .flags = new.flags | SA.RESTORER,
10871094 .mask = undefined,
1088 .restorer = @ptrCast(fn () callconv(.C) void, restorer_fn),
1095 .restorer = @ptrCast(k_sigaction_funcs.restorer, restorer_fn),
10891096 };
10901097 @memcpy(@ptrCast([*]u8, &ksa.mask), @ptrCast([*]const u8, &new.mask), mask_size);
10911098 }
......@@ -3047,39 +3054,55 @@ pub const sigset_t = [1024 / 32]u32;
30473054pub const all_mask: sigset_t = [_]u32{0xffffffff} ** sigset_t.len;
30483055pub 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
30503065pub const k_sigaction = switch (native_arch) {
30513066 .mips, .mipsel => extern struct {
30523067 flags: c_uint,
3053 handler: ?fn (c_int) callconv(.C) void,
3068 handler: k_sigaction_funcs.handler,
30543069 mask: [4]c_ulong,
3055 restorer: fn () callconv(.C) void,
3070 restorer: k_sigaction_funcs.restorer,
30563071 },
30573072 .mips64, .mips64el => extern struct {
30583073 flags: c_uint,
3059 handler: ?fn (c_int) callconv(.C) void,
3074 handler: k_sigaction_funcs.handler,
30603075 mask: [2]c_ulong,
3061 restorer: fn () callconv(.C) void,
3076 restorer: k_sigaction_funcs.restorer,
30623077 },
30633078 else => extern struct {
3064 handler: ?fn (c_int) callconv(.C) void,
3079 handler: k_sigaction_funcs.handler,
30653080 flags: c_ulong,
3066 restorer: fn () callconv(.C) void,
3081 restorer: k_sigaction_funcs.restorer,
30673082 mask: [2]c_uint,
30683083 },
30693084};
30703085
30713086/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
30723087pub const Sigaction = extern struct {
3073 pub const handler_fn = fn (c_int) callconv(.C) void;
3074 pub const sigaction_fn = fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
3088 pub usingnamespace if (builtin.zig_backend == .stage1) struct {
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
30763096 handler: extern union {
3077 handler: ?handler_fn,
3078 sigaction: ?sigaction_fn,
3097 handler: ?Sigaction.handler_fn,
3098 sigaction: ?Sigaction.sigaction_fn,
30793099 },
30803100 mask: sigset_t,
30813101 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,
30833106};
30843107
30853108pub const empty_sigset = [_]u32{0} ** @typeInfo(sigset_t).Array.len;