authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-06-25 02:47:48-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-07-20 22:58:14-04:00
log6abf1fbfe6f7f3c06e70e331a3c9e5101624d501
tree6f2b2b0adfe08900a864b6888590c5f17043a483
parent84a1244b6c8d8b093d514cf267c832ad24d4400f

update to new builtin syntax


5 files changed, 26 insertions(+), 30 deletions(-)

lib/std/debug.zig+4-4
...@@ -987,7 +987,7 @@ pub fn readElfDebugInfo(...@@ -987,7 +987,7 @@ pub fn readElfDebugInfo(
987987
988 if (mem.eql(u8, name, ".gnu_debuglink")) {988 if (mem.eql(u8, name, ".gnu_debuglink")) {
989 const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);989 const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
990 const debug_filename = mem.sliceTo(@ptrCast([*:0]const u8, gnu_debuglink.ptr), 0);990 const debug_filename = mem.sliceTo(@as([*:0]const u8, @ptrCast(gnu_debuglink.ptr)), 0);
991 const crc_offset = mem.alignForward(usize, @intFromPtr(&debug_filename[debug_filename.len]) + 1, 4) - @intFromPtr(gnu_debuglink.ptr);991 const crc_offset = mem.alignForward(usize, @intFromPtr(&debug_filename[debug_filename.len]) + 1, 4) - @intFromPtr(gnu_debuglink.ptr);
992 const crc_bytes = gnu_debuglink[crc_offset .. crc_offset + 4];992 const crc_bytes = gnu_debuglink[crc_offset .. crc_offset + 4];
993 separate_debug_crc = mem.readIntSliceNative(u32, crc_bytes);993 separate_debug_crc = mem.readIntSliceNative(u32, crc_bytes);
...@@ -1535,7 +1535,7 @@ pub const DebugInfo = struct {...@@ -1535,7 +1535,7 @@ pub const DebugInfo = struct {
1535 switch (phdr.p_type) {1535 switch (phdr.p_type) {
1536 elf.PT_NOTE => {1536 elf.PT_NOTE => {
1537 // Look for .note.gnu.build-id1537 // Look for .note.gnu.build-id
1538 const note_bytes = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];1538 const note_bytes = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz];
1539 const name_size = mem.readIntSliceNative(u32, note_bytes[0..4]);1539 const name_size = mem.readIntSliceNative(u32, note_bytes[0..4]);
1540 if (name_size != 4) continue;1540 if (name_size != 4) continue;
1541 const desc_size = mem.readIntSliceNative(u32, note_bytes[4..8]);1541 const desc_size = mem.readIntSliceNative(u32, note_bytes[4..8]);
...@@ -1545,7 +1545,7 @@ pub const DebugInfo = struct {...@@ -1545,7 +1545,7 @@ pub const DebugInfo = struct {
1545 context.build_id = note_bytes[16..][0..desc_size];1545 context.build_id = note_bytes[16..][0..desc_size];
1546 },1546 },
1547 elf.PT_GNU_EH_FRAME => {1547 elf.PT_GNU_EH_FRAME => {
1548 context.gnu_eh_frame = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];1548 context.gnu_eh_frame = @as([*]const u8, @ptrFromInt(info.dlpi_addr + phdr.p_vaddr))[0..phdr.p_memsz];
1549 },1549 },
1550 else => {},1550 else => {},
1551 }1551 }
...@@ -2094,7 +2094,7 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void...@@ -2094,7 +2094,7 @@ fn dumpSegfaultInfoPosix(sig: i32, addr: usize, ctx_ptr: ?*const anyopaque) void
2094 .arm,2094 .arm,
2095 .aarch64,2095 .aarch64,
2096 => {2096 => {
2097 const ctx = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr));2097 const ctx: *const os.ucontext_t = @ptrCast(@alignCast(ctx_ptr));
2098 dumpStackTraceFromBase(ctx);2098 dumpStackTraceFromBase(ctx);
2099 },2099 },
2100 else => {},2100 else => {},
lib/std/dwarf.zig+8-12
...@@ -1538,9 +1538,7 @@ pub const DwarfInfo = struct {...@@ -1538,9 +1538,7 @@ pub const DwarfInfo = struct {
1538 .cie => {1538 .cie => {
1539 const cie = try CommonInformationEntry.parse(1539 const cie = try CommonInformationEntry.parse(
1540 entry_header.entry_bytes,1540 entry_header.entry_bytes,
1541 -@intCast(isize, @intFromPtr(binary_mem.ptr)),1541 -@as(i64, @intCast(@intFromPtr(binary_mem.ptr))),
1542 //@ptrToInt(eh_frame.ptr),
1543 //@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr),
1544 true,1542 true,
1545 entry_header.length_offset,1543 entry_header.length_offset,
1546 @sizeOf(usize),1544 @sizeOf(usize),
...@@ -1552,9 +1550,7 @@ pub const DwarfInfo = struct {...@@ -1552,9 +1550,7 @@ pub const DwarfInfo = struct {
1552 const cie = di.cie_map.get(cie_offset) orelse return badDwarf();1550 const cie = di.cie_map.get(cie_offset) orelse return badDwarf();
1553 const fde = try FrameDescriptionEntry.parse(1551 const fde = try FrameDescriptionEntry.parse(
1554 entry_header.entry_bytes,1552 entry_header.entry_bytes,
1555 -@intCast(isize, @intFromPtr(binary_mem.ptr)),1553 -@as(i64, @intCast(@intFromPtr(binary_mem.ptr))),
1556 //@ptrToInt(eh_frame.ptr),
1557 //@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr),
1558 true,1554 true,
1559 cie,1555 cie,
1560 @sizeOf(usize),1556 @sizeOf(usize),
...@@ -1783,10 +1779,10 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo...@@ -1783,10 +1779,10 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
1783 };1779 };
17841780
1785 const ptr = if (base) |b| switch (value) {1781 const ptr = if (base) |b| switch (value) {
1786 .signed => |s| @intCast(u64, s + @intCast(i64, b)),1782 .signed => |s| @as(u64, @intCast(s + @as(i64, @intCast(b)))),
1787 .unsigned => |u| u + b,1783 .unsigned => |u| u + b,
1788 } else switch (value) {1784 } else switch (value) {
1789 .signed => |s| @intCast(u64, s),1785 .signed => |s| @as(u64, @intCast(s)),
1790 .unsigned => |u| u,1786 .unsigned => |u| u,
1791 };1787 };
17921788
...@@ -1798,7 +1794,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo...@@ -1798,7 +1794,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
17981794
1799 const native_ptr = math.cast(usize, ptr) orelse return error.PointerOverflow;1795 const native_ptr = math.cast(usize, ptr) orelse return error.PointerOverflow;
1800 return switch (addr_size_bytes) {1796 return switch (addr_size_bytes) {
1801 2, 4, 8 => return @ptrFromInt(*const usize, native_ptr).*,1797 2, 4, 8 => return @as(*const usize, @ptrFromInt(native_ptr)).*,
1802 else => return error.UnsupportedAddrSize,1798 else => return error.UnsupportedAddrSize,
1803 };1799 };
1804 } else {1800 } else {
...@@ -1903,7 +1899,7 @@ pub const ExceptionFrameHeader = struct {...@@ -1903,7 +1899,7 @@ pub const ExceptionFrameHeader = struct {
1903 if (self.isValidPtr(fde_ptr + 11, isValidMemory, eh_frame_len)) fde_entry_header_len = 12;1899 if (self.isValidPtr(fde_ptr + 11, isValidMemory, eh_frame_len)) fde_entry_header_len = 12;
19041900
1905 // Even if eh_frame_len is not specified, all ranges accssed are checked by isValidPtr1901 // Even if eh_frame_len is not specified, all ranges accssed are checked by isValidPtr
1906 const eh_frame = @ptrFromInt([*]const u8, self.eh_frame_ptr)[0..eh_frame_len orelse math.maxInt(u32)];1902 const eh_frame = @as([*]const u8, @ptrFromInt(self.eh_frame_ptr))[0 .. eh_frame_len orelse math.maxInt(u32)];
19071903
1908 const fde_offset = fde_ptr - self.eh_frame_ptr;1904 const fde_offset = fde_ptr - self.eh_frame_ptr;
1909 var eh_frame_stream = io.fixedBufferStream(eh_frame);1905 var eh_frame_stream = io.fixedBufferStream(eh_frame);
...@@ -2248,8 +2244,8 @@ pub const FrameDescriptionEntry = struct {...@@ -2248,8 +2244,8 @@ pub const FrameDescriptionEntry = struct {
22482244
2249fn pcRelBase(field_ptr: usize, pc_rel_offset: i64) !usize {2245fn pcRelBase(field_ptr: usize, pc_rel_offset: i64) !usize {
2250 if (pc_rel_offset < 0) {2246 if (pc_rel_offset < 0) {
2251 return math.sub(usize, field_ptr, @intCast(usize, -pc_rel_offset));2247 return math.sub(usize, field_ptr, @as(usize, @intCast(-pc_rel_offset)));
2252 } else {2248 } else {
2253 return math.add(usize, field_ptr, @intCast(usize, pc_rel_offset));2249 return math.add(usize, field_ptr, @as(usize, @intCast(pc_rel_offset)));
2254 }2250 }
2255}2251}
lib/std/dwarf/call_frame.zig+9-9
...@@ -206,13 +206,13 @@ pub const Instruction = union(Opcode) {...@@ -206,13 +206,13 @@ pub const Instruction = union(Opcode) {
206 ) !Instruction {206 ) !Instruction {
207 return switch (try stream.reader().readByte()) {207 return switch (try stream.reader().readByte()) {
208 inline Opcode.lo_inline...Opcode.hi_inline => |opcode| blk: {208 inline Opcode.lo_inline...Opcode.hi_inline => |opcode| blk: {
209 const e = @enumFromInt(Opcode, opcode & 0b11000000);209 const e: Opcode = @enumFromInt(opcode & 0b11000000);
210 var result = @unionInit(Instruction, @tagName(e), undefined);210 var result = @unionInit(Instruction, @tagName(e), undefined);
211 try result.readOperands(stream, @intCast(u6, opcode & 0b111111), addr_size_bytes, endian);211 try result.readOperands(stream, @as(u6, @intCast(opcode & 0b111111)), addr_size_bytes, endian);
212 break :blk result;212 break :blk result;
213 },213 },
214 inline Opcode.lo_reserved...Opcode.hi_reserved => |opcode| blk: {214 inline Opcode.lo_reserved...Opcode.hi_reserved => |opcode| blk: {
215 const e = @enumFromInt(Opcode, opcode);215 const e: Opcode = @enumFromInt(opcode);
216 var result = @unionInit(Instruction, @tagName(e), undefined);216 var result = @unionInit(Instruction, @tagName(e), undefined);
217 try result.readOperands(stream, null, addr_size_bytes, endian);217 try result.readOperands(stream, null, addr_size_bytes, endian);
218 break :blk result;218 break :blk result;
...@@ -234,9 +234,9 @@ pub const Instruction = union(Opcode) {...@@ -234,9 +234,9 @@ pub const Instruction = union(Opcode) {
234/// an error and fall back to FP-based unwinding.234/// an error and fall back to FP-based unwinding.
235pub fn applyOffset(base: usize, offset: i64) !usize {235pub fn applyOffset(base: usize, offset: i64) !usize {
236 return if (offset >= 0)236 return if (offset >= 0)
237 try std.math.add(usize, base, @intCast(usize, offset))237 try std.math.add(usize, base, @as(usize, @intCast(offset)))
238 else238 else
239 try std.math.sub(usize, base, @intCast(usize, -offset));239 try std.math.sub(usize, base, @as(usize, @intCast(-offset)));
240}240}
241241
242/// This is a virtual machine that runs DWARF call frame instructions.242/// This is a virtual machine that runs DWARF call frame instructions.
...@@ -304,7 +304,7 @@ pub const VirtualMachine = struct {...@@ -304,7 +304,7 @@ pub const VirtualMachine = struct {
304 .same_value => {},304 .same_value => {},
305 .offset => |offset| {305 .offset => |offset| {
306 if (context.cfa) |cfa| {306 if (context.cfa) |cfa| {
307 const ptr = @ptrFromInt(*const usize, try applyOffset(cfa, offset));307 const ptr: *const usize = @ptrFromInt(try applyOffset(cfa, offset));
308308
309 // TODO: context.isValidMemory(ptr)309 // TODO: context.isValidMemory(ptr)
310 mem.writeIntSliceNative(usize, out, ptr.*);310 mem.writeIntSliceNative(usize, out, ptr.*);
...@@ -480,7 +480,7 @@ pub const VirtualMachine = struct {...@@ -480,7 +480,7 @@ pub const VirtualMachine = struct {
480 => |i| {480 => |i| {
481 try self.resolveCopyOnWrite(allocator);481 try self.resolveCopyOnWrite(allocator);
482 const column = try self.getOrAddColumn(allocator, i.operands.register);482 const column = try self.getOrAddColumn(allocator, i.operands.register);
483 column.rule = .{ .offset = @intCast(i64, i.operands.offset) * cie.data_alignment_factor };483 column.rule = .{ .offset = @as(i64, @intCast(i.operands.offset)) * cie.data_alignment_factor };
484 },484 },
485 inline .restore,485 inline .restore,
486 .restore_extended,486 .restore_extended,
...@@ -526,7 +526,7 @@ pub const VirtualMachine = struct {...@@ -526,7 +526,7 @@ pub const VirtualMachine = struct {
526 try self.resolveCopyOnWrite(allocator);526 try self.resolveCopyOnWrite(allocator);
527 self.current_row.cfa = .{527 self.current_row.cfa = .{
528 .register = i.operands.register,528 .register = i.operands.register,
529 .rule = .{ .val_offset = @intCast(i64, i.operands.offset) },529 .rule = .{ .val_offset = @intCast(i.operands.offset) },
530 };530 };
531 },531 },
532 .def_cfa_sf => |i| {532 .def_cfa_sf => |i| {
...@@ -544,7 +544,7 @@ pub const VirtualMachine = struct {...@@ -544,7 +544,7 @@ pub const VirtualMachine = struct {
544 .def_cfa_offset => |i| {544 .def_cfa_offset => |i| {
545 try self.resolveCopyOnWrite(allocator);545 try self.resolveCopyOnWrite(allocator);
546 if (self.current_row.cfa.register == null or self.current_row.cfa.rule != .val_offset) return error.InvalidOperation;546 if (self.current_row.cfa.register == null or self.current_row.cfa.rule != .val_offset) return error.InvalidOperation;
547 self.current_row.cfa.rule = .{ .val_offset = @intCast(i64, i.operands.offset) };547 self.current_row.cfa.rule = .{ .val_offset = @intCast(i.operands.offset) };
548 },548 },
549 .def_cfa_offset_sf => |i| {549 .def_cfa_offset_sf => |i| {
550 try self.resolveCopyOnWrite(allocator);550 try self.resolveCopyOnWrite(allocator);
lib/std/dwarf/expressions.zig+4-4
...@@ -62,13 +62,13 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {...@@ -62,13 +62,13 @@ pub fn StackMachine(comptime options: StackMachineOptions) type {
62 const int_info = @typeInfo(@TypeOf(value)).Int;62 const int_info = @typeInfo(@TypeOf(value)).Int;
63 if (@sizeOf(@TypeOf(value)) > options.addr_size) {63 if (@sizeOf(@TypeOf(value)) > options.addr_size) {
64 return .{ .generic = switch (int_info.signedness) {64 return .{ .generic = switch (int_info.signedness) {
65 .signed => @bitCast(addr_type, @truncate(addr_type_signed, value)),65 .signed => @bitCast(@as(addr_type_signed, @truncate(value))),
66 .unsigned => @truncate(addr_type, value),66 .unsigned => @truncate(value),
67 } };67 } };
68 } else {68 } else {
69 return .{ .generic = switch (int_info.signedness) {69 return .{ .generic = switch (int_info.signedness) {
70 .signed => @bitCast(addr_type, @intCast(addr_type_signed, value)),70 .signed => @bitCast(@as(addr_type_signed, @intCast(value))),
71 .unsigned => @intCast(addr_type, value),71 .unsigned => @intCast(value),
72 } };72 } };
73 }73 }
74 }74 }
src/crash_report.zig+1-1
...@@ -207,7 +207,7 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any...@@ -207,7 +207,7 @@ fn handleSegfaultPosix(sig: i32, info: *const os.siginfo_t, ctx_ptr: ?*const any
207 .x86_64,207 .x86_64,
208 .arm,208 .arm,
209 .aarch64,209 .aarch64,
210 => StackContext{ .exception = @ptrCast(*const os.ucontext_t, @alignCast(@alignOf(os.ucontext_t), ctx_ptr)) },210 => StackContext{ .exception = @ptrCast(@alignCast(ctx_ptr)) },
211 else => .not_supported,211 else => .not_supported,
212 };212 };
213213