| ... | ... | @@ -185,7 +185,7 @@ pub fn parse(self: *Object, macho_file: *MachO) !void { |
| 185 | 185 | if (name[0] == 'l' or name[0] == 'L') return 4; |
| 186 | 186 | return 3; |
| 187 | 187 | } |
| 188 | | return if (nl.weakDef()) 2 else 1; |
| 188 | return if (nl.n_desc.weak_def_or_ref_to_weak) 2 else 1; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | fn lessThan(ctx: *const Object, lhs: @This(), rhs: @This()) bool { |
| ... | ... | @@ -202,7 +202,7 @@ pub fn parse(self: *Object, macho_file: *MachO) !void { |
| 202 | 202 | var nlists = try std.array_list.Managed(NlistIdx).initCapacity(gpa, self.symtab.items(.nlist).len); |
| 203 | 203 | defer nlists.deinit(); |
| 204 | 204 | for (self.symtab.items(.nlist), 0..) |nlist, i| { |
| 205 | | if (nlist.stab() or !nlist.sect()) continue; |
| 205 | if (nlist.n_type.bits.is_stab != 0 or nlist.n_type.type != .sect) continue; |
| 206 | 206 | nlists.appendAssumeCapacity(.{ .nlist = nlist, .idx = i }); |
| 207 | 207 | } |
| 208 | 208 | mem.sort(NlistIdx, nlists.items, self, NlistIdx.lessThan); |
| ... | ... | @@ -805,7 +805,7 @@ fn linkNlistToAtom(self: *Object, macho_file: *MachO) !void { |
| 805 | 805 | const tracy = trace(@src()); |
| 806 | 806 | defer tracy.end(); |
| 807 | 807 | for (self.symtab.items(.nlist), self.symtab.items(.atom)) |nlist, *atom| { |
| 808 | | if (!nlist.stab() and nlist.sect()) { |
| 808 | if (!nlist.n_type.bits.is_stab != 0 and nlist.n_type.type == .sect) { |
| 809 | 809 | const sect = self.sections.items(.header)[nlist.n_sect - 1]; |
| 810 | 810 | const subs = self.sections.items(.subsections)[nlist.n_sect - 1].items; |
| 811 | 811 | if (nlist.n_value == sect.addr) { |
| ... | ... | @@ -852,30 +852,30 @@ fn initSymbols(self: *Object, allocator: Allocator, macho_file: *MachO) !void { |
| 852 | 852 | symbol.extra = self.addSymbolExtraAssumeCapacity(.{}); |
| 853 | 853 | |
| 854 | 854 | if (self.getAtom(atom_index)) |atom| { |
| 855 | | assert(!nlist.abs()); |
| 855 | assert(nlist.n_type.type != .abs); |
| 856 | 856 | symbol.value -= atom.getInputAddress(macho_file); |
| 857 | 857 | symbol.atom_ref = .{ .index = atom_index, .file = self.index }; |
| 858 | 858 | } |
| 859 | 859 | |
| 860 | | symbol.flags.weak = nlist.weakDef(); |
| 861 | | symbol.flags.abs = nlist.abs(); |
| 860 | symbol.flags.weak = nlist.n_desc.weak_def_or_ref_to_weak; |
| 861 | symbol.flags.abs = nlist.n_type.type == .abs; |
| 862 | 862 | symbol.flags.tentative = nlist.tentative(); |
| 863 | | symbol.flags.no_dead_strip = symbol.flags.no_dead_strip or nlist.noDeadStrip(); |
| 863 | symbol.flags.no_dead_strip = symbol.flags.no_dead_strip or nlist.n_desc.discarded_or_no_dead_strip; |
| 864 | 864 | symbol.flags.dyn_ref = nlist.n_desc & macho.REFERENCED_DYNAMICALLY != 0; |
| 865 | 865 | symbol.flags.interposable = false; |
| 866 | 866 | // TODO |
| 867 | | // symbol.flags.interposable = nlist.ext() and (nlist.sect() or nlist.abs()) and macho_file.base.isDynLib() and macho_file.options.namespace == .flat and !nlist.pext(); |
| 867 | // symbol.flags.interposable = nlist.ext() and (nlist.n_type.type == .sect or nlist.n_type.type == .abs) and macho_file.base.isDynLib() and macho_file.options.namespace == .flat and !nlist.pext(); |
| 868 | 868 | |
| 869 | | if (nlist.sect() and |
| 869 | if (nlist.n_type.type == .sect and |
| 870 | 870 | self.sections.items(.header)[nlist.n_sect - 1].type() == macho.S_THREAD_LOCAL_VARIABLES) |
| 871 | 871 | { |
| 872 | 872 | symbol.flags.tlv = true; |
| 873 | 873 | } |
| 874 | 874 | |
| 875 | 875 | if (nlist.ext()) { |
| 876 | | if (nlist.undf()) { |
| 877 | | symbol.flags.weak_ref = nlist.weakRef(); |
| 878 | | } else if (nlist.pext() or (nlist.weakDef() and nlist.weakRef()) or self.hidden) { |
| 876 | if (nlist.n_type.type == .undf) { |
| 877 | symbol.flags.weak_ref = nlist.n_desc.weak_ref; |
| 878 | } else if (nlist.pext() or (nlist.n_desc.weak_def_or_ref_to_weak and nlist.n_desc.weak_ref) or self.hidden) { |
| 879 | 879 | symbol.visibility = .hidden; |
| 880 | 880 | } else { |
| 881 | 881 | symbol.visibility = .global; |
| ... | ... | @@ -902,10 +902,10 @@ fn initSymbolStabs(self: *Object, allocator: Allocator, nlists: anytype, macho_f |
| 902 | 902 | }; |
| 903 | 903 | |
| 904 | 904 | const start: u32 = for (self.symtab.items(.nlist), 0..) |nlist, i| { |
| 905 | | if (nlist.stab()) break @intCast(i); |
| 905 | if (nlist.n_type.bits.is_stab != 0) break @intCast(i); |
| 906 | 906 | } else @intCast(self.symtab.items(.nlist).len); |
| 907 | 907 | const end: u32 = for (self.symtab.items(.nlist)[start..], start..) |nlist, i| { |
| 908 | | if (!nlist.stab()) break @intCast(i); |
| 908 | if (nlist.n_type.bits.is_stab == 0) break @intCast(i); |
| 909 | 909 | } else @intCast(self.symtab.items(.nlist).len); |
| 910 | 910 | |
| 911 | 911 | if (start == end) return; |
| ... | ... | @@ -919,7 +919,7 @@ fn initSymbolStabs(self: *Object, allocator: Allocator, nlists: anytype, macho_f |
| 919 | 919 | var addr_lookup = std.StringHashMap(u64).init(allocator); |
| 920 | 920 | defer addr_lookup.deinit(); |
| 921 | 921 | for (syms) |sym| { |
| 922 | | if (sym.sect() and (sym.ext() or sym.pext())) { |
| 922 | if (sym.n_type.type == .sect and (sym.ext() or sym.pext())) { |
| 923 | 923 | try addr_lookup.putNoClobber(self.getNStrx(sym.n_strx), sym.n_value); |
| 924 | 924 | } |
| 925 | 925 | } |
| ... | ... | @@ -1241,8 +1241,8 @@ fn parseUnwindRecords(self: *Object, allocator: Allocator, cpu_arch: std.Target. |
| 1241 | 1241 | |
| 1242 | 1242 | const slice = self.symtab.slice(); |
| 1243 | 1243 | for (slice.items(.nlist), slice.items(.atom), slice.items(.size)) |nlist, atom, size| { |
| 1244 | | if (nlist.stab()) continue; |
| 1245 | | if (!nlist.sect()) continue; |
| 1244 | if (nlist.n_type.bits.is_stab != 0) continue; |
| 1245 | if (nlist.n_type.type != .sect) continue; |
| 1246 | 1246 | const sect = self.sections.items(.header)[nlist.n_sect - 1]; |
| 1247 | 1247 | if (sect.isCode() and sect.size > 0) { |
| 1248 | 1248 | try superposition.ensureUnusedCapacity(1); |
| ... | ... | @@ -1459,7 +1459,7 @@ pub fn resolveSymbols(self: *Object, macho_file: *MachO) !void { |
| 1459 | 1459 | |
| 1460 | 1460 | for (self.symtab.items(.nlist), self.symtab.items(.atom), self.globals.items, 0..) |nlist, atom_index, *global, i| { |
| 1461 | 1461 | if (!nlist.ext()) continue; |
| 1462 | | if (nlist.sect()) { |
| 1462 | if (nlist.n_type.type == .sect) { |
| 1463 | 1463 | const atom = self.getAtom(atom_index).?; |
| 1464 | 1464 | if (!atom.isAlive()) continue; |
| 1465 | 1465 | } |
| ... | ... | @@ -1473,7 +1473,7 @@ pub fn resolveSymbols(self: *Object, macho_file: *MachO) !void { |
| 1473 | 1473 | } |
| 1474 | 1474 | global.* = gop.index; |
| 1475 | 1475 | |
| 1476 | | if (nlist.undf() and !nlist.tentative()) continue; |
| 1476 | if (nlist.n_type.type == .undf and !nlist.tentative()) continue; |
| 1477 | 1477 | if (gop.ref.getFile(macho_file) == null) { |
| 1478 | 1478 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; |
| 1479 | 1479 | continue; |
| ... | ... | @@ -1481,7 +1481,7 @@ pub fn resolveSymbols(self: *Object, macho_file: *MachO) !void { |
| 1481 | 1481 | |
| 1482 | 1482 | if (self.asFile().getSymbolRank(.{ |
| 1483 | 1483 | .archive = !self.alive, |
| 1484 | | .weak = nlist.weakDef(), |
| 1484 | .weak = nlist.n_desc.weak_def_or_ref_to_weak, |
| 1485 | 1485 | .tentative = nlist.tentative(), |
| 1486 | 1486 | }) < gop.ref.getSymbol(macho_file).?.getSymbolRank(macho_file)) { |
| 1487 | 1487 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; |
| ... | ... | @@ -1500,7 +1500,7 @@ pub fn markLive(self: *Object, macho_file: *MachO) void { |
| 1500 | 1500 | const ref = self.getSymbolRef(@intCast(i), macho_file); |
| 1501 | 1501 | const file = ref.getFile(macho_file) orelse continue; |
| 1502 | 1502 | const sym = ref.getSymbol(macho_file).?; |
| 1503 | | const should_keep = nlist.undf() or (nlist.tentative() and !sym.flags.tentative); |
| 1503 | const should_keep = nlist.n_type.type == .undf or (nlist.tentative() and !sym.flags.tentative); |
| 1504 | 1504 | if (should_keep and file == .object and !file.object.alive) { |
| 1505 | 1505 | file.object.alive = true; |
| 1506 | 1506 | file.object.markLive(macho_file); |
| ... | ... | @@ -1685,7 +1685,7 @@ pub fn parseAr(self: *Object, macho_file: *MachO) !void { |
| 1685 | 1685 | pub fn updateArSymtab(self: Object, ar_symtab: *Archive.ArSymtab, macho_file: *MachO) error{OutOfMemory}!void { |
| 1686 | 1686 | const gpa = macho_file.base.comp.gpa; |
| 1687 | 1687 | for (self.symtab.items(.nlist)) |nlist| { |
| 1688 | | if (!nlist.ext() or (nlist.undf() and !nlist.tentative())) continue; |
| 1688 | if (!nlist.ext() or (nlist.n_type.type == .undf and !nlist.tentative())) continue; |
| 1689 | 1689 | const off = try ar_symtab.strtab.insert(gpa, self.getNStrx(nlist.n_strx)); |
| 1690 | 1690 | try ar_symtab.entries.append(gpa, .{ .off = off, .file = self.index }); |
| 1691 | 1691 | } |