authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-17 22:10:07+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-17 22:10:07+02:00
log790633a2a09164db5985d1c8302a60d3809e5002
tree8ac9657594261627e3dd29374d4bc294363cd8eb
parent8b795fe2ac17466d0bc9de7b494f0cf076d7c46d

macho: use common codepath for resolving dyld_stub_binder


1 files changed, 7 insertions(+), 24 deletions(-)

src/link/MachO.zig+7-24
......@@ -376,30 +376,6 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
376376 try self.populateMissingMetadata();
377377 try self.writeLocalSymbol(0);
378378
379 if (self.dyld_stub_binder_index == null) {
380 self.dyld_stub_binder_index = @intCast(u32, self.undefs.items.len);
381 const n_strx = try self.makeString("dyld_stub_binder");
382 try self.undefs.append(self.base.allocator, .{
383 .n_strx = n_strx,
384 .n_type = macho.N_UNDF | macho.N_EXT,
385 .n_sect = 0,
386 .n_desc = @intCast(u8, 1) * macho.N_SYMBOL_RESOLVER,
387 .n_value = 0,
388 });
389 try self.symbol_resolver.putNoClobber(self.base.allocator, n_strx, .{
390 .where = .undef,
391 .where_index = self.dyld_stub_binder_index.?,
392 });
393 const got_key = GotIndirectionKey{
394 .where = .undef,
395 .where_index = self.dyld_stub_binder_index.?,
396 };
397 const got_index = @intCast(u32, self.got_entries.items.len);
398 try self.got_entries.append(self.base.allocator, got_key);
399 try self.got_entries_map.putNoClobber(self.base.allocator, got_key, got_index);
400 try self.writeGotEntry(got_index);
401 self.binding_info_dirty = true;
402 }
403379 if (self.stub_helper_stubs_start_off == null) {
404380 try self.writeStubHelperPreamble();
405381 }
......@@ -1089,6 +1065,7 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const
10891065 break :full_path try self.base.allocator.dupe(u8, path);
10901066 };
10911067 defer self.base.allocator.free(full_path);
1068 log.debug("parsing input file path '{s}'", .{full_path});
10921069
10931070 if (try self.parseObject(full_path)) continue;
10941071 if (try self.parseArchive(full_path)) continue;
......@@ -1102,6 +1079,7 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const
11021079
11031080fn parseLibs(self: *MachO, libs: []const []const u8, syslibroot: ?[]const u8) !void {
11041081 for (libs) |lib| {
1082 log.debug("parsing lib path '{s}'", .{lib});
11051083 if (try self.parseDylib(lib, .{
11061084 .syslibroot = syslibroot,
11071085 })) continue;
......@@ -2510,6 +2488,11 @@ fn resolveDyldStubBinder(self: *MachO) !void {
25102488
25112489 self.binding_info_dirty = true;
25122490 self.got_entries_count_dirty = true;
2491
2492 if (!(build_options.is_stage1 and self.base.options.use_stage1)) {
2493 // TODO remove once we can incrementally update in stage1 too.
2494 try self.writeGotEntry(got_index);
2495 }
25132496}
25142497
25152498fn parseTextBlocks(self: *MachO) !void {