| ... | ... | @@ -2456,6 +2456,17 @@ pub const Zld = struct { |
| 2456 | 2456 | try self.writeStrtab(); |
| 2457 | 2457 | } |
| 2458 | 2458 | |
| 2459 | fn addLocalToSymtab(self: *Zld, sym_loc: SymbolWithLoc, locals: *std.ArrayList(macho.nlist_64)) !void { |
| 2460 | const sym = self.getSymbol(sym_loc); |
| 2461 | if (sym.n_strx == 0) return; // no name, skip |
| 2462 | if (sym.ext()) return; // an export lands in its own symtab section, skip |
| 2463 | if (self.symbolIsTemp(sym_loc)) return; // local temp symbol, skip |
| 2464 | |
| 2465 | var out_sym = sym; |
| 2466 | out_sym.n_strx = try self.strtab.insert(self.gpa, self.getSymbolName(sym_loc)); |
| 2467 | try locals.append(out_sym); |
| 2468 | } |
| 2469 | |
| 2459 | 2470 | fn writeSymtab(self: *Zld) !SymtabCtx { |
| 2460 | 2471 | const gpa = self.gpa; |
| 2461 | 2472 | |
| ... | ... | @@ -2466,14 +2477,12 @@ pub const Zld = struct { |
| 2466 | 2477 | for (object.atoms.items) |atom_index| { |
| 2467 | 2478 | const atom = self.getAtom(atom_index); |
| 2468 | 2479 | const sym_loc = atom.getSymbolWithLoc(); |
| 2469 | | const sym = self.getSymbol(sym_loc); |
| 2470 | | if (sym.n_strx == 0) continue; // no name, skip |
| 2471 | | if (sym.ext()) continue; // an export lands in its own symtab section, skip |
| 2472 | | if (self.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip |
| 2473 | | |
| 2474 | | var out_sym = sym; |
| 2475 | | out_sym.n_strx = try self.strtab.insert(gpa, self.getSymbolName(sym_loc)); |
| 2476 | | try locals.append(out_sym); |
| 2480 | try self.addLocalToSymtab(sym_loc, &locals); |
| 2481 | |
| 2482 | var it = Atom.getInnerSymbolsIterator(self, atom_index); |
| 2483 | while (it.next()) |inner_sym_loc| { |
| 2484 | try self.addLocalToSymtab(inner_sym_loc, &locals); |
| 2485 | } |
| 2477 | 2486 | } |
| 2478 | 2487 | } |
| 2479 | 2488 | |