Skip to content

Commit

Permalink
macho: preserve exports in relocatable mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jan 1, 2024
1 parent ae2b4de commit 21ccb70
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/MachO/relocatable.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub fn flush(macho_file: *MachO) !void {
markExports(macho_file);
claimUnresolved(macho_file);
try initOutputSections(macho_file);
try macho_file.sortSections();
Expand Down Expand Up @@ -62,6 +63,19 @@ pub fn flush(macho_file: *MachO) !void {
try writeHeader(macho_file, ncmds, sizeofcmds);
}

fn markExports(macho_file: *MachO) void {
for (macho_file.objects.items) |index| {
for (macho_file.getFile(index).?.getSymbols()) |sym_index| {
const sym = macho_file.getSymbol(sym_index);
const file = sym.getFile(macho_file) orelse continue;
if (sym.visibility != .global) continue;
if (file.getIndex() == index) {
sym.flags.@"export" = true;
}
}
}
}

fn claimUnresolved(macho_file: *MachO) void {
for (macho_file.objects.items) |index| {
const object = macho_file.getFile(index).?.object;
Expand Down

0 comments on commit 21ccb70

Please sign in to comment.