aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-01-11 19:15:54 +0100
committerJakub Konka <kubkon@jakubkonka.com>2024-01-24 12:34:39 +0100
commitb28ff75f5d47ead9e8b416b41149147d796ff8db (patch)
treece9b62a9c05b11502dc208b858d141b33581c826 /src
parentb0327ff233faca0dd11e50c9ba7fc41f434a4d82 (diff)
downloadzig-b28ff75f5d47ead9e8b416b41149147d796ff8db.tar.gz
zig-b28ff75f5d47ead9e8b416b41149147d796ff8db.zip
macho: mark imports and exports
Diffstat (limited to 'src')
-rw-r--r--src/link/MachO.zig40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig
index f9e1c2a953..8783098e6b 100644
--- a/src/link/MachO.zig
+++ b/src/link/MachO.zig
@@ -505,6 +505,8 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node
try dead_strip.gcAtoms(self);
}
+ self.markImportsAndExports();
+
state_log.debug("{}", .{self.dumpState()});
@panic("TODO");
@@ -1345,6 +1347,44 @@ fn claimUnresolved(self: *MachO) error{OutOfMemory}!void {
}
}
+fn markImportsAndExports(self: *MachO) void {
+ for (self.objects.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 and !sym.flags.abs) {
+ sym.flags.import = true;
+ continue;
+ }
+ if (file.getIndex() == index) {
+ sym.flags.@"export" = true;
+ }
+ }
+ }
+
+ for (self.undefined_symbols.items) |index| {
+ const sym = self.getSymbol(index);
+ if (sym.getFile(self)) |file| {
+ if (sym.visibility != .global) continue;
+ if (file == .dylib and !sym.flags.abs) sym.flags.import = true;
+ }
+ }
+
+ for (&[_]?Symbol.Index{
+ self.entry_index,
+ self.dyld_stub_binder_index,
+ self.objc_msg_send_index,
+ }) |index| {
+ if (index) |idx| {
+ const sym = self.getSymbol(idx);
+ if (sym.getFile(self)) |file| {
+ if (file == .dylib) sym.flags.import = true;
+ }
+ }
+ }
+}
+
fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void {
_ = self;
_ = atom_index;