authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-27 11:07:07+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-29 11:40:20+02:00
log9d62ebc0ce2c12e991f3016e71a8569e262c26c6
tree6df3de9755a95d062f84107474101c5d56d80e4c
parent2c68fb3d7ce077fba711747ee7b05b2fa0df6bcc

macho: fix compilation issues


3 files changed, 35 insertions(+), 32 deletions(-)

src/link/MachO.zig+14-15
......@@ -1455,7 +1455,7 @@ pub fn createTentativeDefAtoms(self: *MachO) !void {
14551455 }
14561456}
14571457
1458fn createDyldPrivateAtom(self: *MachO) !void {
1458pub fn createDyldPrivateAtom(self: *MachO) !void {
14591459 if (self.dyld_private_atom_index != null) return;
14601460
14611461 const sym_index = try self.allocateSymbol();
......@@ -2015,7 +2015,7 @@ fn growAtom(self: *MachO, atom_index: Atom.Index, new_atom_size: u64, alignment:
20152015 return self.allocateAtom(atom_index, new_atom_size, alignment);
20162016}
20172017
2018fn allocateSymbol(self: *MachO) !u32 {
2018pub fn allocateSymbol(self: *MachO) !u32 {
20192019 try self.locals.ensureUnusedCapacity(self.base.allocator, 1);
20202020
20212021 const index = blk: {
......@@ -2104,7 +2104,7 @@ pub fn addStubEntry(self: *MachO, target: SymbolWithLoc) !void {
21042104
21052105pub fn addTlvPtrEntry(self: *MachO, target: SymbolWithLoc) !void {
21062106 if (self.tlv_ptr_table.lookup.contains(target)) return;
2107 _ = try self.tlv_ptr_table.allocateEntry(self.gpa, target);
2107 _ = try self.tlv_ptr_table.allocateEntry(self.base.allocator, target);
21082108 if (self.tlv_ptr_section_index == null) {
21092109 self.tlv_ptr_section_index = try self.initSection("__DATA", "__thread_ptrs", .{
21102110 .flags = macho.S_THREAD_LOCAL_VARIABLE_POINTERS,
......@@ -3490,7 +3490,7 @@ fn collectRebaseData(self: *MachO, rebase: *Rebase) !void {
34903490 const offset = @as(u64, @intCast(base_offset + rel_offset));
34913491 log.debug(" | rebase at {x}", .{offset});
34923492
3493 try rebase.entries.append(self.gpa, .{
3493 try rebase.entries.append(gpa, .{
34943494 .offset = offset,
34953495 .segment_id = segment_id,
34963496 });
......@@ -3656,7 +3656,7 @@ fn collectBindData(self: *MachO, bind: anytype, raw_bindings: anytype) !void {
36563656 if (bind_sym.weakRef()) {
36573657 log.debug(" | marking as weak ref ", .{});
36583658 }
3659 try bind.entries.append(self.gpa, .{
3659 try bind.entries.append(gpa, .{
36603660 .target = global,
36613661 .offset = offset,
36623662 .segment_id = segment_id,
......@@ -4004,8 +4004,8 @@ fn writeSymtab(self: *MachO) !SymtabCtx {
40044004 var locals = std.ArrayList(macho.nlist_64).init(gpa);
40054005 defer locals.deinit();
40064006
4007 for (0..self.locals.items) |sym_id| {
4008 try self.addLocalToSymtab(.{ .sym_index = @intCast(sym_id) });
4007 for (0..self.locals.items.len) |sym_id| {
4008 try self.addLocalToSymtab(.{ .sym_index = @intCast(sym_id) }, &locals);
40094009 }
40104010
40114011 for (self.objects.items) |object| {
......@@ -4611,7 +4611,7 @@ pub fn makeStaticString(bytes: []const u8) [16]u8 {
46114611 return buf;
46124612}
46134613
4614fn getSegmentByName(self: MachO, segname: []const u8) ?u8 {
4614pub fn getSegmentByName(self: MachO, segname: []const u8) ?u8 {
46154615 for (self.segments.items, 0..) |seg, i| {
46164616 if (mem.eql(u8, segname, seg.segName())) return @as(u8, @intCast(i));
46174617 } else return null;
......@@ -5024,7 +5024,7 @@ pub fn logSymtab(self: *MachO) void {
50245024 scoped_log.debug("{}", .{self.tlv_ptr_table});
50255025
50265026 scoped_log.debug("stubs entries:", .{});
5027 scoped_log.debug("{}", .{self.stubs_table});
5027 scoped_log.debug("{}", .{self.stub_table});
50285028
50295029 scoped_log.debug("thunks:", .{});
50305030 for (self.thunks.items, 0..) |thunk, i| {
......@@ -5151,7 +5151,7 @@ const Cache = std.Build.Cache;
51515151const CodeSignature = @import("MachO/CodeSignature.zig");
51525152const Compilation = @import("../Compilation.zig");
51535153const Dwarf = File.Dwarf;
5154const DwarfInfo = @import("DwarfInfo.zig");
5154const DwarfInfo = @import("MachO/DwarfInfo.zig");
51555155const Dylib = @import("MachO/Dylib.zig");
51565156const File = link.File;
51575157const Object = @import("MachO/Object.zig");
......@@ -5170,10 +5170,9 @@ const TypedValue = @import("../TypedValue.zig");
51705170const Value = @import("../value.zig").Value;
51715171
51725172pub const DebugSymbols = @import("MachO/DebugSymbols.zig");
5173
5174const Bind = @import("MachO/dyld_info/bind.zig").Bind(*const MachO, SymbolWithLoc);
5175const LazyBind = @import("MachO/dyld_info/bind.zig").LazyBind(*const MachO, SymbolWithLoc);
5176const Rebase = @import("MachO/dyld_info/Rebase.zig");
5173pub const Bind = @import("MachO/dyld_info/bind.zig").Bind(*const MachO, SymbolWithLoc);
5174pub const LazyBind = @import("MachO/dyld_info/bind.zig").LazyBind(*const MachO, SymbolWithLoc);
5175pub const Rebase = @import("MachO/dyld_info/Rebase.zig");
51775176
51785177pub const base_tag: File.Tag = File.Tag.macho;
51795178pub const N_DEAD: u16 = @as(u16, @bitCast(@as(i16, -1)));
......@@ -5257,7 +5256,7 @@ const UnnamedConstTable = std.AutoArrayHashMapUnmanaged(Module.Decl.Index, std.A
52575256const RebaseTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(u32));
52585257const RelocationTable = std.AutoArrayHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(Relocation));
52595258
5260const ResolveAction = struct {
5259pub const ResolveAction = struct {
52615260 kind: Kind,
52625261 target: SymbolWithLoc,
52635262
src/link/MachO/dead_strip.zig+7-6
......@@ -36,11 +36,12 @@ fn collectRoots(macho_file: *MachO, roots: *AtomTable) !void {
3636 switch (macho_file.base.options.output_mode) {
3737 .Exe => {
3838 // Add entrypoint as GC root
39 const global: SymbolWithLoc = macho_file.getEntryPoint();
40 if (global.getFile()) |file| {
41 try addRoot(macho_file, roots, file, global);
42 } else {
43 assert(macho_file.getSymbol(global).undf()); // Stub as our entrypoint is in a dylib.
39 if (macho_file.getEntryPoint()) |global| {
40 if (global.getFile()) |file| {
41 try addRoot(macho_file, roots, file, global);
42 } else {
43 assert(macho_file.getSymbol(global).undf()); // Stub as our entrypoint is in a dylib.
44 }
4445 }
4546 },
4647 else => |other| {
......@@ -116,7 +117,7 @@ fn markLive(macho_file: *MachO, atom_index: Atom.Index, alive: *AtomTable) void
116117
117118 alive.putAssumeCapacityNoClobber(atom_index, {});
118119
119 const cpu_arch = macho_file.options.target.cpu.arch;
120 const cpu_arch = macho_file.base.options.target.cpu.arch;
120121
121122 const sym = macho_file.getSymbol(atom.getSymbolWithLoc());
122123 const header = macho_file.sections.items(.header)[sym.n_sect - 1];
src/link/MachO/zld.zig+14-11
......@@ -401,7 +401,7 @@ pub fn linkWithZld(
401401 try macho_file.createDyldPrivateAtom();
402402 try macho_file.createTentativeDefAtoms();
403403
404 if (macho_file.options.output_mode == .Exe) {
404 if (macho_file.base.options.output_mode == .Exe) {
405405 const global = macho_file.getEntryPoint().?;
406406 if (macho_file.getSymbol(global).undf()) {
407407 // We do one additional check here in case the entry point was found in one of the dylibs.
......@@ -429,7 +429,7 @@ pub fn linkWithZld(
429429 if (macho_file.dyld_stub_binder_index) |index|
430430 try macho_file.addGotEntry(macho_file.globals.items[index]);
431431
432 try macho_file.calcSectionSizes();
432 try calcSectionSizes(macho_file);
433433
434434 var unwind_info = UnwindInfo{ .gpa = gpa };
435435 defer unwind_info.deinit();
......@@ -461,9 +461,9 @@ pub fn linkWithZld(
461461 try writeLaSymbolPtrs(macho_file);
462462 }
463463 if (macho_file.got_section_index) |sect_id|
464 try macho_file.writePointerEntries(sect_id, &macho_file.got_table);
464 try writePointerEntries(macho_file, sect_id, &macho_file.got_table);
465465 if (macho_file.tlv_ptr_section_index) |sect_id|
466 try macho_file.writePointerEntries(sect_id, &macho_file.tlv_ptr_table);
466 try writePointerEntries(macho_file, sect_id, &macho_file.tlv_ptr_table);
467467
468468 try eh_frame.write(macho_file, &unwind_info);
469469 try unwind_info.write(macho_file);
......@@ -546,11 +546,11 @@ pub fn linkWithZld(
546546 else => {},
547547 }
548548
549 try load_commands.writeRpathLCs(gpa, macho_file.base.options, lc_writer);
549 try load_commands.writeRpathLCs(gpa, &macho_file.base.options, lc_writer);
550550 try lc_writer.writeStruct(macho.source_version_command{
551551 .version = 0,
552552 });
553 try load_commands.writeBuildVersionLC(macho_file.base.options, lc_writer);
553 try load_commands.writeBuildVersionLC(&macho_file.base.options, lc_writer);
554554
555555 const uuid_cmd_offset = @sizeOf(macho.mach_header_64) + @as(u32, @intCast(lc_buffer.items.len));
556556 try lc_writer.writeStruct(macho_file.uuid_cmd);
......@@ -1053,11 +1053,14 @@ fn allocateSegments(macho_file: *MachO) !void {
10531053 const gpa = macho_file.base.allocator;
10541054 for (macho_file.segments.items, 0..) |*segment, segment_index| {
10551055 const is_text_segment = mem.eql(u8, segment.segName(), "__TEXT");
1056 const base_size = if (is_text_segment) try load_commands.calcMinHeaderPad(gpa, macho_file.base.options, .{
1057 .segments = macho_file.segments.items,
1058 .dylibs = macho_file.dylibs.items,
1059 .referenced_dylibs = macho_file.referenced_dylibs.keys(),
1060 }) else 0;
1056 const base_size = if (is_text_segment)
1057 try load_commands.calcMinHeaderPad(gpa, &macho_file.base.options, .{
1058 .segments = macho_file.segments.items,
1059 .dylibs = macho_file.dylibs.items,
1060 .referenced_dylibs = macho_file.referenced_dylibs.keys(),
1061 })
1062 else
1063 0;
10611064 try allocateSegment(macho_file, @as(u8, @intCast(segment_index)), base_size);
10621065 }
10631066}