zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit b300eecb9da8f9ea0baffe737eb595df3c12381f (tree)
parent bd21f499dcd1b50a6ac39644303a9647d16adb0f
Author: joachimschmidt557 <joachim.schmidt557@outlook.com>
Date:   Sat,  6 Aug 2022 19:43:04 +0200

stage2 DWARF: fix size and offset in slices

Previously, `@sizeOf(usize)` was used, however, the pointer size of
the host may differ from the target when cross-compiling.

Diffstat:
Msrc/link/Dwarf.zig | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig @@ -243,11 +243,13 @@ pub const DeclState = struct { .Pointer => { if (ty.isSlice()) { // Slices are structs: struct { .ptr = *, .len = N } + const ptr_bits = target.cpu.arch.ptrBitWidth(); + const ptr_bytes = @intCast(u8, @divExact(ptr_bits, 8)); // DW.AT.structure_type try dbg_info_buffer.ensureUnusedCapacity(2); dbg_info_buffer.appendAssumeCapacity(@enumToInt(AbbrevKind.struct_type)); // DW.AT.byte_size, DW.FORM.sdata - dbg_info_buffer.appendAssumeCapacity(@sizeOf(usize) * 2); + dbg_info_buffer.appendAssumeCapacity(ptr_bytes * 2); // DW.AT.name, DW.FORM.string try dbg_info_buffer.writer().print("{}\x00", .{ty.fmt(module)}); // DW.AT.member @@ -276,7 +278,7 @@ pub const DeclState = struct { try self.addTypeRelocGlobal(atom, Type.usize, @intCast(u32, index)); // DW.AT.data_member_location, DW.FORM.sdata try dbg_info_buffer.ensureUnusedCapacity(2); - dbg_info_buffer.appendAssumeCapacity(@sizeOf(usize)); + dbg_info_buffer.appendAssumeCapacity(ptr_bytes); // DW.AT.structure_type delimit children dbg_info_buffer.appendAssumeCapacity(0); } else {