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...@@ -376,30 +376,6 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
376 try self.populateMissingMetadata();376 try self.populateMissingMetadata();
377 try self.writeLocalSymbol(0);377 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 }
403 if (self.stub_helper_stubs_start_off == null) {379 if (self.stub_helper_stubs_start_off == null) {
404 try self.writeStubHelperPreamble();380 try self.writeStubHelperPreamble();
405 }381 }
...@@ -1089,6 +1065,7 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const...@@ -1089,6 +1065,7 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const
1089 break :full_path try self.base.allocator.dupe(u8, path);1065 break :full_path try self.base.allocator.dupe(u8, path);
1090 };1066 };
1091 defer self.base.allocator.free(full_path);1067 defer self.base.allocator.free(full_path);
1068 log.debug("parsing input file path '{s}'", .{full_path});
10921069
1093 if (try self.parseObject(full_path)) continue;1070 if (try self.parseObject(full_path)) continue;
1094 if (try self.parseArchive(full_path)) continue;1071 if (try self.parseArchive(full_path)) continue;
...@@ -1102,6 +1079,7 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const...@@ -1102,6 +1079,7 @@ fn parseInputFiles(self: *MachO, files: []const []const u8, syslibroot: ?[]const
11021079
1103fn parseLibs(self: *MachO, libs: []const []const u8, syslibroot: ?[]const u8) !void {1080fn parseLibs(self: *MachO, libs: []const []const u8, syslibroot: ?[]const u8) !void {
1104 for (libs) |lib| {1081 for (libs) |lib| {
1082 log.debug("parsing lib path '{s}'", .{lib});
1105 if (try self.parseDylib(lib, .{1083 if (try self.parseDylib(lib, .{
1106 .syslibroot = syslibroot,1084 .syslibroot = syslibroot,
1107 })) continue;1085 })) continue;
...@@ -2510,6 +2488,11 @@ fn resolveDyldStubBinder(self: *MachO) !void {...@@ -2510,6 +2488,11 @@ fn resolveDyldStubBinder(self: *MachO) !void {
25102488
2511 self.binding_info_dirty = true;2489 self.binding_info_dirty = true;
2512 self.got_entries_count_dirty = true;2490 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 }
2513}2496}
25142497
2515fn parseTextBlocks(self: *MachO) !void {2498fn parseTextBlocks(self: *MachO) !void {