Skip to content

Commit b300eec

Browse files
joachimschmidt557andrewrk
authored andcommitted
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.
1 parent bd21f49 commit b300eec

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/link/Dwarf.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,13 @@ pub const DeclState = struct {
243243
.Pointer => {
244244
if (ty.isSlice()) {
245245
// Slices are structs: struct { .ptr = *, .len = N }
246+
const ptr_bits = target.cpu.arch.ptrBitWidth();
247+
const ptr_bytes = @intCast(u8, @divExact(ptr_bits, 8));
246248
// DW.AT.structure_type
247249
try dbg_info_buffer.ensureUnusedCapacity(2);
248250
dbg_info_buffer.appendAssumeCapacity(@enumToInt(AbbrevKind.struct_type));
249251
// DW.AT.byte_size, DW.FORM.sdata
250-
dbg_info_buffer.appendAssumeCapacity(@sizeOf(usize) * 2);
252+
dbg_info_buffer.appendAssumeCapacity(ptr_bytes * 2);
251253
// DW.AT.name, DW.FORM.string
252254
try dbg_info_buffer.writer().print("{}\x00", .{ty.fmt(module)});
253255
// DW.AT.member
@@ -276,7 +278,7 @@ pub const DeclState = struct {
276278
try self.addTypeRelocGlobal(atom, Type.usize, @intCast(u32, index));
277279
// DW.AT.data_member_location, DW.FORM.sdata
278280
try dbg_info_buffer.ensureUnusedCapacity(2);
279-
dbg_info_buffer.appendAssumeCapacity(@sizeOf(usize));
281+
dbg_info_buffer.appendAssumeCapacity(ptr_bytes);
280282
// DW.AT.structure_type delimit children
281283
dbg_info_buffer.appendAssumeCapacity(0);
282284
} else {

0 commit comments

Comments
 (0)