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 {...@@ -1536,7 +1536,7 @@ pub fn mergeSymbolVisibility(self: *Object, macho_file: *MachO) void {
1536 for (self.symbols.items, 0..) |sym, i| {1536 for (self.symbols.items, 0..) |sym, i| {
1537 const ref = self.getSymbolRef(@intCast(i), macho_file);1537 const ref = self.getSymbolRef(@intCast(i), macho_file);
1538 const global = ref.getSymbol(macho_file) orelse continue;1538 const global = ref.getSymbol(macho_file) orelse continue;
1539 if (global.visibility != .global) {1539 if (sym.visibility.rank() < global.visibility.rank()) {
1540 global.visibility = sym.visibility;1540 global.visibility = sym.visibility;
1541 }1541 }
1542 if (sym.flags.weak_ref) {1542 if (sym.flags.weak_ref) {
src/link/MachO/Symbol.zig+14-1
...@@ -331,9 +331,14 @@ fn format2(...@@ -331,9 +331,14 @@ fn format2(
331 if (symbol.getAtom(ctx.macho_file)) |atom| {331 if (symbol.getAtom(ctx.macho_file)) |atom| {
332 try writer.print(" : atom({d})", .{atom.atom_index});332 try writer.print(" : atom({d})", .{atom.atom_index});
333 }333 }
334 var buf: [2]u8 = .{'_'} ** 2;334 var buf: [3]u8 = .{'_'} ** 3;
335 if (symbol.flags.@"export") buf[0] = 'E';335 if (symbol.flags.@"export") buf[0] = 'E';
336 if (symbol.flags.import) buf[1] = 'I';336 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 }
337 try writer.print(" : {s}", .{&buf});342 try writer.print(" : {s}", .{&buf});
338 if (symbol.flags.weak) try writer.writeAll(" : weak");343 if (symbol.flags.weak) try writer.writeAll(" : weak");
339 if (symbol.isSymbolStab(ctx.macho_file)) try writer.writeAll(" : stab");344 if (symbol.isSymbolStab(ctx.macho_file)) try writer.writeAll(" : stab");
...@@ -402,6 +407,14 @@ pub const Visibility = enum {...@@ -402,6 +407,14 @@ pub const Visibility = enum {
402 global,407 global,
403 hidden,408 hidden,
404 local,409 local,
410
411 pub fn rank(vis: Visibility) u2 {
412 return switch (vis) {
413 .local => 2,
414 .hidden => 1,
415 .global => 0,
416 };
417 }
405};418};
406419
407pub const Extra = struct {420pub const Extra = struct {
src/link/MachO/ZigObject.zig+1-1
...@@ -267,7 +267,7 @@ pub fn mergeSymbolVisibility(self: *ZigObject, macho_file: *MachO) void {...@@ -267,7 +267,7 @@ pub fn mergeSymbolVisibility(self: *ZigObject, macho_file: *MachO) void {
267 for (self.symbols.items, 0..) |sym, i| {267 for (self.symbols.items, 0..) |sym, i| {
268 const ref = self.getSymbolRef(@intCast(i), macho_file);268 const ref = self.getSymbolRef(@intCast(i), macho_file);
269 const global = ref.getSymbol(macho_file) orelse continue;269 const global = ref.getSymbol(macho_file) orelse continue;
270 if (global.visibility != .global) {270 if (sym.visibility.rank() < global.visibility.rank()) {
271 global.visibility = sym.visibility;271 global.visibility = sym.visibility;
272 }272 }
273 if (sym.flags.weak_ref) {273 if (sym.flags.weak_ref) {