authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-02-11 12:16:32+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-02-11 12:16:32+01:00
log066758b1a296aa6f01d505f7b90d5aee2f387d30
tree50c15027ca05182f8f47e55d2891d9b9d318db66
parentb9b1ab024063105a9adfe3828692867c91015dc6

macho: correctly lower slices incl reloc and rebase tracking

Match changes required to `Elf` linker, which enable lowering of const slices on `MachO` targets. Expand `Mir` instructions requiring the knowledge of the containing atom - pass the symbol index into the linker's table from codegen via mir to emitter, to then utilise it in the linker.

9 files changed, 130 insertions(+), 61 deletions(-)

src/arch/aarch64/CodeGen.zig+15-1
......@@ -1617,7 +1617,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
16171617
16181618 _ = try self.addInst(.{
16191619 .tag = .call_extern,
1620 .data = .{ .extern_fn = n_strx },
1620 .data = .{
1621 .extern_fn = .{
1622 .atom_index = self.mod_fn.owner_decl.link.macho.local_sym_index,
1623 .sym_name = n_strx,
1624 },
1625 },
16211626 });
16221627 } else {
16231628 return self.fail("TODO implement calling bitcasted functions", .{});
......@@ -2485,9 +2490,18 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
24852490 });
24862491 },
24872492 .memory => |addr| {
2493 const owner_decl = self.mod_fn.owner_decl;
2494 // TODO when refactoring LinkBlock, make this into a generic function.
2495 const atom_index = switch (self.bin_file.tag) {
2496 .macho => owner_decl.link.macho.local_sym_index,
2497 .elf => owner_decl.link.elf.local_sym_index,
2498 .plan9 => @intCast(u32, owner_decl.link.plan9.sym_index orelse 0),
2499 else => return self.fail("TODO handle aarch64 load memory in {}", .{self.bin_file.tag}),
2500 };
24882501 _ = try self.addInst(.{
24892502 .tag = .load_memory,
24902503 .data = .{ .payload = try self.addExtra(Mir.LoadMemory{
2504 .atom_index = atom_index,
24912505 .register = @enumToInt(reg),
24922506 .addr = @intCast(u32, addr),
24932507 }) },
src/arch/aarch64/Emit.zig+7-7
......@@ -537,7 +537,7 @@ fn mirDebugEpilogueBegin(self: *Emit) !void {
537537
538538fn mirCallExtern(emit: *Emit, inst: Mir.Inst.Index) !void {
539539 assert(emit.mir.instructions.items(.tag)[inst] == .call_extern);
540 const n_strx = emit.mir.instructions.items(.data)[inst].extern_fn;
540 const extern_fn = emit.mir.instructions.items(.data)[inst].extern_fn;
541541
542542 if (emit.bin_file.cast(link.File.MachO)) |macho_file| {
543543 const offset = blk: {
......@@ -547,9 +547,10 @@ fn mirCallExtern(emit: *Emit, inst: Mir.Inst.Index) !void {
547547 break :blk offset;
548548 };
549549 // Add relocation to the decl.
550 try macho_file.active_decl.?.link.macho.relocs.append(emit.bin_file.allocator, .{
550 const atom = macho_file.atom_by_index_table.get(extern_fn.atom_index).?;
551 try atom.relocs.append(emit.bin_file.allocator, .{
551552 .offset = offset,
552 .target = .{ .global = n_strx },
553 .target = .{ .global = extern_fn.sym_name },
553554 .addend = 0,
554555 .subtractor = null,
555556 .pcrel = true,
......@@ -613,10 +614,9 @@ fn mirLoadMemory(emit: *Emit, inst: Mir.Inst.Index) !void {
613614 ));
614615
615616 if (emit.bin_file.cast(link.File.MachO)) |macho_file| {
616 // TODO I think the reloc might be in the wrong place.
617 const decl = macho_file.active_decl.?;
617 const atom = macho_file.atom_by_index_table.get(load_memory.atom_index).?;
618618 // Page reloc for adrp instruction.
619 try decl.link.macho.relocs.append(emit.bin_file.allocator, .{
619 try atom.relocs.append(emit.bin_file.allocator, .{
620620 .offset = offset,
621621 .target = .{ .local = addr },
622622 .addend = 0,
......@@ -626,7 +626,7 @@ fn mirLoadMemory(emit: *Emit, inst: Mir.Inst.Index) !void {
626626 .@"type" = @enumToInt(std.macho.reloc_type_arm64.ARM64_RELOC_GOT_LOAD_PAGE21),
627627 });
628628 // Pageoff reloc for adrp instruction.
629 try decl.link.macho.relocs.append(emit.bin_file.allocator, .{
629 try atom.relocs.append(emit.bin_file.allocator, .{
630630 .offset = offset + 4,
631631 .target = .{ .local = addr },
632632 .addend = 0,
src/arch/aarch64/Mir.zig+7-1
......@@ -134,7 +134,12 @@ pub const Inst = struct {
134134 /// An extern function
135135 ///
136136 /// Used by e.g. call_extern
137 extern_fn: u32,
137 extern_fn: struct {
138 /// Index of the containing atom.
139 atom_index: u32,
140 /// Index into the linker's string table.
141 sym_name: u32,
142 },
138143 /// A 16-bit immediate value.
139144 ///
140145 /// Used by e.g. svc
......@@ -278,6 +283,7 @@ pub fn extraData(mir: Mir, comptime T: type, index: usize) struct { data: T, end
278283}
279284
280285pub const LoadMemory = struct {
286 atom_index: u32,
281287 register: u32,
282288 addr: u32,
283289};
src/arch/x86_64/CodeGen.zig+48-4
......@@ -1897,7 +1897,12 @@ fn store(self: *Self, ptr: MCValue, value: MCValue, ptr_ty: Type, value_ty: Type
18971897 .reg1 = addr_reg.to64(),
18981898 .flags = flags,
18991899 }).encode(),
1900 .data = .{ .linker_sym_index = sym_index },
1900 .data = .{
1901 .load_reloc = .{
1902 .atom_index = self.mod_fn.owner_decl.link.macho.local_sym_index,
1903 .sym_index = sym_index,
1904 },
1905 },
19011906 });
19021907 break :blk addr_reg;
19031908 },
......@@ -2670,7 +2675,12 @@ fn airCall(self: *Self, inst: Air.Inst.Index) !void {
26702675 _ = try self.addInst(.{
26712676 .tag = .call_extern,
26722677 .ops = undefined,
2673 .data = .{ .extern_fn = n_strx },
2678 .data = .{
2679 .extern_fn = .{
2680 .atom_index = self.mod_fn.owner_decl.link.macho.local_sym_index,
2681 .sym_name = n_strx,
2682 },
2683 },
26742684 });
26752685 } else {
26762686 return self.fail("TODO implement calling bitcasted functions", .{});
......@@ -3550,7 +3560,12 @@ fn genSetStackArg(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerE
35503560 .reg1 = addr_reg.to64(),
35513561 .flags = flags,
35523562 }).encode(),
3553 .data = .{ .linker_sym_index = sym_index },
3563 .data = .{
3564 .load_reloc = .{
3565 .atom_index = self.mod_fn.owner_decl.link.macho.local_sym_index,
3566 .sym_index = sym_index,
3567 },
3568 },
35543569 });
35553570 break :blk addr_reg;
35563571 },
......@@ -3767,6 +3782,30 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: i32, mcv: MCValue) InnerErro
37673782 const reg = try self.copyToTmpRegister(Type.usize, .{ .immediate = addr });
37683783 break :blk reg;
37693784 },
3785 .direct_load,
3786 .got_load,
3787 => |sym_index| {
3788 const flags: u2 = switch (mcv) {
3789 .got_load => 0b00,
3790 .direct_load => 0b01,
3791 else => unreachable,
3792 };
3793 const addr_reg = try self.register_manager.allocReg(null);
3794 _ = try self.addInst(.{
3795 .tag = .lea_pie,
3796 .ops = (Mir.Ops{
3797 .reg1 = addr_reg.to64(),
3798 .flags = flags,
3799 }).encode(),
3800 .data = .{
3801 .load_reloc = .{
3802 .atom_index = self.mod_fn.owner_decl.link.macho.local_sym_index,
3803 .sym_index = sym_index,
3804 },
3805 },
3806 });
3807 break :blk addr_reg;
3808 },
37703809 else => {
37713810 return self.fail("TODO implement memcpy for setting stack from {}", .{mcv});
37723811 },
......@@ -4202,7 +4241,12 @@ fn genSetReg(self: *Self, ty: Type, reg: Register, mcv: MCValue) InnerError!void
42024241 .reg1 = reg,
42034242 .flags = flags,
42044243 }).encode(),
4205 .data = .{ .linker_sym_index = sym_index },
4244 .data = .{
4245 .load_reloc = .{
4246 .atom_index = self.mod_fn.owner_decl.link.macho.local_sym_index,
4247 .sym_index = sym_index,
4248 },
4249 },
42064250 });
42074251 // MOV reg, [reg]
42084252 _ = try self.addInst(.{
src/arch/x86_64/Emit.zig+12-7
......@@ -763,6 +763,7 @@ fn mirLeaPie(emit: *Emit, inst: Mir.Inst.Index) InnerError!void {
763763 const tag = emit.mir.instructions.items(.tag)[inst];
764764 assert(tag == .lea_pie);
765765 const ops = Mir.Ops.decode(emit.mir.instructions.items(.ops)[inst]);
766 const load_reloc = emit.mir.instructions.items(.data)[inst].load_reloc;
766767
767768 // lea reg1, [rip + reloc]
768769 // RM
......@@ -772,18 +773,19 @@ fn mirLeaPie(emit: *Emit, inst: Mir.Inst.Index) InnerError!void {
772773 RegisterOrMemory.rip(Memory.PtrSize.fromBits(ops.reg1.size()), 0),
773774 emit.code,
774775 );
776
775777 const end_offset = emit.code.items.len;
776 const sym_index = emit.mir.instructions.items(.data)[inst].linker_sym_index;
778
777779 if (emit.bin_file.cast(link.File.MachO)) |macho_file| {
778780 const reloc_type = switch (ops.flags) {
779781 0b00 => @enumToInt(std.macho.reloc_type_x86_64.X86_64_RELOC_GOT),
780782 0b01 => @enumToInt(std.macho.reloc_type_x86_64.X86_64_RELOC_SIGNED),
781783 else => return emit.fail("TODO unused LEA PIE variants 0b10 and 0b11", .{}),
782784 };
783 const decl = macho_file.active_decl.?;
784 try decl.link.macho.relocs.append(emit.bin_file.allocator, .{
785 const atom = macho_file.atom_by_index_table.get(load_reloc.atom_index).?;
786 try atom.relocs.append(emit.bin_file.allocator, .{
785787 .offset = @intCast(u32, end_offset - 4),
786 .target = .{ .local = sym_index },
788 .target = .{ .local = load_reloc.sym_index },
787789 .addend = 0,
788790 .subtractor = null,
789791 .pcrel = true,
......@@ -801,17 +803,20 @@ fn mirLeaPie(emit: *Emit, inst: Mir.Inst.Index) InnerError!void {
801803fn mirCallExtern(emit: *Emit, inst: Mir.Inst.Index) InnerError!void {
802804 const tag = emit.mir.instructions.items(.tag)[inst];
803805 assert(tag == .call_extern);
804 const n_strx = emit.mir.instructions.items(.data)[inst].extern_fn;
806 const extern_fn = emit.mir.instructions.items(.data)[inst].extern_fn;
807
805808 const offset = blk: {
806809 // callq
807810 try lowerToDEnc(.call_near, 0, emit.code);
808811 break :blk @intCast(u32, emit.code.items.len) - 4;
809812 };
813
810814 if (emit.bin_file.cast(link.File.MachO)) |macho_file| {
811815 // Add relocation to the decl.
812 try macho_file.active_decl.?.link.macho.relocs.append(emit.bin_file.allocator, .{
816 const atom = macho_file.atom_by_index_table.get(extern_fn.atom_index).?;
817 try atom.relocs.append(emit.bin_file.allocator, .{
813818 .offset = offset,
814 .target = .{ .global = n_strx },
819 .target = .{ .global = extern_fn.sym_name },
815820 .addend = 0,
816821 .subtractor = null,
817822 .pcrel = true,
src/arch/x86_64/Mir.zig+15-6
......@@ -185,7 +185,7 @@ pub const Inst = struct {
185185 /// 0b00 reg1, [rip + reloc] // via GOT emits X86_64_RELOC_GOT relocation
186186 /// 0b01 reg1, [rip + reloc] // direct load emits X86_64_RELOC_SIGNED relocation
187187 /// Notes:
188 /// * `Data` contains `linker_sym_index`
188 /// * `Data` contains `load_reloc`
189189 lea_pie,
190190
191191 /// ops flags: form:
......@@ -350,10 +350,19 @@ pub const Inst = struct {
350350 /// A 32-bit immediate value.
351351 imm: u32,
352352 /// An extern function.
353 /// Index into the linker's string table.
354 extern_fn: u32,
355 /// Entry in the linker's symbol table.
356 linker_sym_index: u32,
353 extern_fn: struct {
354 /// Index of the containing atom.
355 atom_index: u32,
356 /// Index into the linker's string table.
357 sym_name: u32,
358 },
359 /// PIE load relocation.
360 load_reloc: struct {
361 /// Index of the containing atom.
362 atom_index: u32,
363 /// Index into the linker's symbol table.
364 sym_index: u32,
365 },
357366 /// Index into `extra`. Meaning of what can be found there is context-dependent.
358367 payload: u32,
359368 };
......@@ -362,7 +371,7 @@ pub const Inst = struct {
362371 // Note that in Debug builds, Zig is allowed to insert a secret field for safety checks.
363372 comptime {
364373 if (builtin.mode != .Debug) {
365 assert(@sizeOf(Inst) == 8);
374 assert(@sizeOf(Data) == 8);
366375 }
367376 }
368377};
src/arch/x86_64/PrintMir.zig+2-2
......@@ -450,6 +450,7 @@ fn mirLea(print: *const Print, inst: Mir.Inst.Index, w: anytype) !void {
450450
451451fn mirLeaPie(print: *const Print, inst: Mir.Inst.Index, w: anytype) !void {
452452 const ops = Mir.Ops.decode(print.mir.instructions.items(.ops)[inst]);
453 const load_reloc = print.mir.instructions.items(.data)[inst].load_reloc;
453454 try w.print("lea {s}, ", .{@tagName(ops.reg1)});
454455 switch (ops.reg1.size()) {
455456 8 => try w.print("byte ptr ", .{}),
......@@ -459,9 +460,8 @@ fn mirLeaPie(print: *const Print, inst: Mir.Inst.Index, w: anytype) !void {
459460 else => unreachable,
460461 }
461462 try w.print("[rip + 0x0] ", .{});
462 const sym_index = print.mir.instructions.items(.data)[inst].linker_sym_index;
463463 if (print.bin_file.cast(link.File.MachO)) |macho_file| {
464 const target = macho_file.locals.items[sym_index];
464 const target = macho_file.locals.items[load_reloc.sym_index];
465465 const target_name = macho_file.getString(target.n_strx);
466466 try w.print("target@{s}", .{target_name});
467467 } else {
src/link/MachO.zig+21-32
......@@ -40,6 +40,7 @@ const StringIndexContext = std.hash_map.StringIndexContext;
4040const Trie = @import("MachO/Trie.zig");
4141const Type = @import("../type.zig").Type;
4242const TypedValue = @import("../TypedValue.zig");
43const Value = @import("../value.zig").Value;
4344
4445pub const TextBlock = Atom;
4546
......@@ -220,6 +221,7 @@ atoms: std.AutoHashMapUnmanaged(MatchingSection, *Atom) = .{},
220221/// at present owned by Module.Decl.
221222/// TODO consolidate this.
222223managed_atoms: std.ArrayListUnmanaged(*Atom) = .{},
224atom_by_index_table: std.AutoHashMapUnmanaged(u32, *Atom) = .{},
223225
224226/// Table of unnamed constants associated with a parent `Decl`.
225227/// We store them here so that we can free the constants whenever the `Decl`
......@@ -248,12 +250,6 @@ unnamed_const_atoms: UnnamedConstTable = .{},
248250/// TODO consolidate this.
249251decls: std.AutoArrayHashMapUnmanaged(*Module.Decl, ?MatchingSection) = .{},
250252
251/// Currently active Module.Decl.
252/// TODO this might not be necessary if we figure out how to pass Module.Decl instance
253/// to codegen.genSetReg() or alternatively move PIE displacement for MCValue{ .memory = x }
254/// somewhere else in the codegen.
255active_decl: ?*Module.Decl = null,
256
257253const Entry = struct {
258254 target: Atom.Relocation.Target,
259255 atom: *Atom,
......@@ -3441,6 +3437,8 @@ pub fn deinit(self: *MachO) void {
34413437 }
34423438 self.unnamed_const_atoms.deinit(self.base.allocator);
34433439 }
3440
3441 self.atom_by_index_table.deinit(self.base.allocator);
34443442}
34453443
34463444pub fn closeFiles(self: MachO) void {
......@@ -3647,6 +3645,7 @@ pub fn allocateDeclIndexes(self: *MachO, decl: *Module.Decl) !void {
36473645 if (decl.link.macho.local_sym_index != 0) return;
36483646
36493647 decl.link.macho.local_sym_index = try self.allocateLocalSymbol();
3648 try self.atom_by_index_table.putNoClobber(self.base.allocator, decl.link.macho.local_sym_index, &decl.link.macho);
36503649 try self.decls.putNoClobber(self.base.allocator, decl, null);
36513650
36523651 const got_target = .{ .local = decl.link.macho.local_sym_index };
......@@ -3693,8 +3692,6 @@ pub fn updateFunc(self: *MachO, module: *Module, func: *Module.Fn, air: Air, liv
36933692 }
36943693 }
36953694
3696 self.active_decl = decl;
3697
36983695 const res = if (debug_buffers) |dbg|
36993696 try codegen.generateFunction(&self.base, decl.srcLoc(), func, air, liveness, &code_buffer, .{
37003697 .dwarf = .{
......@@ -3756,14 +3753,9 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl: *Module.De
37563753 log.debug("allocating symbol indexes for {s}", .{name});
37573754
37583755 const required_alignment = typed_value.ty.abiAlignment(self.base.options.target);
3759 const match = (try self.getMatchingSection(.{
3760 .segname = makeStaticString("__TEXT"),
3761 .sectname = makeStaticString("__const"),
3762 .size = @sizeOf(u64),
3763 .@"align" = math.log2(required_alignment),
3764 })).?;
37653756 const local_sym_index = try self.allocateLocalSymbol();
37663757 const atom = try self.createEmptyAtom(local_sym_index, @sizeOf(u64), math.log2(required_alignment));
3758 try self.atom_by_index_table.putNoClobber(self.base.allocator, local_sym_index, atom);
37673759
37683760 const res = try codegen.generateSymbol(&self.base, local_sym_index, decl.srcLoc(), typed_value, &code_buffer, .{
37693761 .none = .{},
......@@ -3780,6 +3772,8 @@ pub fn lowerUnnamedConst(self: *MachO, typed_value: TypedValue, decl: *Module.De
37803772
37813773 atom.code.clearRetainingCapacity();
37823774 try atom.code.appendSlice(self.base.allocator, code);
3775
3776 const match = try self.getMatchingSectionAtom(atom, typed_value.ty, typed_value.val);
37833777 const addr = try self.allocateAtom(atom, code.len, required_alignment, match);
37843778
37853779 log.debug("allocated atom for {s} at 0x{x}", .{ name, addr });
......@@ -3839,11 +3833,9 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
38393833 }
38403834 }
38413835
3842 self.active_decl = decl;
3843
38443836 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
38453837 const res = if (debug_buffers) |dbg|
3846 try codegen.generateSymbol(&self.base, decl.link.elf.local_sym_index, decl.srcLoc(), .{
3838 try codegen.generateSymbol(&self.base, decl.link.macho.local_sym_index, decl.srcLoc(), .{
38473839 .ty = decl.ty,
38483840 .val = decl_val,
38493841 }, &code_buffer, .{
......@@ -3854,7 +3846,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
38543846 },
38553847 })
38563848 else
3857 try codegen.generateSymbol(&self.base, decl.link.elf.local_sym_index, decl.srcLoc(), .{
3849 try codegen.generateSymbol(&self.base, decl.link.macho.local_sym_index, decl.srcLoc(), .{
38583850 .ty = decl.ty,
38593851 .val = decl_val,
38603852 }, &code_buffer, .none);
......@@ -3908,13 +3900,11 @@ fn isElemTyPointer(ty: Type) bool {
39083900 }
39093901}
39103902
3911fn getMatchingSectionDecl(self: *MachO, decl: *Module.Decl) !MatchingSection {
3912 const code = decl.link.macho.code.items;
3913 const alignment = decl.ty.abiAlignment(self.base.options.target);
3903fn getMatchingSectionAtom(self: *MachO, atom: *Atom, ty: Type, val: Value) !MatchingSection {
3904 const code = atom.code.items;
3905 const alignment = ty.abiAlignment(self.base.options.target);
39143906 const align_log_2 = math.log2(alignment);
3915 const ty = decl.ty;
39163907 const zig_ty = ty.zigTypeTag();
3917 const val = decl.val;
39183908 const mode = self.base.options.optimize_mode;
39193909 const match: MatchingSection = blk: {
39203910 // TODO finish and audit this function
......@@ -4023,9 +4013,11 @@ fn getMatchingSectionDecl(self: *MachO, decl: *Module.Decl) !MatchingSection {
40234013 },
40244014 }
40254015 };
4016 const local = self.locals.items[atom.local_sym_index];
40264017 const seg = self.load_commands.items[match.seg].segment;
40274018 const sect = seg.sections.items[match.sect];
4028 log.debug(" allocating atom in '{s},{s}' ({d},{d})", .{
4019 log.debug(" allocating atom '{s}' in '{s},{s}' ({d},{d})", .{
4020 self.getString(local.n_strx),
40294021 sect.segName(),
40304022 sect.sectName(),
40314023 match.seg,
......@@ -4041,7 +4033,7 @@ fn placeDecl(self: *MachO, decl: *Module.Decl, code_len: usize) !*macho.nlist_64
40414033
40424034 const decl_ptr = self.decls.getPtr(decl).?;
40434035 if (decl_ptr.* == null) {
4044 decl_ptr.* = try self.getMatchingSectionDecl(decl);
4036 decl_ptr.* = try self.getMatchingSectionAtom(&decl.link.macho, decl.ty, decl.val);
40454037 }
40464038 const match = decl_ptr.*.?;
40474039
......@@ -4290,6 +4282,8 @@ fn freeUnnamedConsts(self: *MachO, decl: *Module.Decl) void {
42904282 }, true);
42914283 self.locals_free_list.append(self.base.allocator, atom.local_sym_index) catch {};
42924284 self.locals.items[atom.local_sym_index].n_type = 0;
4285 _ = self.atom_by_index_table.remove(atom.local_sym_index);
4286 atom.local_sym_index = 0;
42934287 }
42944288 unnamed_consts.clearAndFree(self.base.allocator);
42954289}
......@@ -4316,6 +4310,7 @@ pub fn freeDecl(self: *MachO, decl: *Module.Decl) void {
43164310 }
43174311
43184312 self.locals.items[decl.link.macho.local_sym_index].n_type = 0;
4313 _ = self.atom_by_index_table.remove(decl.link.macho.local_sym_index);
43194314 decl.link.macho.local_sym_index = 0;
43204315 }
43214316 if (self.d_sym) |*ds| {
......@@ -4347,13 +4342,7 @@ pub fn getDeclVAddr(self: *MachO, decl: *const Module.Decl, parent_atom_index: u
43474342 assert(self.llvm_object == null);
43484343 assert(decl.link.macho.local_sym_index != 0);
43494344
4350 // TODO cache local_sym_index => atom!!!
4351 const atom: *Atom = blk: for (self.managed_atoms.items) |atom| {
4352 if (atom.local_sym_index == parent_atom_index) {
4353 break :blk atom;
4354 }
4355 } else unreachable;
4356
4345 const atom = self.atom_by_index_table.get(parent_atom_index).?;
43574346 try atom.relocs.append(self.base.allocator, .{
43584347 .offset = @intCast(u32, offset),
43594348 .target = .{ .local = decl.link.macho.local_sym_index },
src/link/Plan9.zig+3-1
......@@ -302,7 +302,9 @@ pub fn updateDecl(self: *Plan9, module: *Module, decl: *Module.Decl) !void {
302302 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
303303 defer code_buffer.deinit();
304304 const decl_val = if (decl.val.castTag(.variable)) |payload| payload.data.init else decl.val;
305 const res = try codegen.generateSymbol(&self.base, @intCast(u32, decl.link.plan9.sym_index.?), decl.srcLoc(), .{
305 // TODO we need the symbol index for symbol in the table of locals for the containing atom
306 const sym_index = decl.link.plan9.sym_index orelse 0;
307 const res = try codegen.generateSymbol(&self.base, @intCast(u32, sym_index), decl.srcLoc(), .{
306308 .ty = decl.ty,
307309 .val = decl_val,
308310 }, &code_buffer, .{ .none = .{} });