authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-12-06 00:09:51+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-12-06 00:09:51+01:00
log71d19318e78b6126561f630333bb47edca5fb7bd
tree12fc89be7d44592919d179e1c6e0ab46c28e74e2
parent3ac973c7068f540fa46c0939d3c4bb712b407d37

macho: do not preserve temp symbol names

and do not write out local symbol in MachO's symbol table if global symbol exists with the same name.

1 files changed, 5 insertions(+), 3 deletions(-)

src/link/MachO.zig+5-3
......@@ -2584,12 +2584,11 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void {
25842584 return error.UnhandledSymbolType;
25852585 }
25862586
2587 const n_strx = try self.makeString(sym_name);
25882587 if (sym.sect()) {
25892588 // Defined symbol regardless of scope lands in the locals symbol table.
25902589 const local_sym_index = @intCast(u32, self.locals.items.len);
25912590 try self.locals.append(self.base.allocator, .{
2592 .n_strx = n_strx,
2591 .n_strx = if (symbolIsTemp(sym, sym_name)) 0 else try self.makeString(sym_name),
25932592 .n_type = macho.N_SECT,
25942593 .n_sect = 0,
25952594 .n_desc = 0,
......@@ -2602,6 +2601,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void {
26022601 // if we should save the symbol as a global, or potentially flag the error.
26032602 if (!sym.ext()) continue;
26042603
2604 const n_strx = try self.makeString(sym_name);
26052605 const local = self.locals.items[local_sym_index];
26062606 const resolv = self.symbol_resolver.getPtr(n_strx) orelse {
26072607 const global_sym_index = @intCast(u32, self.globals.items.len);
......@@ -2672,6 +2672,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void {
26722672 };
26732673 } else if (sym.tentative()) {
26742674 // Symbol is a tentative definition.
2675 const n_strx = try self.makeString(sym_name);
26752676 const resolv = self.symbol_resolver.getPtr(n_strx) orelse {
26762677 const global_sym_index = @intCast(u32, self.globals.items.len);
26772678 try self.globals.append(self.base.allocator, .{
......@@ -2729,6 +2730,7 @@ fn resolveSymbolsInObject(self: *MachO, object_id: u16) !void {
27292730 }
27302731 } else {
27312732 // Symbol is undefined.
2733 const n_strx = try self.makeString(sym_name);
27322734 if (self.symbol_resolver.contains(n_strx)) continue;
27332735
27342736 const undef_sym_index = @intCast(u32, self.undefs.items.len);
......@@ -5394,7 +5396,7 @@ fn writeSymbolTable(self: *MachO) !void {
53945396
53955397 for (self.locals.items) |sym| {
53965398 if (sym.n_strx == 0) continue;
5397 if (symbolIsTemp(sym, self.getString(sym.n_strx))) continue;
5399 if (self.symbol_resolver.get(sym.n_strx)) |_| continue;
53985400 try locals.append(sym);
53995401 }
54005402