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