- rebase and update to lastest master

This commit is contained in:
kcbanner 2023-06-23 11:54:06 -04:00
parent adbc5bbdb3
commit a47212c72e
3 changed files with 36 additions and 38 deletions

View File

@ -988,7 +988,7 @@ pub fn readElfDebugInfo(
if (mem.eql(u8, name, ".gnu_debuglink")) {
const gnu_debuglink = try chopSlice(mapped_mem, shdr.sh_offset, shdr.sh_size);
const debug_filename = mem.sliceTo(@ptrCast([*:0]const u8, gnu_debuglink.ptr), 0);
const crc_offset = mem.alignForward(@ptrToInt(&debug_filename[debug_filename.len]) + 1, 4) - @ptrToInt(gnu_debuglink.ptr);
const crc_offset = mem.alignForward(usize, @intFromPtr(&debug_filename[debug_filename.len]) + 1, 4) - @intFromPtr(gnu_debuglink.ptr);
const crc_bytes = gnu_debuglink[crc_offset .. crc_offset + 4];
separate_debug_crc = mem.readIntSliceNative(u32, crc_bytes);
separate_debug_filename = debug_filename;
@ -1007,11 +1007,9 @@ pub fn readElfDebugInfo(
var section_stream = io.fixedBufferStream(section_bytes);
var section_reader = section_stream.reader();
const chdr = section_reader.readStruct(elf.Chdr) catch continue;
// TODO: Support ZSTD
if (chdr.ch_type != .ZLIB) continue;
var zlib_stream = std.compress.zlib.zlibStream(allocator, section_stream.reader()) catch continue;
var zlib_stream = std.compress.zlib.decompressStream(allocator, section_stream.reader()) catch continue;
defer zlib_stream.deinit();
var decompressed_section = try allocator.alloc(u8, chdr.ch_size);
@ -1031,10 +1029,10 @@ pub fn readElfDebugInfo(
}
const missing_debug_info =
sections[@enumToInt(DW.DwarfSection.debug_info)] == null or
sections[@enumToInt(DW.DwarfSection.debug_abbrev)] == null or
sections[@enumToInt(DW.DwarfSection.debug_str)] == null or
sections[@enumToInt(DW.DwarfSection.debug_line)] == null;
sections[@intFromEnum(DW.DwarfSection.debug_info)] == null or
sections[@intFromEnum(DW.DwarfSection.debug_abbrev)] == null or
sections[@intFromEnum(DW.DwarfSection.debug_str)] == null or
sections[@intFromEnum(DW.DwarfSection.debug_line)] == null;
// Attempt to load debug info from an external file
// See: https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html
@ -1537,7 +1535,7 @@ pub const DebugInfo = struct {
switch (phdr.p_type) {
elf.PT_NOTE => {
// Look for .note.gnu.build-id
const note_bytes = @intToPtr([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
const note_bytes = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
const name_size = mem.readIntSliceNative(u32, note_bytes[0..4]);
if (name_size != 4) continue;
const desc_size = mem.readIntSliceNative(u32, note_bytes[4..8]);
@ -1547,7 +1545,7 @@ pub const DebugInfo = struct {
context.build_id = note_bytes[16..][0..desc_size];
},
elf.PT_GNU_EH_FRAME => {
context.gnu_eh_frame = @intToPtr([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
context.gnu_eh_frame = @ptrFromInt([*]const u8, info.dlpi_addr + phdr.p_vaddr)[0..phdr.p_memsz];
},
else => {},
}
@ -1575,7 +1573,7 @@ pub const DebugInfo = struct {
// are encoded relative to its base address, so we must use the
// version that is already memory mapped, and not the one that
// will be mapped separately from the ELF file.
sections[@enumToInt(DW.DwarfSection.eh_frame_hdr)] = .{
sections[@intFromEnum(DW.DwarfSection.eh_frame_hdr)] = .{
.data = eh_frame_hdr,
.owned = false,
};
@ -1689,10 +1687,10 @@ pub const ModuleDebugInfo = switch (native_os) {
}
const missing_debug_info =
sections[@enumToInt(DW.DwarfSection.debug_info)] == null or
sections[@enumToInt(DW.DwarfSection.debug_abbrev)] == null or
sections[@enumToInt(DW.DwarfSection.debug_str)] == null or
sections[@enumToInt(DW.DwarfSection.debug_line)] == null;
sections[@intFromEnum(DW.DwarfSection.debug_info)] == null or
sections[@intFromEnum(DW.DwarfSection.debug_abbrev)] == null or
sections[@intFromEnum(DW.DwarfSection.debug_str)] == null or
sections[@intFromEnum(DW.DwarfSection.debug_line)] == null;
if (missing_debug_info) return error.MissingDebugInfo;
var di = DW.DwarfInfo{

View File

@ -691,7 +691,7 @@ pub const DwarfInfo = struct {
is_macho: bool,
pub fn section(di: DwarfInfo, dwarf_section: DwarfSection) ?[]const u8 {
return if (di.sections[@enumToInt(dwarf_section)]) |s| s.data else null;
return if (di.sections[@intFromEnum(dwarf_section)]) |s| s.data else null;
}
pub fn deinit(di: *DwarfInfo, allocator: mem.Allocator) void {
@ -1506,12 +1506,12 @@ pub const DwarfInfo = struct {
if (table_enc == EH.PE.omit) break :blk;
const eh_frame_ptr = std.math.cast(usize, try readEhPointer(reader, eh_frame_ptr_enc, @sizeOf(usize), .{
.pc_rel_base = @ptrToInt(&eh_frame_hdr[stream.pos]),
.pc_rel_base = @intFromPtr(&eh_frame_hdr[stream.pos]),
.follow_indirect = true,
}, builtin.cpu.arch.endian()) orelse return badDwarf()) orelse return badDwarf();
const fde_count = std.math.cast(usize, try readEhPointer(reader, fde_count_enc, @sizeOf(usize), .{
.pc_rel_base = @ptrToInt(&eh_frame_hdr[stream.pos]),
.pc_rel_base = @intFromPtr(&eh_frame_hdr[stream.pos]),
.follow_indirect = true,
}, builtin.cpu.arch.endian()) orelse return badDwarf()) orelse return badDwarf();
@ -1538,7 +1538,7 @@ pub const DwarfInfo = struct {
.cie => {
const cie = try CommonInformationEntry.parse(
entry_header.entry_bytes,
-@intCast(isize, @ptrToInt(binary_mem.ptr)),
-@intCast(isize, @intFromPtr(binary_mem.ptr)),
//@ptrToInt(eh_frame.ptr),
//@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr),
true,
@ -1552,7 +1552,7 @@ pub const DwarfInfo = struct {
const cie = di.cie_map.get(cie_offset) orelse return badDwarf();
const fde = try FrameDescriptionEntry.parse(
entry_header.entry_bytes,
-@intCast(isize, @ptrToInt(binary_mem.ptr)),
-@intCast(isize, @intFromPtr(binary_mem.ptr)),
//@ptrToInt(eh_frame.ptr),
//@ptrToInt(eh_frame.ptr) - @ptrToInt(binary_mem.ptr),
true,
@ -1594,7 +1594,7 @@ pub const DwarfInfo = struct {
if (di.eh_frame_hdr) |header| {
mapped_pc = context.pc;
try header.findEntry(context.isValidMemory, @ptrToInt(di.section(.eh_frame_hdr).?.ptr), mapped_pc, &cie, &fde);
try header.findEntry(context.isValidMemory, @intFromPtr(di.section(.eh_frame_hdr).?.ptr), mapped_pc, &cie, &fde);
} else {
mapped_pc = context.pc - module_base_address;
const index = std.sort.binarySearch(FrameDescriptionEntry, mapped_pc, di.fde_list.items, {}, struct {
@ -1790,7 +1790,7 @@ fn readEhPointer(reader: anytype, enc: u8, addr_size_bytes: u8, ctx: EhPointerCo
const native_ptr = math.cast(usize, ptr) orelse return error.PointerOverflow;
return switch (addr_size_bytes) {
2, 4, 8 => return @intToPtr(*const usize, native_ptr).*,
2, 4, 8 => return @ptrFromInt(*const usize, native_ptr).*,
else => return error.UnsupportedAddrSize,
};
} else {
@ -1842,7 +1842,7 @@ pub const ExceptionFrameHeader = struct {
try stream.seekTo(mid * entry_size);
const pc_begin = try readEhPointer(reader, self.table_enc, @sizeOf(usize), .{
.pc_rel_base = @ptrToInt(&self.entries[stream.pos]),
.pc_rel_base = @intFromPtr(&self.entries[stream.pos]),
.follow_indirect = true,
.data_rel_base = eh_frame_hdr_ptr,
}, builtin.cpu.arch.endian()) orelse return badDwarf();
@ -1857,13 +1857,13 @@ pub const ExceptionFrameHeader = struct {
// Read past pc_begin
_ = try readEhPointer(reader, self.table_enc, @sizeOf(usize), .{
.pc_rel_base = @ptrToInt(&self.entries[stream.pos]),
.pc_rel_base = @intFromPtr(&self.entries[stream.pos]),
.follow_indirect = true,
.data_rel_base = eh_frame_hdr_ptr,
}, builtin.cpu.arch.endian()) orelse return badDwarf();
const fde_ptr = math.cast(usize, try readEhPointer(reader, self.table_enc, @sizeOf(usize), .{
.pc_rel_base = @ptrToInt(&self.entries[stream.pos]),
.pc_rel_base = @intFromPtr(&self.entries[stream.pos]),
.follow_indirect = true,
.data_rel_base = eh_frame_hdr_ptr,
}, builtin.cpu.arch.endian()) orelse return badDwarf()) orelse return badDwarf();
@ -1872,20 +1872,20 @@ pub const ExceptionFrameHeader = struct {
// The length of the .eh_frame section is unknown at this point, since .eh_frame_hdr only provides the start
if (!isValidMemory(fde_ptr) or fde_ptr < self.eh_frame_ptr) return badDwarf();
const eh_frame = @intToPtr([*]const u8, self.eh_frame_ptr)[0..math.maxInt(usize)];
const eh_frame = @ptrFromInt([*]const u8, self.eh_frame_ptr)[0..math.maxInt(usize)];
const fde_offset = fde_ptr - self.eh_frame_ptr;
var eh_frame_stream = io.fixedBufferStream(eh_frame);
try eh_frame_stream.seekTo(fde_offset);
const fde_entry_header = try EntryHeader.read(&eh_frame_stream, builtin.cpu.arch.endian());
if (!isValidMemory(@ptrToInt(&fde_entry_header.entry_bytes[fde_entry_header.entry_bytes.len - 1]))) return badDwarf();
if (!isValidMemory(@intFromPtr(&fde_entry_header.entry_bytes[fde_entry_header.entry_bytes.len - 1]))) return badDwarf();
if (fde_entry_header.type != .fde) return badDwarf();
const cie_offset = fde_entry_header.type.fde;
try eh_frame_stream.seekTo(cie_offset);
const cie_entry_header = try EntryHeader.read(&eh_frame_stream, builtin.cpu.arch.endian());
if (!isValidMemory(@ptrToInt(&cie_entry_header.entry_bytes[cie_entry_header.entry_bytes.len - 1]))) return badDwarf();
if (!isValidMemory(@intFromPtr(&cie_entry_header.entry_bytes[cie_entry_header.entry_bytes.len - 1]))) return badDwarf();
if (cie_entry_header.type != .cie) return badDwarf();
cie.* = try CommonInformationEntry.parse(
@ -2083,7 +2083,7 @@ pub const CommonInformationEntry = struct {
personality_enc.?,
addr_size_bytes,
.{
.pc_rel_base = try pcRelBase(@ptrToInt(&cie_bytes[stream.pos]), pc_rel_offset),
.pc_rel_base = try pcRelBase(@intFromPtr(&cie_bytes[stream.pos]), pc_rel_offset),
.follow_indirect = is_runtime,
},
endian,
@ -2161,7 +2161,7 @@ pub const FrameDescriptionEntry = struct {
cie.fde_pointer_enc,
addr_size_bytes,
.{
.pc_rel_base = try pcRelBase(@ptrToInt(&fde_bytes[stream.pos]), pc_rel_offset),
.pc_rel_base = try pcRelBase(@intFromPtr(&fde_bytes[stream.pos]), pc_rel_offset),
.follow_indirect = is_runtime,
},
endian,
@ -2190,7 +2190,7 @@ pub const FrameDescriptionEntry = struct {
cie.lsda_pointer_enc,
addr_size_bytes,
.{
.pc_rel_base = try pcRelBase(@ptrToInt(&fde_bytes[stream.pos]), pc_rel_offset),
.pc_rel_base = try pcRelBase(@intFromPtr(&fde_bytes[stream.pos]), pc_rel_offset),
.follow_indirect = is_runtime,
},
endian,

View File

@ -38,12 +38,12 @@ const Opcode = enum(u8) {
val_expression = 0x16,
// These opcodes encode an operand in the lower 6 bits of the opcode itself
pub const lo_inline = @enumToInt(Opcode.advance_loc);
pub const hi_inline = @enumToInt(Opcode.restore) | 0b111111;
pub const lo_inline = @intFromEnum(Opcode.advance_loc);
pub const hi_inline = @intFromEnum(Opcode.restore) | 0b111111;
// These opcodes are trailed by zero or more operands
pub const lo_reserved = @enumToInt(Opcode.nop);
pub const hi_reserved = @enumToInt(Opcode.val_expression);
pub const lo_reserved = @intFromEnum(Opcode.nop);
pub const hi_reserved = @intFromEnum(Opcode.val_expression);
// Vendor-specific opcodes
pub const lo_user = 0x1c;
@ -206,13 +206,13 @@ pub const Instruction = union(Opcode) {
) !Instruction {
return switch (try stream.reader().readByte()) {
inline Opcode.lo_inline...Opcode.hi_inline => |opcode| blk: {
const e = @intToEnum(Opcode, opcode & 0b11000000);
const e = @enumFromInt(Opcode, opcode & 0b11000000);
var result = @unionInit(Instruction, @tagName(e), undefined);
try result.readOperands(stream, @intCast(u6, opcode & 0b111111), addr_size_bytes, endian);
break :blk result;
},
inline Opcode.lo_reserved...Opcode.hi_reserved => |opcode| blk: {
const e = @intToEnum(Opcode, opcode);
const e = @enumFromInt(Opcode, opcode);
var result = @unionInit(Instruction, @tagName(e), undefined);
try result.readOperands(stream, null, addr_size_bytes, endian);
break :blk result;
@ -304,7 +304,7 @@ pub const VirtualMachine = struct {
.same_value => {},
.offset => |offset| {
if (context.cfa) |cfa| {
const ptr = @intToPtr(*const usize, try applyOffset(cfa, offset));
const ptr = @ptrFromInt(*const usize, try applyOffset(cfa, offset));
// TODO: context.isValidMemory(ptr)
mem.writeIntSliceNative(usize, out, ptr.*);