authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-11 18:30:22+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:39+01:00
logb8f67d79850b0be1f2384dca0a9a946bfa6a75a6
treec779d8a1f7e53f81bd6d0441c86fb6b9a98869f4
parent8c7a34ae68bbc87e67692e280350f8f825a59230

macho: init InternalObject and add forced undefined globals


1 files changed, 45 insertions(+), 0 deletions(-)

src/link/MachO.zig+45
......@@ -48,6 +48,14 @@ eh_frame_sect_index: ?u8 = null,
4848unwind_info_sect_index: ?u8 = null,
4949objc_stubs_sect_index: ?u8 = null,
5050
51mh_execute_header_index: ?Symbol.Index = null,
52mh_dylib_header_index: ?Symbol.Index = null,
53dyld_private_index: ?Symbol.Index = null,
54dyld_stub_binder_index: ?Symbol.Index = null,
55dso_handle_index: ?Symbol.Index = null,
56objc_msg_send_index: ?Symbol.Index = null,
57entry_index: ?Symbol.Index = null,
58
5159/// List of atoms that are either synthetic or map directly to the Zig source program.
5260atoms: std.ArrayListUnmanaged(Atom) = .{},
5361thunks: std.ArrayListUnmanaged(Thunk) = .{},
......@@ -482,6 +490,14 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node
482490 try dylib.initSymbols(self);
483491 }
484492
493 {
494 const index = @as(File.Index, @intCast(try self.files.addOne(gpa)));
495 self.files.set(index, .{ .internal = .{ .index = index } });
496 self.internal_object = index;
497 }
498
499 try self.addUndefinedGlobals();
500
485501 state_log.debug("{}", .{self.dumpState()});
486502
487503 @panic("TODO");
......@@ -1112,6 +1128,35 @@ fn parseTbd(self: *MachO, lib: SystemLib, explicit: bool) ParseError!File.Index
11121128// }
11131129// }
11141130
1131fn addUndefinedGlobals(self: *MachO) !void {
1132 const gpa = self.base.comp.gpa;
1133
1134 try self.undefined_symbols.ensureUnusedCapacity(gpa, self.base.comp.force_undefined_symbols.keys().len);
1135 for (self.base.comp.force_undefined_symbols.keys()) |name| {
1136 const off = try self.strings.insert(gpa, name);
1137 const gop = try self.getOrCreateGlobal(off);
1138 self.undefined_symbols.appendAssumeCapacity(gop.index);
1139 }
1140
1141 if (!self.base.isDynLib() and self.entry_name != null) {
1142 const off = try self.strings.insert(gpa, self.entry_name.?);
1143 const gop = try self.getOrCreateGlobal(off);
1144 self.entry_index = gop.index;
1145 }
1146
1147 {
1148 const off = try self.strings.insert(gpa, "dyld_stub_binder");
1149 const gop = try self.getOrCreateGlobal(off);
1150 self.dyld_stub_binder_index = gop.index;
1151 }
1152
1153 {
1154 const off = try self.strings.insert(gpa, "_objc_msgSend");
1155 const gop = try self.getOrCreateGlobal(off);
1156 self.objc_msg_send_index = gop.index;
1157 }
1158}
1159
11151160fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void {
11161161 _ = self;
11171162 _ = atom_index;