diff options
| author | joachimschmidt557 <joachim.schmidt557@outlook.com> | 2022-08-06 19:43:04 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-08-06 14:44:05 -0700 |
| commit | b300eecb9da8f9ea0baffe737eb595df3c12381f (patch) | |
| tree | 1426afec8981cb47ff79683e7018e977c1bdc896 /src/link | |
| parent | bd21f499dcd1b50a6ac39644303a9647d16adb0f (diff) | |
| download | zig-b300eecb9da8f9ea0baffe737eb595df3c12381f.tar.gz zig-b300eecb9da8f9ea0baffe737eb595df3c12381f.zip | |
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 (limited to 'src/link')
| -rw-r--r-- | src/link/Dwarf.zig | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/link/Dwarf.zig b/src/link/Dwarf.zig index 627f946e36..2cd00f5a87 100644 --- 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 { |
