Skip to content

Commit

Permalink
macho: mark explicit dylibs to differentiate them from hoisted dylibs
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Dec 12, 2023
1 parent 798c5a2 commit 4ed0d66
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
26 changes: 9 additions & 17 deletions src/MachO.zig
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pub fn flush(self: *MachO) !void {

for (self.dylibs.items) |index| {
const dylib = self.getFile(index).?.dylib;
if (!dylib.hoisted) continue;
if (!dylib.explicit and !dylib.hoisted) continue;
try dylib.initSymbols(self);
}

Expand Down Expand Up @@ -583,8 +583,8 @@ fn parsePositional(self: *MachO, arena: Allocator, obj: LinkObject) !void {

if (try self.parseObject(arena, obj)) return;
if (try self.parseArchive(arena, obj)) return;
if (try self.parseDylib(arena, obj)) |_| return;
if (try self.parseTbd(obj)) |_| return;
if (try self.parseDylib(arena, obj, true)) |_| return;
if (try self.parseTbd(obj, true)) |_| return;

self.base.fatal("unknown filetype for positional argument: '{s}'", .{obj.path});
}
Expand Down Expand Up @@ -695,7 +695,7 @@ const DylibOpts = struct {
reexport: bool = false,
};

fn parseDylib(self: *MachO, arena: Allocator, obj: LinkObject) anyerror!?File.Index {
fn parseDylib(self: *MachO, arena: Allocator, obj: LinkObject, explicit: bool) anyerror!?File.Index {
const tracy = trace(@src());
defer tracy.end();

Expand Down Expand Up @@ -738,6 +738,7 @@ fn parseDylib(self: *MachO, arena: Allocator, obj: LinkObject) anyerror!?File.In
.needed = obj.needed,
.weak = obj.weak,
.reexport = obj.reexport,
.explicit = explicit,
} });
const dylib = &self.files.items(.data)[index].dylib;
try dylib.parse(self);
Expand All @@ -749,7 +750,7 @@ fn parseDylib(self: *MachO, arena: Allocator, obj: LinkObject) anyerror!?File.In
return index;
}

fn parseTbd(self: *MachO, obj: LinkObject) anyerror!?File.Index {
fn parseTbd(self: *MachO, obj: LinkObject, explicit: bool) anyerror!?File.Index {
const tracy = trace(@src());
defer tracy.end();

Expand All @@ -775,6 +776,7 @@ fn parseTbd(self: *MachO, obj: LinkObject) anyerror!?File.Index {
.needed = obj.needed,
.weak = obj.weak,
.reexport = obj.reexport,
.explicit = explicit,
} });
const dylib = &self.files.items(.data)[index].dylib;
try dylib.parseTbd(cpu_arch, self.options.platform, lib_stub, self);
Expand Down Expand Up @@ -896,8 +898,8 @@ fn parseDependentDylibs(
.weak = is_weak,
};
const file_index = file_index: {
if (try self.parseDylib(arena, link_obj)) |file| break :file_index file;
if (try self.parseTbd(link_obj)) |file| break :file_index file;
if (try self.parseDylib(arena, link_obj, false)) |file| break :file_index file;
if (try self.parseTbd(link_obj, false)) |file| break :file_index file;
break :file_index @as(File.Index, 0);
};
dependents.appendAssumeCapacity(file_index);
Expand Down Expand Up @@ -995,16 +997,6 @@ fn convertTentativeDefinitions(self: *MachO) !void {
}

fn markImportsAndExports(self: *MachO) void {
// if (!self.options.dylib)
// for (self.dylibs.items) |index| {
// for (self.getFile(index).?.getSymbols()) |sym_index| {
// const sym = self.getSymbol(sym_index);
// const file = sym.getFile(self) orelse continue;
// if (sym.visibility != .global) continue;
// if (file != .dylib) sym.flags.@"export" = true;
// }
// };

for (self.objects.items) |index| {
for (self.getFile(index).?.getSymbols()) |sym_index| {
const sym = self.getSymbol(sym_index);
Expand Down
3 changes: 2 additions & 1 deletion src/MachO/Dylib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ platform: ?MachO.Options.Platform = null,
needed: bool,
weak: bool,
reexport: bool,
explicit: bool,
hoisted: bool = true,
referenced: bool = false,

Expand Down Expand Up @@ -473,7 +474,7 @@ pub fn resetGlobals(self: *Dylib, macho_file: *MachO) void {
}

pub fn isAlive(self: Dylib, macho_file: *MachO) bool {
if (!macho_file.options.dead_strip_dylibs) return self.hoisted;
if (!macho_file.options.dead_strip_dylibs) return self.explicit or self.referenced or self.needed;
return self.referenced or self.needed;
}

Expand Down

0 comments on commit 4ed0d66

Please sign in to comment.