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