authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-11 19:15:54+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-01-24 12:34:39+01:00
logb28ff75f5d47ead9e8b416b41149147d796ff8db
treece9b62a9c05b11502dc208b858d141b33581c826
parentb0327ff233faca0dd11e50c9ba7fc41f434a4d82

macho: mark imports and exports


1 files changed, 40 insertions(+), 0 deletions(-)

src/link/MachO.zig+40
...@@ -505,6 +505,8 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node...@@ -505,6 +505,8 @@ pub fn flushModule(self: *MachO, arena: Allocator, prog_node: *std.Progress.Node
505 try dead_strip.gcAtoms(self);505 try dead_strip.gcAtoms(self);
506 }506 }
507507
508 self.markImportsAndExports();
509
508 state_log.debug("{}", .{self.dumpState()});510 state_log.debug("{}", .{self.dumpState()});
509511
510 @panic("TODO");512 @panic("TODO");
...@@ -1345,6 +1347,44 @@ fn claimUnresolved(self: *MachO) error{OutOfMemory}!void {...@@ -1345,6 +1347,44 @@ fn claimUnresolved(self: *MachO) error{OutOfMemory}!void {
1345 }1347 }
1346}1348}
13471349
1350fn markImportsAndExports(self: *MachO) void {
1351 for (self.objects.items) |index| {
1352 for (self.getFile(index).?.getSymbols()) |sym_index| {
1353 const sym = self.getSymbol(sym_index);
1354 const file = sym.getFile(self) orelse continue;
1355 if (sym.visibility != .global) continue;
1356 if (file == .dylib and !sym.flags.abs) {
1357 sym.flags.import = true;
1358 continue;
1359 }
1360 if (file.getIndex() == index) {
1361 sym.flags.@"export" = true;
1362 }
1363 }
1364 }
1365
1366 for (self.undefined_symbols.items) |index| {
1367 const sym = self.getSymbol(index);
1368 if (sym.getFile(self)) |file| {
1369 if (sym.visibility != .global) continue;
1370 if (file == .dylib and !sym.flags.abs) sym.flags.import = true;
1371 }
1372 }
1373
1374 for (&[_]?Symbol.Index{
1375 self.entry_index,
1376 self.dyld_stub_binder_index,
1377 self.objc_msg_send_index,
1378 }) |index| {
1379 if (index) |idx| {
1380 const sym = self.getSymbol(idx);
1381 if (sym.getFile(self)) |file| {
1382 if (file == .dylib) sym.flags.import = true;
1383 }
1384 }
1385 }
1386}
1387
1348fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void {1388fn shrinkAtom(self: *MachO, atom_index: Atom.Index, new_block_size: u64) void {
1349 _ = self;1389 _ = self;
1350 _ = atom_index;1390 _ = atom_index;