authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-02 19:48:23+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-08-02 19:49:32+02:00
log41d7787b69a437e21351d103353fc2eefafb5d17
tree4998363492bd09a1b25a83685c5cc3a6c0e115f9
parentbf25650974933cdb8c1314a85e0838257f6f4471

macho: remove obsolete pack/unpack dylib ordinal fns

Remove some unused debugging machinery such as full printing of the symtab after symbol resolution. It was there only for the time of rewriting the linker.

1 files changed, 9 insertions(+), 85 deletions(-)

src/link/MachO.zig+9-85
......@@ -970,7 +970,6 @@ fn linkWithZld(self: *MachO, comp: *Compilation) !void {
970970 try self.allocateDataSegment();
971971 self.allocateLinkeditSegment();
972972 try self.allocateTextBlocks();
973 self.printSymtabAndTextBlock();
974973 try self.flushZld();
975974 }
976975
......@@ -2345,7 +2344,7 @@ fn resolveSymbols(self: *MachO) !void {
23452344 .n_strx = undef.n_strx,
23462345 .n_type = macho.N_UNDF | macho.N_EXT,
23472346 .n_sect = 0,
2348 .n_desc = packDylibOrdinal(@intCast(u16, ordinal + 1)),
2347 .n_desc = @intCast(u16, ordinal + 1) * macho.N_SYMBOL_RESOLVER,
23492348 .n_value = 0,
23502349 });
23512350 resolv.* = .{
......@@ -3021,7 +3020,7 @@ fn writeBindInfoTableZld(self: *MachO) !void {
30213020 try pointers.append(.{
30223021 .offset = base_offset + i * @sizeOf(u64),
30233022 .segment_id = segment_id,
3024 .dylib_ordinal = unpackDylibOrdinal(sym.n_desc),
3023 .dylib_ordinal = @divExact(sym.n_desc, macho.N_SYMBOL_RESOLVER),
30253024 .name = self.getString(sym.n_strx),
30263025 });
30273026 }
......@@ -3046,7 +3045,7 @@ fn writeBindInfoTableZld(self: *MachO) !void {
30463045 try pointers.append(.{
30473046 .offset = binding.offset + base_offset,
30483047 .segment_id = match.seg,
3049 .dylib_ordinal = unpackDylibOrdinal(bind_sym.n_desc),
3048 .dylib_ordinal = @divExact(bind_sym.n_desc, macho.N_SYMBOL_RESOLVER),
30503049 .name = self.getString(bind_sym.n_strx),
30513050 });
30523051 }
......@@ -3093,7 +3092,7 @@ fn writeLazyBindInfoTableZld(self: *MachO) !void {
30933092 pointers.appendAssumeCapacity(.{
30943093 .offset = base_offset + i * @sizeOf(u64),
30953094 .segment_id = segment_id,
3096 .dylib_ordinal = unpackDylibOrdinal(sym.n_desc),
3095 .dylib_ordinal = @divExact(sym.n_desc, macho.N_SYMBOL_RESOLVER),
30973096 .name = self.getString(sym.n_strx),
30983097 });
30993098 }
......@@ -4395,7 +4394,7 @@ pub fn populateMissingMetadata(self: *MachO) !void {
43954394 .n_strx = n_strx,
43964395 .n_type = macho.N_UNDF | macho.N_EXT,
43974396 .n_sect = 0,
4398 .n_desc = packDylibOrdinal(1),
4397 .n_desc = @intCast(u8, 1) * macho.N_SYMBOL_RESOLVER,
43994398 .n_value = 0,
44004399 });
44014400 try self.symbol_resolver.putNoClobber(self.base.allocator, n_strx, .{
......@@ -4541,7 +4540,7 @@ pub fn addExternFn(self: *MachO, name: []const u8) !u32 {
45414540 .n_strx = n_strx,
45424541 .n_type = macho.N_UNDF | macho.N_EXT,
45434542 .n_sect = 0,
4544 .n_desc = packDylibOrdinal(1),
4543 .n_desc = @intCast(u8, 1) * macho.N_SYMBOL_RESOLVER,
45454544 .n_value = 0,
45464545 });
45474546 try self.symbol_resolver.putNoClobber(self.base.allocator, n_strx, .{
......@@ -5423,7 +5422,7 @@ fn writeBindInfoTable(self: *MachO) !void {
54235422 try pointers.append(.{
54245423 .offset = base_offset + i * @sizeOf(u64),
54255424 .segment_id = segment_id,
5426 .dylib_ordinal = unpackDylibOrdinal(sym.n_desc),
5425 .dylib_ordinal = @divExact(sym.n_desc, macho.N_SYMBOL_RESOLVER),
54275426 .name = self.getString(sym.n_strx),
54285427 });
54295428 }
......@@ -5448,7 +5447,7 @@ fn writeBindInfoTable(self: *MachO) !void {
54485447 try pointers.append(.{
54495448 .offset = binding.offset + base_offset,
54505449 .segment_id = match.seg,
5451 .dylib_ordinal = unpackDylibOrdinal(bind_sym.n_desc),
5450 .dylib_ordinal = @divExact(bind_sym.n_desc, macho.N_SYMBOL_RESOLVER),
54525451 .name = self.getString(bind_sym.n_strx),
54535452 });
54545453 }
......@@ -5507,7 +5506,7 @@ fn writeLazyBindInfoTable(self: *MachO) !void {
55075506 pointers.appendAssumeCapacity(.{
55085507 .offset = base_offset + i * @sizeOf(u64),
55095508 .segment_id = segment_id,
5510 .dylib_ordinal = unpackDylibOrdinal(sym.n_desc),
5509 .dylib_ordinal = @divExact(sym.n_desc, macho.N_SYMBOL_RESOLVER),
55115510 .name = self.getString(sym.n_strx),
55125511 });
55135512 }
......@@ -5849,14 +5848,6 @@ pub fn symbolIsTemp(sym: macho.nlist_64, sym_name: []const u8) bool {
58495848 return mem.startsWith(u8, sym_name, "l") or mem.startsWith(u8, sym_name, "L");
58505849}
58515850
5852fn packDylibOrdinal(ordinal: u16) u16 {
5853 return ordinal * macho.N_SYMBOL_RESOLVER;
5854}
5855
5856fn unpackDylibOrdinal(pack: u16) u16 {
5857 return @divExact(pack, macho.N_SYMBOL_RESOLVER);
5858}
5859
58605851pub fn findFirst(comptime T: type, haystack: []T, start: usize, predicate: anytype) usize {
58615852 if (!@hasDecl(@TypeOf(predicate), "predicate"))
58625853 @compileError("Predicate is required to define fn predicate(@This(), T) bool");
......@@ -5869,70 +5860,3 @@ pub fn findFirst(comptime T: type, haystack: []T, start: usize, predicate: anyty
58695860 }
58705861 return i;
58715862}
5872
5873fn printSymtabAndTextBlock(self: *MachO) void {
5874 log.debug("locals", .{});
5875 for (self.locals.items) |sym, id| {
5876 log.debug(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym });
5877 }
5878
5879 log.debug("globals", .{});
5880 for (self.globals.items) |sym, id| {
5881 log.debug(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym });
5882 }
5883
5884 log.debug("tentatives", .{});
5885 for (self.tentatives.items) |sym, id| {
5886 log.debug(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym });
5887 }
5888
5889 log.debug("undefines", .{});
5890 for (self.undefs.items) |sym, id| {
5891 log.debug(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym });
5892 }
5893
5894 log.debug("imports", .{});
5895 for (self.imports.items) |sym, id| {
5896 log.debug(" {d}: {s}, {}", .{ id, self.getString(sym.n_strx), sym });
5897 }
5898
5899 {
5900 log.debug("symbol resolver", .{});
5901 var it = self.symbol_resolver.keyIterator();
5902 while (it.next()) |key_ptr| {
5903 const sym_name = self.getString(key_ptr.*);
5904 log.debug(" {s} => {}", .{ sym_name, self.symbol_resolver.get(key_ptr.*).? });
5905 }
5906 }
5907
5908 log.debug("mappings", .{});
5909 for (self.objects.items) |object| {
5910 log.debug(" in object {s}", .{object.name});
5911 for (object.symtab.items) |sym, sym_id| {
5912 if (object.symbol_mapping.get(@intCast(u32, sym_id))) |local_id| {
5913 log.debug(" | {d} => {d}", .{ sym_id, local_id });
5914 } else {
5915 log.debug(" | {d} no local mapping for {s}", .{ sym_id, object.getString(sym.n_strx) });
5916 }
5917 }
5918 }
5919
5920 {
5921 var it = self.blocks.iterator();
5922 while (it.next()) |entry| {
5923 const seg = self.load_commands.items[entry.key_ptr.seg].Segment;
5924 const sect = seg.sections.items[entry.key_ptr.sect];
5925
5926 var block: *TextBlock = entry.value_ptr.*;
5927
5928 log.debug("\n\n{s},{s} contents:", .{ commands.segmentName(sect), commands.sectionName(sect) });
5929 log.debug("{}", .{sect});
5930 log.debug("{}", .{block});
5931
5932 while (block.prev) |prev| {
5933 block = prev;
5934 log.debug("{}", .{block});
5935 }
5936 }
5937 }
5938}