| ... | @@ -127,55 +127,56 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ? | ... | @@ -127,55 +127,56 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ? |
| 127 | | 127 | |
| 128 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | 128 | if (comp.link_errors.items.len > 0) return error.FlushFailure; |
| 129 | | 129 | |
| 130 | // First, we flush relocatable object file generated with our backends. | 130 | // TODO re-enable |
| 131 | if (macho_file.getZigObject()) |zo| { | 131 | // // First, we flush relocatable object file generated with our backends. |
| 132 | zo.resolveSymbols(macho_file); | 132 | // if (macho_file.getZigObject()) |zo| { |
| 133 | zo.asFile().markExportsRelocatable(macho_file); | 133 | // zo.resolveSymbols(macho_file); |
| 134 | zo.asFile().claimUnresolvedRelocatable(macho_file); | 134 | // zo.asFile().markExportsRelocatable(macho_file); |
| 135 | try macho_file.sortSections(); | 135 | // zo.asFile().claimUnresolvedRelocatable(macho_file); |
| 136 | try macho_file.addAtomsToSections(); | 136 | // try macho_file.sortSections(); |
| 137 | try calcSectionSizes(macho_file); | 137 | // try macho_file.addAtomsToSections(); |
| 138 | try createSegment(macho_file); | 138 | // try calcSectionSizes(macho_file); |
| 139 | try allocateSections(macho_file); | 139 | // try createSegment(macho_file); |
| 140 | allocateSegment(macho_file); | 140 | // try allocateSections(macho_file); |
| 141 | | 141 | // allocateSegment(macho_file); |
| 142 | var off = off: { | 142 | |
| 143 | const seg = macho_file.segments.items[0]; | 143 | // var off = off: { |
| 144 | const off = math.cast(u32, seg.fileoff + seg.filesize) orelse return error.Overflow; | 144 | // const seg = macho_file.segments.items[0]; |
| 145 | break :off mem.alignForward(u32, off, @alignOf(macho.relocation_info)); | 145 | // const off = math.cast(u32, seg.fileoff + seg.filesize) orelse return error.Overflow; |
| 146 | }; | 146 | // break :off mem.alignForward(u32, off, @alignOf(macho.relocation_info)); |
| 147 | off = allocateSectionsRelocs(macho_file, off); | 147 | // }; |
| 148 | | 148 | // off = allocateSectionsRelocs(macho_file, off); |
| 149 | if (build_options.enable_logging) { | 149 | |
| 150 | state_log.debug("{}", .{macho_file.dumpState()}); | 150 | // if (build_options.enable_logging) { |
| 151 | } | 151 | // state_log.debug("{}", .{macho_file.dumpState()}); |
| 152 | | 152 | // } |
| 153 | try macho_file.calcSymtabSize(); | 153 | |
| 154 | try writeAtoms(macho_file); | 154 | // try macho_file.calcSymtabSize(); |
| 155 | | 155 | // try writeAtoms(macho_file); |
| 156 | off = mem.alignForward(u32, off, @alignOf(u64)); | 156 | |
| 157 | off = try macho_file.writeDataInCode(0, off); | 157 | // off = mem.alignForward(u32, off, @alignOf(u64)); |
| 158 | off = mem.alignForward(u32, off, @alignOf(u64)); | 158 | // off = try macho_file.writeDataInCode(0, off); |
| 159 | off = try macho_file.writeSymtab(off); | 159 | // off = mem.alignForward(u32, off, @alignOf(u64)); |
| 160 | off = mem.alignForward(u32, off, @alignOf(u64)); | 160 | // off = try macho_file.writeSymtab(off); |
| 161 | off = try macho_file.writeStrtab(off); | 161 | // off = mem.alignForward(u32, off, @alignOf(u64)); |
| 162 | | 162 | // off = try macho_file.writeStrtab(off); |
| 163 | // In order to please Apple ld (and possibly other MachO linkers in the wild), | 163 | |
| 164 | // we will now sanitize segment names of Zig-specific segments. | 164 | // // In order to please Apple ld (and possibly other MachO linkers in the wild), |
| 165 | sanitizeZigSections(macho_file); | 165 | // // we will now sanitize segment names of Zig-specific segments. |
| 166 | | 166 | // sanitizeZigSections(macho_file); |
| 167 | const ncmds, const sizeofcmds = try writeLoadCommands(macho_file); | 167 | |
| 168 | try writeHeader(macho_file, ncmds, sizeofcmds); | 168 | // const ncmds, const sizeofcmds = try writeLoadCommands(macho_file); |
| 169 | | 169 | // try writeHeader(macho_file, ncmds, sizeofcmds); |
| 170 | // TODO we can avoid reading in the file contents we just wrote if we give the linker | 170 | |
| 171 | // ability to write directly to a buffer. | 171 | // // TODO we can avoid reading in the file contents we just wrote if we give the linker |
| 172 | try zo.readFileContents(off, macho_file); | 172 | // // ability to write directly to a buffer. |
| 173 | } | 173 | // try zo.readFileContents(off, macho_file); |
| | 174 | // } |
| 174 | | 175 | |
| 175 | var files = std.ArrayList(File.Index).init(gpa); | 176 | var files = std.ArrayList(File.Index).init(gpa); |
| 176 | defer files.deinit(); | 177 | defer files.deinit(); |
| 177 | try files.ensureTotalCapacityPrecise(macho_file.objects.items.len + 1); | 178 | try files.ensureTotalCapacityPrecise(macho_file.objects.items.len + 1); |
| 178 | if (macho_file.getZigObject()) |zo| files.appendAssumeCapacity(zo.index); | 179 | // if (macho_file.getZigObject()) |zo| files.appendAssumeCapacity(zo.index); |
| 179 | for (macho_file.objects.items) |index| files.appendAssumeCapacity(index); | 180 | for (macho_file.objects.items) |index| files.appendAssumeCapacity(index); |
| 180 | | 181 | |
| 181 | const format: Archive.Format = .p32; | 182 | const format: Archive.Format = .p32; |