authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-24 18:43:38+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-24 20:27:23+02:00
log5e0e7b2cb4b568e244a4b0b4eb51d8faeb3fb226
treec4e49d6a466182267f81a09aa2b17c70eb70260d
parent8669e3d46b24fcd6b6aa1053a16cf5301ed0e87a

zld: exclude libs part of the umbrella

when parsing the umbrella lib

2 files changed, 34 insertions(+), 19 deletions(-)

src/link/MachO/Dylib.zig+34-16
......@@ -62,7 +62,6 @@ pub fn createAndParseFromPath(
6262 arch: Arch,
6363 path: []const u8,
6464 syslibroot: ?[]const u8,
65 recurse_libs: bool,
6665) Error!?[]*Dylib {
6766 const file = fs.cwd().openFile(path, .{}) catch |err| switch (err) {
6867 error.FileNotFound => return null,
......@@ -102,11 +101,9 @@ pub fn createAndParseFromPath(
102101
103102 var dylibs = std.ArrayList(*Dylib).init(allocator);
104103 defer dylibs.deinit();
105 try dylibs.append(dylib);
106104
107 if (recurse_libs) {
108 try dylib.parseDependentLibs(&dylibs);
109 }
105 try dylibs.append(dylib);
106 try dylib.parseDependentLibs(&dylibs);
110107
111108 return dylibs.toOwnedSlice();
112109}
......@@ -283,18 +280,17 @@ pub fn parseFromStub(self: *Dylib, lib_stub: LibStub) !void {
283280 else => unreachable,
284281 };
285282
286 for (lib_stub.inner) |stub| {
287 if (!hasTarget(stub.targets, target_string)) continue;
283 var umbrella_libs = std.StringHashMap(void).init(self.allocator);
284 defer umbrella_libs.deinit();
288285
289 if (stub.reexported_libraries) |reexports| {
290 for (reexports) |reexp| {
291 if (!hasTarget(reexp.targets, target_string)) continue;
286 for (lib_stub.inner) |stub, stub_index| {
287 if (!hasTarget(stub.targets, target_string)) continue;
292288
293 try self.dependent_libs.ensureUnusedCapacity(self.allocator, reexp.libraries.len);
294 for (reexp.libraries) |lib| {
295 self.dependent_libs.putAssumeCapacity(try self.allocator.dupe(u8, lib), {});
296 }
297 }
289 if (stub_index > 0) {
290 // TODO I thought that we could switch on presence of `parent-umbrella` map;
291 // however, turns out `libsystem_notify.dylib` is fully reexported by `libSystem.dylib`
292 // BUT does not feature a `parent-umbrella` map as the only sublib. Apple's bug perhaps?
293 try umbrella_libs.put(stub.install_name, .{});
298294 }
299295
300296 if (stub.exports) |exports| {
......@@ -341,6 +337,29 @@ pub fn parseFromStub(self: *Dylib, lib_stub: LibStub) !void {
341337 }
342338 }
343339 }
340
341 log.debug("{s}", .{umbrella_lib.install_name});
342
343 // TODO track which libs were already parsed in different steps
344 for (lib_stub.inner) |stub| {
345 if (!hasTarget(stub.targets, target_string)) continue;
346
347 if (stub.reexported_libraries) |reexports| {
348 for (reexports) |reexp| {
349 if (!hasTarget(reexp.targets, target_string)) continue;
350
351 for (reexp.libraries) |lib| {
352 if (umbrella_libs.contains(lib)) {
353 log.debug(" | {s} <= {s}", .{ lib, umbrella_lib.install_name });
354 continue;
355 }
356
357 log.debug(" | {s}", .{lib});
358 try self.dependent_libs.put(self.allocator, try self.allocator.dupe(u8, lib), {});
359 }
360 }
361 }
362 }
344363}
345364
346365pub fn parseDependentLibs(self: *Dylib, out: *std.ArrayList(*Dylib)) !void {
......@@ -374,7 +393,6 @@ pub fn parseDependentLibs(self: *Dylib, out: *std.ArrayList(*Dylib)) !void {
374393 self.arch.?,
375394 lib_path,
376395 self.syslibroot,
377 true,
378396 )) orelse {
379397 continue;
380398 };
src/link/MachO/Zld.zig-3
......@@ -279,7 +279,6 @@ fn parseInputFiles(self: *Zld, files: []const []const u8) !void {
279279 self.arch.?,
280280 full_path,
281281 self.syslibroot,
282 true,
283282 )) |dylibs| {
284283 defer self.allocator.free(dylibs);
285284 try self.dylibs.appendSlice(self.allocator, dylibs);
......@@ -297,7 +296,6 @@ fn parseLibs(self: *Zld, libs: []const []const u8) !void {
297296 self.arch.?,
298297 lib,
299298 self.syslibroot,
300 true,
301299 )) |dylibs| {
302300 defer self.allocator.free(dylibs);
303301 try self.dylibs.appendSlice(self.allocator, dylibs);
......@@ -319,7 +317,6 @@ fn parseLibSystem(self: *Zld, libc_stub_path: []const u8) !void {
319317 self.arch.?,
320318 libc_stub_path,
321319 self.syslibroot,
322 false,
323320 )) orelse return error.FailedToParseLibSystem;
324321 defer self.allocator.free(dylibs);
325322