authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-10-18 10:40:05+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-02 22:05:21-05:00
log29c7f6810fe00cf69adf81d635d3410402b530e8
tree6b0b98cf032a6177ec2a8189f5138390d41b9481
parentf78006c1bfa9b32ff5ccda39c2535c97f50eddc5

macho: fix 32bit builds


1 files changed, 15 insertions(+), 4 deletions(-)

src/link/MachO/Dwarf.zig+15-4
...@@ -14,10 +14,18 @@ pub fn deinit(dwarf: *Dwarf, allocator: Allocator) void {...@@ -14,10 +14,18 @@ pub fn deinit(dwarf: *Dwarf, allocator: Allocator) void {
14/// This is new in DWARFv5 and requires the producer to specify DW_FORM_strx* (`index` arg)14/// This is new in DWARFv5 and requires the producer to specify DW_FORM_strx* (`index` arg)
15/// but also DW_AT_str_offsets_base with DW_FORM_sec_offset (`base` arg) in the opening header15/// but also DW_AT_str_offsets_base with DW_FORM_sec_offset (`base` arg) in the opening header
16/// of a "referencing entity" such as DW_TAG_compile_unit.16/// of a "referencing entity" such as DW_TAG_compile_unit.
17fn getOffset(debug_str_offsets: []const u8, base: u64, index: u64, dw_fmt: DwarfFormat) u64 {17fn getOffset(debug_str_offsets: []const u8, base: u64, index: u64, dw_fmt: DwarfFormat) error{Overflow}!u64 {
18 const base_as_usize = math.cast(usize, base) orelse return error.Overflow;
19 const index_as_usize = math.cast(usize, index) orelse return error.Overflow;
18 return switch (dw_fmt) {20 return switch (dw_fmt) {
19 .dwarf32 => @as(*align(1) const u32, @ptrCast(debug_str_offsets.ptr + base + index * @sizeOf(u32))).*,21 .dwarf32 => @as(
20 .dwarf64 => @as(*align(1) const u64, @ptrCast(debug_str_offsets.ptr + base + index * @sizeOf(u64))).*,22 *align(1) const u32,
23 @ptrCast(debug_str_offsets.ptr + base_as_usize + index_as_usize * @sizeOf(u32)),
24 ).*,
25 .dwarf64 => @as(
26 *align(1) const u64,
27 @ptrCast(debug_str_offsets.ptr + base_as_usize + index_as_usize * @sizeOf(u64)),
28 ).*,
21 };29 };
22}30}
2331
...@@ -228,7 +236,10 @@ pub const InfoReader = struct {...@@ -228,7 +236,10 @@ pub const InfoReader = struct {
228 dw.FORM.strx4,236 dw.FORM.strx4,
229 => {237 => {
230 const index = try p.readIndex(form);238 const index = try p.readIndex(form);
231 const off = getOffset(p.ctx.debug_str_offsets, base, index, cuh.format);239 const off = math.cast(
240 usize,
241 try getOffset(p.ctx.debug_str_offsets, base, index, cuh.format),
242 ) orelse return error.Overflow;
232 return mem.sliceTo(@as([*:0]const u8, @ptrCast(p.ctx.debug_str.ptr + off)), 0);243 return mem.sliceTo(@as([*:0]const u8, @ptrCast(p.ctx.debug_str.ptr + off)), 0);
233 },244 },
234 else => unreachable,245 else => unreachable,