diff --git a/src/link/MachO.zig b/src/link/MachO.zig index a00c156b35..ee0eb9533c 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -356,7 +356,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n if (comp.verbose_link) try self.dumpArgv(comp); if (self.getZigObject()) |zo| try zo.flushModule(self, tid); - // if (self.base.isStaticLib()) return relocatable.flushStaticLib(self, comp, module_obj_path); + if (self.base.isStaticLib()) return relocatable.flushStaticLib(self, comp, module_obj_path); // if (self.base.isObject()) return relocatable.flushObject(self, comp, module_obj_path); var positionals = std.ArrayList(Compilation.LinkObject).init(gpa); diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index fe99df22bd..d6f4d903ea 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -77,6 +77,8 @@ pub fn parse(self: *Object, macho_file: *MachO) !void { const tracy = trace(@src()); defer tracy.end(); + log.debug("parsing {}", .{self.fmtPath()}); + const gpa = macho_file.base.comp.gpa; const handle = macho_file.getFileHandle(self.file_handle); const cpu_arch = macho_file.getTarget().cpu.arch; diff --git a/src/link/MachO/Relocation.zig b/src/link/MachO/Relocation.zig index 390e543ea9..bfb551f224 100644 --- a/src/link/MachO/Relocation.zig +++ b/src/link/MachO/Relocation.zig @@ -41,7 +41,7 @@ pub fn getGotTargetAddress(rel: Relocation, atom: Atom, macho_file: *MachO) u64 } pub fn getZigGotTargetAddress(rel: Relocation, macho_file: *MachO) u64 { - const zo = macho_file.getZigObject().?; + const zo = macho_file.getZigObject() orelse return 0; return switch (rel.tag) { .local => 0, .@"extern" => { diff --git a/src/link/MachO/file.zig b/src/link/MachO/file.zig index c1558292f5..5f52d6eb49 100644 --- a/src/link/MachO/file.zig +++ b/src/link/MachO/file.zig @@ -205,6 +205,8 @@ pub const File = union(enum) { pub fn updateArSymtab(file: File, ar_symtab: *Archive.ArSymtab, macho_file: *MachO) error{OutOfMemory}!void { return switch (file) { .dylib, .internal => unreachable, + // TODO + .zig_object => unreachable, inline else => |x| x.updateArSymtab(ar_symtab, macho_file), }; } @@ -212,7 +214,9 @@ pub const File = union(enum) { pub fn updateArSize(file: File, macho_file: *MachO) !void { return switch (file) { .dylib, .internal => unreachable, - .zig_object => |x| x.updateArSize(), + // TODO + .zig_object => unreachable, + // .zig_object => |x| x.updateArSize(), .object => |x| x.updateArSize(macho_file), }; } @@ -220,7 +224,9 @@ pub const File = union(enum) { pub fn writeAr(file: File, ar_format: Archive.Format, macho_file: *MachO, writer: anytype) !void { return switch (file) { .dylib, .internal => unreachable, - .zig_object => |x| x.writeAr(ar_format, writer), + // TODO + .zig_object => unreachable, + // .zig_object => |x| x.writeAr(ar_format, writer), .object => |x| x.writeAr(ar_format, macho_file, writer), }; } diff --git a/src/link/MachO/relocatable.zig b/src/link/MachO/relocatable.zig index a2979eafe0..516b9a1c46 100644 --- a/src/link/MachO/relocatable.zig +++ b/src/link/MachO/relocatable.zig @@ -127,55 +127,56 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ? if (comp.link_errors.items.len > 0) return error.FlushFailure; - // First, we flush relocatable object file generated with our backends. - if (macho_file.getZigObject()) |zo| { - zo.resolveSymbols(macho_file); - zo.asFile().markExportsRelocatable(macho_file); - zo.asFile().claimUnresolvedRelocatable(macho_file); - try macho_file.sortSections(); - try macho_file.addAtomsToSections(); - try calcSectionSizes(macho_file); - try createSegment(macho_file); - try allocateSections(macho_file); - allocateSegment(macho_file); + // TODO re-enable + // // First, we flush relocatable object file generated with our backends. + // if (macho_file.getZigObject()) |zo| { + // zo.resolveSymbols(macho_file); + // zo.asFile().markExportsRelocatable(macho_file); + // zo.asFile().claimUnresolvedRelocatable(macho_file); + // try macho_file.sortSections(); + // try macho_file.addAtomsToSections(); + // try calcSectionSizes(macho_file); + // try createSegment(macho_file); + // try allocateSections(macho_file); + // allocateSegment(macho_file); - var off = off: { - const seg = macho_file.segments.items[0]; - const off = math.cast(u32, seg.fileoff + seg.filesize) orelse return error.Overflow; - break :off mem.alignForward(u32, off, @alignOf(macho.relocation_info)); - }; - off = allocateSectionsRelocs(macho_file, off); + // var off = off: { + // const seg = macho_file.segments.items[0]; + // const off = math.cast(u32, seg.fileoff + seg.filesize) orelse return error.Overflow; + // break :off mem.alignForward(u32, off, @alignOf(macho.relocation_info)); + // }; + // off = allocateSectionsRelocs(macho_file, off); - if (build_options.enable_logging) { - state_log.debug("{}", .{macho_file.dumpState()}); - } + // if (build_options.enable_logging) { + // state_log.debug("{}", .{macho_file.dumpState()}); + // } - try macho_file.calcSymtabSize(); - try writeAtoms(macho_file); + // try macho_file.calcSymtabSize(); + // try writeAtoms(macho_file); - off = mem.alignForward(u32, off, @alignOf(u64)); - off = try macho_file.writeDataInCode(0, off); - off = mem.alignForward(u32, off, @alignOf(u64)); - off = try macho_file.writeSymtab(off); - off = mem.alignForward(u32, off, @alignOf(u64)); - off = try macho_file.writeStrtab(off); + // off = mem.alignForward(u32, off, @alignOf(u64)); + // off = try macho_file.writeDataInCode(0, off); + // off = mem.alignForward(u32, off, @alignOf(u64)); + // off = try macho_file.writeSymtab(off); + // off = mem.alignForward(u32, off, @alignOf(u64)); + // off = try macho_file.writeStrtab(off); - // In order to please Apple ld (and possibly other MachO linkers in the wild), - // we will now sanitize segment names of Zig-specific segments. - sanitizeZigSections(macho_file); + // // In order to please Apple ld (and possibly other MachO linkers in the wild), + // // we will now sanitize segment names of Zig-specific segments. + // sanitizeZigSections(macho_file); - const ncmds, const sizeofcmds = try writeLoadCommands(macho_file); - try writeHeader(macho_file, ncmds, sizeofcmds); + // const ncmds, const sizeofcmds = try writeLoadCommands(macho_file); + // try writeHeader(macho_file, ncmds, sizeofcmds); - // TODO we can avoid reading in the file contents we just wrote if we give the linker - // ability to write directly to a buffer. - try zo.readFileContents(off, macho_file); - } + // // TODO we can avoid reading in the file contents we just wrote if we give the linker + // // ability to write directly to a buffer. + // try zo.readFileContents(off, macho_file); + // } var files = std.ArrayList(File.Index).init(gpa); defer files.deinit(); try files.ensureTotalCapacityPrecise(macho_file.objects.items.len + 1); - if (macho_file.getZigObject()) |zo| files.appendAssumeCapacity(zo.index); + // if (macho_file.getZigObject()) |zo| files.appendAssumeCapacity(zo.index); for (macho_file.objects.items) |index| files.appendAssumeCapacity(index); const format: Archive.Format = .p32;