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