diff --git a/src/MachO/relocatable.zig b/src/MachO/relocatable.zig index 7fe1e2b2..92354375 100644 --- a/src/MachO/relocatable.zig +++ b/src/MachO/relocatable.zig @@ -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(); @@ -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;