authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-11 14:49:16+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-18 09:13:08+02:00
log90c54f1eb6d34fb703b6c4e093580a0f2f70d559
tree7e0a3416b09d81f61ac95c539b6fa22165a53822
parent3d58faed12d018d70a4cd28aff89b733621a0259

macho: fix symbol visibility merging logic


3 files changed, 16 insertions(+), 3 deletions(-)

src/link/MachO/Object.zig+1-1
......@@ -1536,7 +1536,7 @@ pub fn mergeSymbolVisibility(self: *Object, macho_file: *MachO) void {
15361536 for (self.symbols.items, 0..) |sym, i| {
15371537 const ref = self.getSymbolRef(@intCast(i), macho_file);
15381538 const global = ref.getSymbol(macho_file) orelse continue;
1539 if (global.visibility != .global) {
1539 if (sym.visibility.rank() < global.visibility.rank()) {
15401540 global.visibility = sym.visibility;
15411541 }
15421542 if (sym.flags.weak_ref) {
src/link/MachO/Symbol.zig+14-1
......@@ -331,9 +331,14 @@ fn format2(
331331 if (symbol.getAtom(ctx.macho_file)) |atom| {
332332 try writer.print(" : atom({d})", .{atom.atom_index});
333333 }
334 var buf: [2]u8 = .{'_'} ** 2;
334 var buf: [3]u8 = .{'_'} ** 3;
335335 if (symbol.flags.@"export") buf[0] = 'E';
336336 if (symbol.flags.import) buf[1] = 'I';
337 switch (symbol.visibility) {
338 .local => buf[2] = 'L',
339 .hidden => buf[2] = 'H',
340 .global => buf[2] = 'G',
341 }
337342 try writer.print(" : {s}", .{&buf});
338343 if (symbol.flags.weak) try writer.writeAll(" : weak");
339344 if (symbol.isSymbolStab(ctx.macho_file)) try writer.writeAll(" : stab");
......@@ -402,6 +407,14 @@ pub const Visibility = enum {
402407 global,
403408 hidden,
404409 local,
410
411 pub fn rank(vis: Visibility) u2 {
412 return switch (vis) {
413 .local => 2,
414 .hidden => 1,
415 .global => 0,
416 };
417 }
405418};
406419
407420pub const Extra = struct {
src/link/MachO/ZigObject.zig+1-1
......@@ -267,7 +267,7 @@ pub fn mergeSymbolVisibility(self: *ZigObject, macho_file: *MachO) void {
267267 for (self.symbols.items, 0..) |sym, i| {
268268 const ref = self.getSymbolRef(@intCast(i), macho_file);
269269 const global = ref.getSymbol(macho_file) orelse continue;
270 if (global.visibility != .global) {
270 if (sym.visibility.rank() < global.visibility.rank()) {
271271 global.visibility = sym.visibility;
272272 }
273273 if (sym.flags.weak_ref) {