authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-16 22:25:50+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-17 12:10:39+01:00
log3019676440c5ea30be8a9a185fb1346622f7cbdb
tree35da96326b92fdec09219f49a252f59488c18d5e
parentf76bd56588e556ea580c1faa63667cc9264cc218

macho: apply some renames to bring closer to zld


3 files changed, 86 insertions(+), 85 deletions(-)

src/codegen.zig+4-3
......@@ -2152,8 +2152,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
21522152 const decl = func_payload.data;
21532153 const decl_name = try std.fmt.allocPrint(self.bin_file.allocator, "_{s}", .{decl.name});
21542154 defer self.bin_file.allocator.free(decl_name);
2155 const already_defined = macho_file.extern_lazy_symbols.contains(decl_name);
2156 const symbol: u32 = if (macho_file.extern_lazy_symbols.getIndex(decl_name)) |index|
2155 const already_defined = macho_file.lazy_imports.contains(decl_name);
2156 const symbol: u32 = if (macho_file.lazy_imports.getIndex(decl_name)) |index|
21572157 @intCast(u32, index)
21582158 else
21592159 try macho_file.addExternSymbol(decl_name);
......@@ -3111,7 +3111,8 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
31113111 4, 8 => {
31123112 const offset = if (math.cast(i9, adj_off)) |imm|
31133113 Instruction.LoadStoreOffset.imm_post_index(-imm)
3114 else |_| Instruction.LoadStoreOffset.reg(try self.copyToTmpRegister(src, Type.initTag(.u64), MCValue{ .immediate = adj_off }));
3114 else |_|
3115 Instruction.LoadStoreOffset.reg(try self.copyToTmpRegister(src, Type.initTag(.u64), MCValue{ .immediate = adj_off }));
31153116 const rn: Register = switch (arch) {
31163117 .aarch64, .aarch64_be => .x29,
31173118 .aarch64_32 => .w29,
src/link/MachO.zig+78-78
......@@ -104,16 +104,16 @@ entry_addr: ?u64 = null,
104104
105105/// Table of all local symbols
106106/// Internally references string table for names (which are optional).
107local_symbols: std.ArrayListUnmanaged(macho.nlist_64) = .{},
107locals: std.ArrayListUnmanaged(macho.nlist_64) = .{},
108108/// Table of all global symbols
109global_symbols: std.ArrayListUnmanaged(macho.nlist_64) = .{},
109globals: std.ArrayListUnmanaged(macho.nlist_64) = .{},
110110/// Table of all extern nonlazy symbols, indexed by name.
111extern_nonlazy_symbols: std.StringArrayHashMapUnmanaged(ExternSymbol) = .{},
111nonlazy_imports: std.StringArrayHashMapUnmanaged(ExternSymbol) = .{},
112112/// Table of all extern lazy symbols, indexed by name.
113extern_lazy_symbols: std.StringArrayHashMapUnmanaged(ExternSymbol) = .{},
113lazy_imports: std.StringArrayHashMapUnmanaged(ExternSymbol) = .{},
114114
115local_symbol_free_list: std.ArrayListUnmanaged(u32) = .{},
116global_symbol_free_list: std.ArrayListUnmanaged(u32) = .{},
115locals_free_list: std.ArrayListUnmanaged(u32) = .{},
116globals_free_list: std.ArrayListUnmanaged(u32) = .{},
117117offset_table_free_list: std.ArrayListUnmanaged(u32) = .{},
118118
119119stub_helper_stubs_start_off: ?u64 = null,
......@@ -260,9 +260,9 @@ pub const TextBlock = struct {
260260 /// File offset relocation happens transparently, so it is not included in
261261 /// this calculation.
262262 fn capacity(self: TextBlock, macho_file: MachO) u64 {
263 const self_sym = macho_file.local_symbols.items[self.local_sym_index];
263 const self_sym = macho_file.locals.items[self.local_sym_index];
264264 if (self.next) |next| {
265 const next_sym = macho_file.local_symbols.items[next.local_sym_index];
265 const next_sym = macho_file.locals.items[next.local_sym_index];
266266 return next_sym.n_value - self_sym.n_value;
267267 } else {
268268 // We are the last block.
......@@ -274,8 +274,8 @@ pub const TextBlock = struct {
274274 fn freeListEligible(self: TextBlock, macho_file: MachO) bool {
275275 // No need to keep a free list node for the last block.
276276 const next = self.next orelse return false;
277 const self_sym = macho_file.local_symbols.items[self.local_sym_index];
278 const next_sym = macho_file.local_symbols.items[next.local_sym_index];
277 const self_sym = macho_file.locals.items[self.local_sym_index];
278 const next_sym = macho_file.locals.items[next.local_sym_index];
279279 const cap = next_sym.n_value - self_sym.n_value;
280280 const ideal_cap = padToIdeal(self.size);
281281 if (cap <= ideal_cap) return false;
......@@ -344,7 +344,7 @@ pub fn openPath(allocator: *Allocator, sub_path: []const u8, options: link.Optio
344344 };
345345
346346 // Index 0 is always a null symbol.
347 try self.local_symbols.append(allocator, .{
347 try self.locals.append(allocator, .{
348348 .n_strx = 0,
349349 .n_type = 0,
350350 .n_sect = 0,
......@@ -834,7 +834,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
834834 }
835835 },
836836 else => {
837 log.err("{s} terminated", .{ argv.items[0] });
837 log.err("{s} terminated", .{argv.items[0]});
838838 return error.LLDCrashed;
839839 },
840840 }
......@@ -1019,14 +1019,14 @@ pub fn deinit(self: *MachO) void {
10191019 if (self.d_sym) |*ds| {
10201020 ds.deinit(self.base.allocator);
10211021 }
1022 for (self.extern_lazy_symbols.items()) |*entry| {
1022 for (self.lazy_imports.items()) |*entry| {
10231023 self.base.allocator.free(entry.key);
10241024 }
1025 self.extern_lazy_symbols.deinit(self.base.allocator);
1026 for (self.extern_nonlazy_symbols.items()) |*entry| {
1025 self.lazy_imports.deinit(self.base.allocator);
1026 for (self.nonlazy_imports.items()) |*entry| {
10271027 self.base.allocator.free(entry.key);
10281028 }
1029 self.extern_nonlazy_symbols.deinit(self.base.allocator);
1029 self.nonlazy_imports.deinit(self.base.allocator);
10301030 self.pie_fixups.deinit(self.base.allocator);
10311031 self.stub_fixups.deinit(self.base.allocator);
10321032 self.text_block_free_list.deinit(self.base.allocator);
......@@ -1040,10 +1040,10 @@ pub fn deinit(self: *MachO) void {
10401040 }
10411041 self.string_table_directory.deinit(self.base.allocator);
10421042 self.string_table.deinit(self.base.allocator);
1043 self.global_symbols.deinit(self.base.allocator);
1044 self.global_symbol_free_list.deinit(self.base.allocator);
1045 self.local_symbols.deinit(self.base.allocator);
1046 self.local_symbol_free_list.deinit(self.base.allocator);
1043 self.globals.deinit(self.base.allocator);
1044 self.globals_free_list.deinit(self.base.allocator);
1045 self.locals.deinit(self.base.allocator);
1046 self.locals_free_list.deinit(self.base.allocator);
10471047 for (self.load_commands.items) |*lc| {
10481048 lc.deinit(self.base.allocator);
10491049 }
......@@ -1098,7 +1098,7 @@ fn shrinkTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64) vo
10981098}
10991099
11001100fn growTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64, alignment: u64) !u64 {
1101 const sym = self.local_symbols.items[text_block.local_sym_index];
1101 const sym = self.locals.items[text_block.local_sym_index];
11021102 const align_ok = mem.alignBackwardGeneric(u64, sym.n_value, alignment) == sym.n_value;
11031103 const need_realloc = !align_ok or new_block_size > text_block.capacity(self.*);
11041104 if (!need_realloc) return sym.n_value;
......@@ -1108,16 +1108,16 @@ fn growTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64, alig
11081108pub fn allocateDeclIndexes(self: *MachO, decl: *Module.Decl) !void {
11091109 if (decl.link.macho.local_sym_index != 0) return;
11101110
1111 try self.local_symbols.ensureCapacity(self.base.allocator, self.local_symbols.items.len + 1);
1111 try self.locals.ensureCapacity(self.base.allocator, self.locals.items.len + 1);
11121112 try self.offset_table.ensureCapacity(self.base.allocator, self.offset_table.items.len + 1);
11131113
1114 if (self.local_symbol_free_list.popOrNull()) |i| {
1114 if (self.locals_free_list.popOrNull()) |i| {
11151115 log.debug("reusing symbol index {d} for {s}", .{ i, decl.name });
11161116 decl.link.macho.local_sym_index = i;
11171117 } else {
1118 log.debug("allocating symbol index {d} for {s}", .{ self.local_symbols.items.len, decl.name });
1119 decl.link.macho.local_sym_index = @intCast(u32, self.local_symbols.items.len);
1120 _ = self.local_symbols.addOneAssumeCapacity();
1118 log.debug("allocating symbol index {d} for {s}", .{ self.locals.items.len, decl.name });
1119 decl.link.macho.local_sym_index = @intCast(u32, self.locals.items.len);
1120 _ = self.locals.addOneAssumeCapacity();
11211121 }
11221122
11231123 if (self.offset_table_free_list.popOrNull()) |i| {
......@@ -1128,7 +1128,7 @@ pub fn allocateDeclIndexes(self: *MachO, decl: *Module.Decl) !void {
11281128 self.offset_table_count_dirty = true;
11291129 }
11301130
1131 self.local_symbols.items[decl.link.macho.local_sym_index] = .{
1131 self.locals.items[decl.link.macho.local_sym_index] = .{
11321132 .n_strx = 0,
11331133 .n_type = 0,
11341134 .n_sect = 0,
......@@ -1189,7 +1189,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
11891189
11901190 const required_alignment = typed_value.ty.abiAlignment(self.base.options.target);
11911191 assert(decl.link.macho.local_sym_index != 0); // Caller forgot to call allocateDeclIndexes()
1192 const symbol = &self.local_symbols.items[decl.link.macho.local_sym_index];
1192 const symbol = &self.locals.items[decl.link.macho.local_sym_index];
11931193
11941194 if (decl.link.macho.size != 0) {
11951195 const capacity = decl.link.macho.capacity(self.*);
......@@ -1285,7 +1285,7 @@ pub fn updateDecl(self: *MachO, module: *Module, decl: *Module.Decl) !void {
12851285 try self.writeStubInStubHelper(fixup.symbol);
12861286 try self.writeLazySymbolPointer(fixup.symbol);
12871287
1288 const extern_sym = &self.extern_lazy_symbols.items()[fixup.symbol].value;
1288 const extern_sym = &self.lazy_imports.items()[fixup.symbol].value;
12891289 extern_sym.segment = self.data_segment_cmd_index.?;
12901290 extern_sym.offset = fixup.symbol * @sizeOf(u64);
12911291 self.rebase_info_dirty = true;
......@@ -1329,9 +1329,9 @@ pub fn updateDeclExports(
13291329 const tracy = trace(@src());
13301330 defer tracy.end();
13311331
1332 try self.global_symbols.ensureCapacity(self.base.allocator, self.global_symbols.items.len + exports.len);
1332 try self.globals.ensureCapacity(self.base.allocator, self.globals.items.len + exports.len);
13331333 if (decl.link.macho.local_sym_index == 0) return;
1334 const decl_sym = &self.local_symbols.items[decl.link.macho.local_sym_index];
1334 const decl_sym = &self.locals.items[decl.link.macho.local_sym_index];
13351335
13361336 for (exports) |exp| {
13371337 if (exp.options.section) |section_name| {
......@@ -1364,7 +1364,7 @@ pub fn updateDeclExports(
13641364 };
13651365 const n_type = decl_sym.n_type | macho.N_EXT;
13661366 if (exp.link.macho.sym_index) |i| {
1367 const sym = &self.global_symbols.items[i];
1367 const sym = &self.globals.items[i];
13681368 sym.* = .{
13691369 .n_strx = try self.updateString(sym.n_strx, exp.options.name),
13701370 .n_type = n_type,
......@@ -1374,12 +1374,12 @@ pub fn updateDeclExports(
13741374 };
13751375 } else {
13761376 const name_str_index = try self.makeString(exp.options.name);
1377 const i = if (self.global_symbol_free_list.popOrNull()) |i| i else blk: {
1378 _ = self.global_symbols.addOneAssumeCapacity();
1377 const i = if (self.globals_free_list.popOrNull()) |i| i else blk: {
1378 _ = self.globals.addOneAssumeCapacity();
13791379 self.export_info_dirty = true;
1380 break :blk self.global_symbols.items.len - 1;
1380 break :blk self.globals.items.len - 1;
13811381 };
1382 self.global_symbols.items[i] = .{
1382 self.globals.items[i] = .{
13831383 .n_strx = name_str_index,
13841384 .n_type = n_type,
13851385 .n_sect = @intCast(u8, self.text_section_index.?) + 1,
......@@ -1394,18 +1394,18 @@ pub fn updateDeclExports(
13941394
13951395pub fn deleteExport(self: *MachO, exp: Export) void {
13961396 const sym_index = exp.sym_index orelse return;
1397 self.global_symbol_free_list.append(self.base.allocator, sym_index) catch {};
1398 self.global_symbols.items[sym_index].n_type = 0;
1397 self.globals_free_list.append(self.base.allocator, sym_index) catch {};
1398 self.globals.items[sym_index].n_type = 0;
13991399}
14001400
14011401pub fn freeDecl(self: *MachO, decl: *Module.Decl) void {
14021402 // Appending to free lists is allowed to fail because the free lists are heuristics based anyway.
14031403 self.freeTextBlock(&decl.link.macho);
14041404 if (decl.link.macho.local_sym_index != 0) {
1405 self.local_symbol_free_list.append(self.base.allocator, decl.link.macho.local_sym_index) catch {};
1405 self.locals_free_list.append(self.base.allocator, decl.link.macho.local_sym_index) catch {};
14061406 self.offset_table_free_list.append(self.base.allocator, decl.link.macho.offset_table_index) catch {};
14071407
1408 self.local_symbols.items[decl.link.macho.local_sym_index].n_type = 0;
1408 self.locals.items[decl.link.macho.local_sym_index].n_type = 0;
14091409
14101410 decl.link.macho.local_sym_index = 0;
14111411 }
......@@ -1413,7 +1413,7 @@ pub fn freeDecl(self: *MachO, decl: *Module.Decl) void {
14131413
14141414pub fn getDeclVAddr(self: *MachO, decl: *const Module.Decl) u64 {
14151415 assert(decl.link.macho.local_sym_index != 0);
1416 return self.local_symbols.items[decl.link.macho.local_sym_index].n_value;
1416 return self.locals.items[decl.link.macho.local_sym_index].n_value;
14171417}
14181418
14191419pub fn populateMissingMetadata(self: *MachO) !void {
......@@ -2060,11 +2060,11 @@ pub fn populateMissingMetadata(self: *MachO) !void {
20602060 self.header_dirty = true;
20612061 self.load_commands_dirty = true;
20622062 }
2063 if (!self.extern_nonlazy_symbols.contains("dyld_stub_binder")) {
2064 const index = @intCast(u32, self.extern_nonlazy_symbols.items().len);
2063 if (!self.nonlazy_imports.contains("dyld_stub_binder")) {
2064 const index = @intCast(u32, self.nonlazy_imports.items().len);
20652065 const name = try self.base.allocator.dupe(u8, "dyld_stub_binder");
20662066 const offset = try self.makeString("dyld_stub_binder");
2067 try self.extern_nonlazy_symbols.putNoClobber(self.base.allocator, name, .{
2067 try self.nonlazy_imports.putNoClobber(self.base.allocator, name, .{
20682068 .inner = .{
20692069 .n_strx = offset,
20702070 .n_type = std.macho.N_UNDF | std.macho.N_EXT,
......@@ -2159,7 +2159,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
21592159 const big_block = self.text_block_free_list.items[i];
21602160 // We now have a pointer to a live text block that has too much capacity.
21612161 // Is it enough that we could fit this new text block?
2162 const sym = self.local_symbols.items[big_block.local_sym_index];
2162 const sym = self.locals.items[big_block.local_sym_index];
21632163 const capacity = big_block.capacity(self.*);
21642164 const ideal_capacity = padToIdeal(capacity);
21652165 const ideal_capacity_end_vaddr = sym.n_value + ideal_capacity;
......@@ -2190,7 +2190,7 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
21902190 }
21912191 break :blk new_start_vaddr;
21922192 } else if (self.last_text_block) |last| {
2193 const last_symbol = self.local_symbols.items[last.local_sym_index];
2193 const last_symbol = self.locals.items[last.local_sym_index];
21942194 // TODO We should pad out the excess capacity with NOPs. For executables,
21952195 // no padding seems to be OK, but it will probably not be for objects.
21962196 const ideal_capacity = padToIdeal(last.size);
......@@ -2288,11 +2288,11 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 {
22882288}
22892289
22902290pub fn addExternSymbol(self: *MachO, name: []const u8) !u32 {
2291 const index = @intCast(u32, self.extern_lazy_symbols.items().len);
2291 const index = @intCast(u32, self.lazy_imports.items().len);
22922292 const offset = try self.makeString(name);
22932293 const sym_name = try self.base.allocator.dupe(u8, name);
22942294 const dylib_ordinal = 1; // TODO this is now hardcoded, since we only support libSystem.
2295 try self.extern_lazy_symbols.putNoClobber(self.base.allocator, sym_name, .{
2295 try self.lazy_imports.putNoClobber(self.base.allocator, sym_name, .{
22962296 .inner = .{
22972297 .n_strx = offset,
22982298 .n_type = macho.N_UNDF | macho.N_EXT,
......@@ -2591,9 +2591,9 @@ fn writeStubInStubHelper(self: *MachO, index: u32) !void {
25912591
25922592fn relocateSymbolTable(self: *MachO) !void {
25932593 const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab;
2594 const nlocals = self.local_symbols.items.len;
2595 const nglobals = self.global_symbols.items.len;
2596 const nundefs = self.extern_lazy_symbols.items().len + self.extern_nonlazy_symbols.items().len;
2594 const nlocals = self.locals.items.len;
2595 const nglobals = self.globals.items.len;
2596 const nundefs = self.lazy_imports.items().len + self.nonlazy_imports.items().len;
25972597 const nsyms = nlocals + nglobals + nundefs;
25982598
25992599 if (symtab.nsyms < nsyms) {
......@@ -2628,7 +2628,7 @@ fn writeLocalSymbol(self: *MachO, index: usize) !void {
26282628 const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab;
26292629 const off = symtab.symoff + @sizeOf(macho.nlist_64) * index;
26302630 log.debug("writing local symbol {} at 0x{x}", .{ index, off });
2631 try self.base.file.?.pwriteAll(mem.asBytes(&self.local_symbols.items[index]), off);
2631 try self.base.file.?.pwriteAll(mem.asBytes(&self.locals.items[index]), off);
26322632}
26332633
26342634fn writeAllGlobalAndUndefSymbols(self: *MachO) !void {
......@@ -2637,17 +2637,17 @@ fn writeAllGlobalAndUndefSymbols(self: *MachO) !void {
26372637
26382638 try self.relocateSymbolTable();
26392639 const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab;
2640 const nlocals = self.local_symbols.items.len;
2641 const nglobals = self.global_symbols.items.len;
2640 const nlocals = self.locals.items.len;
2641 const nglobals = self.globals.items.len;
26422642
2643 const nundefs = self.extern_lazy_symbols.items().len + self.extern_nonlazy_symbols.items().len;
2643 const nundefs = self.lazy_imports.items().len + self.nonlazy_imports.items().len;
26442644 var undefs = std.ArrayList(macho.nlist_64).init(self.base.allocator);
26452645 defer undefs.deinit();
26462646 try undefs.ensureCapacity(nundefs);
2647 for (self.extern_lazy_symbols.items()) |entry| {
2647 for (self.lazy_imports.items()) |entry| {
26482648 undefs.appendAssumeCapacity(entry.value.inner);
26492649 }
2650 for (self.extern_nonlazy_symbols.items()) |entry| {
2650 for (self.nonlazy_imports.items()) |entry| {
26512651 undefs.appendAssumeCapacity(entry.value.inner);
26522652 }
26532653
......@@ -2657,7 +2657,7 @@ fn writeAllGlobalAndUndefSymbols(self: *MachO) !void {
26572657 const globals_off = locals_off + locals_size;
26582658 const globals_size = nglobals * @sizeOf(macho.nlist_64);
26592659 log.debug("writing global symbols from 0x{x} to 0x{x}", .{ globals_off, globals_size + globals_off });
2660 try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.global_symbols.items), globals_off);
2660 try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.globals.items), globals_off);
26612661
26622662 const undefs_off = globals_off + globals_size;
26632663 const undefs_size = nundefs * @sizeOf(macho.nlist_64);
......@@ -2688,8 +2688,8 @@ fn writeIndirectSymbolTable(self: *MachO) !void {
26882688 const la_symbol_ptr = &data_segment.sections.items[self.la_symbol_ptr_section_index.?];
26892689 const dysymtab = &self.load_commands.items[self.dysymtab_cmd_index.?].Dysymtab;
26902690
2691 const lazy = self.extern_lazy_symbols.items();
2692 const nonlazy = self.extern_nonlazy_symbols.items();
2691 const lazy = self.lazy_imports.items();
2692 const nonlazy = self.nonlazy_imports.items();
26932693 const allocated_size = self.allocatedSizeLinkedit(dysymtab.indirectsymoff);
26942694 const nindirectsyms = @intCast(u32, lazy.len * 2 + nonlazy.len);
26952695 const needed_size = @intCast(u32, nindirectsyms * @sizeOf(u32));
......@@ -2710,20 +2710,20 @@ fn writeIndirectSymbolTable(self: *MachO) !void {
27102710 var writer = stream.writer();
27112711
27122712 stubs.reserved1 = 0;
2713 for (self.extern_lazy_symbols.items()) |_, i| {
2713 for (self.lazy_imports.items()) |_, i| {
27142714 const symtab_idx = @intCast(u32, dysymtab.iundefsym + i);
27152715 try writer.writeIntLittle(u32, symtab_idx);
27162716 }
27172717
27182718 const base_id = @intCast(u32, lazy.len);
27192719 got.reserved1 = base_id;
2720 for (self.extern_nonlazy_symbols.items()) |_, i| {
2720 for (self.nonlazy_imports.items()) |_, i| {
27212721 const symtab_idx = @intCast(u32, dysymtab.iundefsym + i + base_id);
27222722 try writer.writeIntLittle(u32, symtab_idx);
27232723 }
27242724
27252725 la_symbol_ptr.reserved1 = got.reserved1 + @intCast(u32, nonlazy.len);
2726 for (self.extern_lazy_symbols.items()) |_, i| {
2726 for (self.lazy_imports.items()) |_, i| {
27272727 const symtab_idx = @intCast(u32, dysymtab.iundefsym + i);
27282728 try writer.writeIntLittle(u32, symtab_idx);
27292729 }
......@@ -2789,7 +2789,7 @@ fn writeCodeSignature(self: *MachO) !void {
27892789
27902790fn writeExportTrie(self: *MachO) !void {
27912791 if (!self.export_info_dirty) return;
2792 if (self.global_symbols.items.len == 0) return;
2792 if (self.globals.items.len == 0) return;
27932793
27942794 const tracy = trace(@src());
27952795 defer tracy.end();
......@@ -2798,7 +2798,7 @@ fn writeExportTrie(self: *MachO) !void {
27982798 defer trie.deinit();
27992799
28002800 const text_segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
2801 for (self.global_symbols.items) |symbol| {
2801 for (self.globals.items) |symbol| {
28022802 // TODO figure out if we should put all global symbols into the export trie
28032803 const name = self.getString(symbol.n_strx);
28042804 assert(symbol.n_value >= text_segment.inner.vmaddr);
......@@ -2840,12 +2840,12 @@ fn writeRebaseInfoTable(self: *MachO) !void {
28402840 const tracy = trace(@src());
28412841 defer tracy.end();
28422842
2843 const size = try rebaseInfoSize(self.extern_lazy_symbols.items());
2843 const size = try rebaseInfoSize(self.lazy_imports.items());
28442844 var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
28452845 defer self.base.allocator.free(buffer);
28462846
28472847 var stream = std.io.fixedBufferStream(buffer);
2848 try writeRebaseInfo(self.extern_lazy_symbols.items(), stream.writer());
2848 try writeRebaseInfo(self.lazy_imports.items(), stream.writer());
28492849
28502850 const linkedit_segment = &self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
28512851 const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfoOnly;
......@@ -2872,12 +2872,12 @@ fn writeBindingInfoTable(self: *MachO) !void {
28722872 const tracy = trace(@src());
28732873 defer tracy.end();
28742874
2875 const size = try bindInfoSize(self.extern_nonlazy_symbols.items());
2875 const size = try bindInfoSize(self.nonlazy_imports.items());
28762876 var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
28772877 defer self.base.allocator.free(buffer);
28782878
28792879 var stream = std.io.fixedBufferStream(buffer);
2880 try writeBindInfo(self.extern_nonlazy_symbols.items(), stream.writer());
2880 try writeBindInfo(self.nonlazy_imports.items(), stream.writer());
28812881
28822882 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
28832883 const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfoOnly;
......@@ -2901,12 +2901,12 @@ fn writeBindingInfoTable(self: *MachO) !void {
29012901fn writeLazyBindingInfoTable(self: *MachO) !void {
29022902 if (!self.lazy_binding_info_dirty) return;
29032903
2904 const size = try lazyBindInfoSize(self.extern_lazy_symbols.items());
2904 const size = try lazyBindInfoSize(self.lazy_imports.items());
29052905 var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
29062906 defer self.base.allocator.free(buffer);
29072907
29082908 var stream = std.io.fixedBufferStream(buffer);
2909 try writeLazyBindInfo(self.extern_lazy_symbols.items(), stream.writer());
2909 try writeLazyBindInfo(self.lazy_imports.items(), stream.writer());
29102910
29112911 const linkedit_segment = self.load_commands.items[self.linkedit_segment_cmd_index.?].Segment;
29122912 const dyld_info = &self.load_commands.items[self.dyld_info_cmd_index.?].DyldInfoOnly;
......@@ -2929,7 +2929,7 @@ fn writeLazyBindingInfoTable(self: *MachO) !void {
29292929}
29302930
29312931fn populateLazyBindOffsetsInStubHelper(self: *MachO, buffer: []const u8) !void {
2932 if (self.extern_lazy_symbols.items().len == 0) return;
2932 if (self.lazy_imports.items().len == 0) return;
29332933
29342934 var stream = std.io.fixedBufferStream(buffer);
29352935 var reader = stream.reader();
......@@ -2975,7 +2975,7 @@ fn populateLazyBindOffsetsInStubHelper(self: *MachO, buffer: []const u8) !void {
29752975 else => {},
29762976 }
29772977 }
2978 assert(self.extern_lazy_symbols.items().len <= offsets.items.len);
2978 assert(self.lazy_imports.items().len <= offsets.items.len);
29792979
29802980 const stub_size: u4 = switch (self.base.options.target.cpu.arch) {
29812981 .x86_64 => 10,
......@@ -2988,7 +2988,7 @@ fn populateLazyBindOffsetsInStubHelper(self: *MachO, buffer: []const u8) !void {
29882988 else => unreachable,
29892989 };
29902990 var buf: [@sizeOf(u32)]u8 = undefined;
2991 for (self.extern_lazy_symbols.items()) |_, i| {
2991 for (self.lazy_imports.items()) |_, i| {
29922992 const placeholder_off = self.stub_helper_stubs_start_off.? + i * stub_size + off;
29932993 mem.writeIntLittle(u32, &buf, offsets.items[i]);
29942994 try self.base.file.?.pwriteAll(&buf, placeholder_off);
......@@ -3193,12 +3193,12 @@ fn parseSymbolTable(self: *MachO) !void {
31933193 const nread = try self.base.file.?.preadAll(@ptrCast([*]u8, buffer)[0 .. symtab.nsyms * @sizeOf(macho.nlist_64)], symtab.symoff);
31943194 assert(@divExact(nread, @sizeOf(macho.nlist_64)) == buffer.len);
31953195
3196 try self.local_symbols.ensureCapacity(self.base.allocator, dysymtab.nlocalsym);
3197 try self.global_symbols.ensureCapacity(self.base.allocator, dysymtab.nextdefsym);
3196 try self.locals.ensureCapacity(self.base.allocator, dysymtab.nlocalsym);
3197 try self.globals.ensureCapacity(self.base.allocator, dysymtab.nextdefsym);
31983198 try self.undef_symbols.ensureCapacity(self.base.allocator, dysymtab.nundefsym);
31993199
3200 self.local_symbols.appendSliceAssumeCapacity(buffer[dysymtab.ilocalsym .. dysymtab.ilocalsym + dysymtab.nlocalsym]);
3201 self.global_symbols.appendSliceAssumeCapacity(buffer[dysymtab.iextdefsym .. dysymtab.iextdefsym + dysymtab.nextdefsym]);
3200 self.locals.appendSliceAssumeCapacity(buffer[dysymtab.ilocalsym .. dysymtab.ilocalsym + dysymtab.nlocalsym]);
3201 self.globals.appendSliceAssumeCapacity(buffer[dysymtab.iextdefsym .. dysymtab.iextdefsym + dysymtab.nextdefsym]);
32023202 self.undef_symbols.appendSliceAssumeCapacity(buffer[dysymtab.iundefsym .. dysymtab.iundefsym + dysymtab.nundefsym]);
32033203}
32043204
src/link/MachO/DebugSymbols.zig+4-4
......@@ -839,8 +839,8 @@ fn findFreeSpaceLinkedit(self: *DebugSymbols, object_size: u64, min_alignment: u
839839
840840fn relocateSymbolTable(self: *DebugSymbols) !void {
841841 const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab;
842 const nlocals = self.base.local_symbols.items.len;
843 const nglobals = self.base.global_symbols.items.len;
842 const nlocals = self.base.locals.items.len;
843 const nglobals = self.base.globals.items.len;
844844 const nsyms = nlocals + nglobals;
845845
846846 if (symtab.nsyms < nsyms) {
......@@ -875,7 +875,7 @@ pub fn writeLocalSymbol(self: *DebugSymbols, index: usize) !void {
875875 const symtab = &self.load_commands.items[self.symtab_cmd_index.?].Symtab;
876876 const off = symtab.symoff + @sizeOf(macho.nlist_64) * index;
877877 log.debug("writing dSym local symbol {} at 0x{x}", .{ index, off });
878 try self.file.pwriteAll(mem.asBytes(&self.base.local_symbols.items[index]), off);
878 try self.file.pwriteAll(mem.asBytes(&self.base.locals.items[index]), off);
879879}
880880
881881fn writeStringTable(self: *DebugSymbols) !void {
......@@ -1057,7 +1057,7 @@ pub fn commitDeclDebugInfo(
10571057 var dbg_info_buffer = &debug_buffers.dbg_info_buffer;
10581058 var dbg_info_type_relocs = &debug_buffers.dbg_info_type_relocs;
10591059
1060 const symbol = self.base.local_symbols.items[decl.link.macho.local_sym_index];
1060 const symbol = self.base.locals.items[decl.link.macho.local_sym_index];
10611061 const text_block = &decl.link.macho;
10621062 // If the Decl is a function, we need to update the __debug_line program.
10631063 const typed_value = decl.typed_value.most_recent.typed_value;