authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-10-19 10:55:00+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-10-22 07:59:23+02:00
log04a590a171c68570be1b2371617d747efbda7f1f
treedcd6a02cb13f27f16bbbca7c453690c7a6da6493
parentd57639a30802ac9b42d8528c466f7b3123dbc469

macho: remove unused nlist flags


2 files changed, 2 insertions(+), 19 deletions(-)

src/link/MachO.zig+2-17
...@@ -55,8 +55,6 @@ pub const SearchStrategy = enum {...@@ -55,8 +55,6 @@ pub const SearchStrategy = enum {
55 dylibs_first,55 dylibs_first,
56};56};
5757
58pub const N_DESC_GCED: u16 = @bitCast(u16, @as(i16, -1));
59
60const Section = struct {58const Section = struct {
61 header: macho.section_64,59 header: macho.section_64,
62 segment_index: u8,60 segment_index: u8,
...@@ -3602,7 +3600,6 @@ fn collectExportData(self: *MachO, trie: *Trie) !void {...@@ -3602,7 +3600,6 @@ fn collectExportData(self: *MachO, trie: *Trie) !void {
36023600
3603 if (sym.undf()) continue;3601 if (sym.undf()) continue;
3604 if (!sym.ext()) continue;3602 if (!sym.ext()) continue;
3605 if (sym.n_desc == N_DESC_GCED) continue;
36063603
3607 const sym_name = self.getSymbolName(global);3604 const sym_name = self.getSymbolName(global);
3608 log.debug(" (putting '{s}' defined at 0x{x})", .{ sym_name, sym.n_value });3605 log.debug(" (putting '{s}' defined at 0x{x})", .{ sym_name, sym.n_value });
...@@ -3850,7 +3847,6 @@ fn writeSymtab(self: *MachO, lc: *macho.symtab_command) !SymtabCtx {...@@ -3850,7 +3847,6 @@ fn writeSymtab(self: *MachO, lc: *macho.symtab_command) !SymtabCtx {
38503847
3851 for (self.locals.items) |sym, sym_id| {3848 for (self.locals.items) |sym, sym_id| {
3852 if (sym.n_strx == 0) continue; // no name, skip3849 if (sym.n_strx == 0) continue; // no name, skip
3853 if (sym.n_desc == N_DESC_GCED) continue; // GCed, skip
3854 const sym_loc = SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null };3850 const sym_loc = SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null };
3855 if (self.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip3851 if (self.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip
3856 if (self.getGlobal(self.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip3852 if (self.getGlobal(self.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip
...@@ -3863,7 +3859,6 @@ fn writeSymtab(self: *MachO, lc: *macho.symtab_command) !SymtabCtx {...@@ -3863,7 +3859,6 @@ fn writeSymtab(self: *MachO, lc: *macho.symtab_command) !SymtabCtx {
3863 for (self.globals.items) |global| {3859 for (self.globals.items) |global| {
3864 const sym = self.getSymbol(global);3860 const sym = self.getSymbol(global);
3865 if (sym.undf()) continue; // import, skip3861 if (sym.undf()) continue; // import, skip
3866 if (sym.n_desc == N_DESC_GCED) continue; // GCed, skip
3867 var out_sym = sym;3862 var out_sym = sym;
3868 out_sym.n_strx = try self.strtab.insert(gpa, self.getSymbolName(global));3863 out_sym.n_strx = try self.strtab.insert(gpa, self.getSymbolName(global));
3869 try exports.append(out_sym);3864 try exports.append(out_sym);
...@@ -3966,8 +3961,6 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx, lc: *macho.dysymtab_command) !voi...@@ -3966,8 +3961,6 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx, lc: *macho.dysymtab_command) !voi
3966 stubs.reserved1 = 0;3961 stubs.reserved1 = 0;
3967 for (self.stubs.items) |entry| {3962 for (self.stubs.items) |entry| {
3968 if (entry.sym_index == 0) continue;3963 if (entry.sym_index == 0) continue;
3969 const atom_sym = entry.getSymbol(self);
3970 if (atom_sym.n_desc == N_DESC_GCED) continue;
3971 const target_sym = self.getSymbol(entry.target);3964 const target_sym = self.getSymbol(entry.target);
3972 assert(target_sym.undf());3965 assert(target_sym.undf());
3973 try writer.writeIntLittle(u32, iundefsym + ctx.imports_table.get(entry.target).?);3966 try writer.writeIntLittle(u32, iundefsym + ctx.imports_table.get(entry.target).?);
...@@ -3979,8 +3972,6 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx, lc: *macho.dysymtab_command) !voi...@@ -3979,8 +3972,6 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx, lc: *macho.dysymtab_command) !voi
3979 got.reserved1 = nstubs;3972 got.reserved1 = nstubs;
3980 for (self.got_entries.items) |entry| {3973 for (self.got_entries.items) |entry| {
3981 if (entry.sym_index == 0) continue;3974 if (entry.sym_index == 0) continue;
3982 const atom_sym = entry.getSymbol(self);
3983 if (atom_sym.n_desc == N_DESC_GCED) continue;
3984 const target_sym = self.getSymbol(entry.target);3975 const target_sym = self.getSymbol(entry.target);
3985 if (target_sym.undf()) {3976 if (target_sym.undf()) {
3986 try writer.writeIntLittle(u32, iundefsym + ctx.imports_table.get(entry.target).?);3977 try writer.writeIntLittle(u32, iundefsym + ctx.imports_table.get(entry.target).?);
...@@ -3995,8 +3986,6 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx, lc: *macho.dysymtab_command) !voi...@@ -3995,8 +3986,6 @@ fn writeDysymtab(self: *MachO, ctx: SymtabCtx, lc: *macho.dysymtab_command) !voi
3995 la_symbol_ptr.reserved1 = nstubs + ngot_entries;3986 la_symbol_ptr.reserved1 = nstubs + ngot_entries;
3996 for (self.stubs.items) |entry| {3987 for (self.stubs.items) |entry| {
3997 if (entry.sym_index == 0) continue;3988 if (entry.sym_index == 0) continue;
3998 const atom_sym = entry.getSymbol(self);
3999 if (atom_sym.n_desc == N_DESC_GCED) continue;
4000 const target_sym = self.getSymbol(entry.target);3989 const target_sym = self.getSymbol(entry.target);
4001 assert(target_sym.undf());3990 assert(target_sym.undf());
4002 try writer.writeIntLittle(u32, iundefsym + ctx.imports_table.get(entry.target).?);3991 try writer.writeIntLittle(u32, iundefsym + ctx.imports_table.get(entry.target).?);
...@@ -4594,7 +4583,7 @@ pub fn logSections(self: *MachO) void {...@@ -4594,7 +4583,7 @@ pub fn logSections(self: *MachO) void {
4594 }4583 }
4595}4584}
45964585
4597fn logSymAttributes(sym: macho.nlist_64, buf: *[9]u8) []const u8 {4586fn logSymAttributes(sym: macho.nlist_64, buf: *[4]u8) []const u8 {
4598 mem.set(u8, buf[0..4], '_');4587 mem.set(u8, buf[0..4], '_');
4599 mem.set(u8, buf[4..], ' ');4588 mem.set(u8, buf[4..], ' ');
4600 if (sym.sect()) {4589 if (sym.sect()) {
...@@ -4613,14 +4602,11 @@ fn logSymAttributes(sym: macho.nlist_64, buf: *[9]u8) []const u8 {...@@ -4613,14 +4602,11 @@ fn logSymAttributes(sym: macho.nlist_64, buf: *[9]u8) []const u8 {
4613 if (sym.undf()) {4602 if (sym.undf()) {
4614 buf[3] = 'u';4603 buf[3] = 'u';
4615 }4604 }
4616 if (sym.n_desc == N_DESC_GCED) {
4617 mem.copy(u8, buf[5..], "DEAD");
4618 }
4619 return buf[0..];4605 return buf[0..];
4620}4606}
46214607
4622pub fn logSymtab(self: *MachO) void {4608pub fn logSymtab(self: *MachO) void {
4623 var buf: [9]u8 = undefined;4609 var buf: [4]u8 = undefined;
46244610
4625 log.debug("symtab:", .{});4611 log.debug("symtab:", .{});
4626 for (self.locals.items) |sym, sym_id| {4612 for (self.locals.items) |sym, sym_id| {
...@@ -4648,7 +4634,6 @@ pub fn logSymtab(self: *MachO) void {...@@ -4648,7 +4634,6 @@ pub fn logSymtab(self: *MachO) void {
4648 log.debug("GOT entries:", .{});4634 log.debug("GOT entries:", .{});
4649 for (self.got_entries.items) |entry, i| {4635 for (self.got_entries.items) |entry, i| {
4650 const atom_sym = entry.getSymbol(self);4636 const atom_sym = entry.getSymbol(self);
4651 if (atom_sym.n_desc == N_DESC_GCED) continue;
4652 const target_sym = self.getSymbol(entry.target);4637 const target_sym = self.getSymbol(entry.target);
4653 if (target_sym.undf()) {4638 if (target_sym.undf()) {
4654 log.debug(" {d}@{x} => import('{s}')", .{4639 log.debug(" {d}@{x} => import('{s}')", .{
src/link/MachO/DebugSymbols.zig-2
...@@ -477,7 +477,6 @@ fn writeSymtab(self: *DebugSymbols, lc: *macho.symtab_command) !void {...@@ -477,7 +477,6 @@ fn writeSymtab(self: *DebugSymbols, lc: *macho.symtab_command) !void {
477477
478 for (self.base.locals.items) |sym, sym_id| {478 for (self.base.locals.items) |sym, sym_id| {
479 if (sym.n_strx == 0) continue; // no name, skip479 if (sym.n_strx == 0) continue; // no name, skip
480 if (sym.n_desc == MachO.N_DESC_GCED) continue; // GCed, skip
481 const sym_loc = MachO.SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null };480 const sym_loc = MachO.SymbolWithLoc{ .sym_index = @intCast(u32, sym_id), .file = null };
482 if (self.base.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip481 if (self.base.symbolIsTemp(sym_loc)) continue; // local temp symbol, skip
483 if (self.base.getGlobal(self.base.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip482 if (self.base.getGlobal(self.base.getSymbolName(sym_loc)) != null) continue; // global symbol is either an export or import, skip
...@@ -492,7 +491,6 @@ fn writeSymtab(self: *DebugSymbols, lc: *macho.symtab_command) !void {...@@ -492,7 +491,6 @@ fn writeSymtab(self: *DebugSymbols, lc: *macho.symtab_command) !void {
492 for (self.base.globals.items) |global| {491 for (self.base.globals.items) |global| {
493 const sym = self.base.getSymbol(global);492 const sym = self.base.getSymbol(global);
494 if (sym.undf()) continue; // import, skip493 if (sym.undf()) continue; // import, skip
495 if (sym.n_desc == MachO.N_DESC_GCED) continue; // GCed, skip
496 var out_sym = sym;494 var out_sym = sym;
497 out_sym.n_strx = try self.strtab.insert(gpa, self.base.getSymbolName(global));495 out_sym.n_strx = try self.strtab.insert(gpa, self.base.getSymbolName(global));
498 try exports.append(out_sym);496 try exports.append(out_sym);