| ... | @@ -26,68 +26,70 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]c | ... | @@ -26,68 +26,70 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]c |
| 26 | return; | 26 | return; |
| 27 | } | 27 | } |
| 28 | | 28 | |
| 29 | for (positionals.items) |obj| { | 29 | @panic("TODO -r mode"); |
| 30 | macho_file.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { | 30 | |
| 31 | error.MalformedObject, | 31 | // for (positionals.items) |obj| { |
| 32 | error.MalformedArchive, | 32 | // macho_file.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { |
| 33 | error.InvalidCpuArch, | 33 | // error.MalformedObject, |
| 34 | error.InvalidTarget, | 34 | // error.MalformedArchive, |
| 35 | => continue, // already reported | 35 | // error.InvalidCpuArch, |
| 36 | error.UnknownFileType => try macho_file.reportParseError(obj.path, "unknown file type for an object file", .{}), | 36 | // error.InvalidTarget, |
| 37 | else => |e| try macho_file.reportParseError( | 37 | // => continue, // already reported |
| 38 | obj.path, | 38 | // error.UnknownFileType => try macho_file.reportParseError(obj.path, "unknown file type for an object file", .{}), |
| 39 | "unexpected error: parsing input file failed with error {s}", | 39 | // else => |e| try macho_file.reportParseError( |
| 40 | .{@errorName(e)}, | 40 | // obj.path, |
| 41 | ), | 41 | // "unexpected error: parsing input file failed with error {s}", |
| 42 | }; | 42 | // .{@errorName(e)}, |
| 43 | } | 43 | // ), |
| 44 | | 44 | // }; |
| 45 | if (comp.link_errors.items.len > 0) return error.FlushFailure; | 45 | // } |
| 46 | | | |
| 47 | try macho_file.addUndefinedGlobals(); | | |
| 48 | try macho_file.resolveSymbols(); | | |
| 49 | try macho_file.parseDebugInfo(); | | |
| 50 | try macho_file.dedupLiterals(); | | |
| 51 | markExports(macho_file); | | |
| 52 | claimUnresolved(macho_file); | | |
| 53 | try initOutputSections(macho_file); | | |
| 54 | try macho_file.sortSections(); | | |
| 55 | try macho_file.addAtomsToSections(); | | |
| 56 | try calcSectionSizes(macho_file); | | |
| 57 | | | |
| 58 | try createSegment(macho_file); | | |
| 59 | try allocateSections(macho_file); | | |
| 60 | allocateSegment(macho_file); | | |
| 61 | | | |
| 62 | var off = off: { | | |
| 63 | const seg = macho_file.segments.items[0]; | | |
| 64 | const off = math.cast(u32, seg.fileoff + seg.filesize) orelse return error.Overflow; | | |
| 65 | break :off mem.alignForward(u32, off, @alignOf(macho.relocation_info)); | | |
| 66 | }; | | |
| 67 | off = allocateSectionsRelocs(macho_file, off); | | |
| 68 | | 46 | |
| 69 | if (build_options.enable_logging) { | 47 | // if (comp.link_errors.items.len > 0) return error.FlushFailure; |
| 70 | state_log.debug("{}", .{macho_file.dumpState()}); | 48 | |
| 71 | } | 49 | // try macho_file.addUndefinedGlobals(); |
| | 50 | // try macho_file.resolveSymbols(); |
| | 51 | // try macho_file.parseDebugInfo(); |
| | 52 | // try macho_file.dedupLiterals(); |
| | 53 | // markExports(macho_file); |
| | 54 | // claimUnresolved(macho_file); |
| | 55 | // try initOutputSections(macho_file); |
| | 56 | // try macho_file.sortSections(); |
| | 57 | // try macho_file.addAtomsToSections(); |
| | 58 | // try calcSectionSizes(macho_file); |
| | 59 | |
| | 60 | // try createSegment(macho_file); |
| | 61 | // try allocateSections(macho_file); |
| | 62 | // allocateSegment(macho_file); |
| | 63 | |
| | 64 | // var off = off: { |
| | 65 | // const seg = macho_file.segments.items[0]; |
| | 66 | // const off = math.cast(u32, seg.fileoff + seg.filesize) orelse return error.Overflow; |
| | 67 | // break :off mem.alignForward(u32, off, @alignOf(macho.relocation_info)); |
| | 68 | // }; |
| | 69 | // off = allocateSectionsRelocs(macho_file, off); |
| | 70 | |
| | 71 | // if (build_options.enable_logging) { |
| | 72 | // state_log.debug("{}", .{macho_file.dumpState()}); |
| | 73 | // } |
| 72 | | 74 | |
| 73 | try macho_file.calcSymtabSize(); | 75 | // try macho_file.calcSymtabSize(); |
| 74 | try writeAtoms(macho_file); | 76 | // try writeAtoms(macho_file); |
| 75 | try writeCompactUnwind(macho_file); | 77 | // try writeCompactUnwind(macho_file); |
| 76 | try writeEhFrame(macho_file); | 78 | // try writeEhFrame(macho_file); |
| 77 | | 79 | |
| 78 | off = mem.alignForward(u32, off, @alignOf(u64)); | 80 | // off = mem.alignForward(u32, off, @alignOf(u64)); |
| 79 | off = try macho_file.writeDataInCode(0, off); | 81 | // off = try macho_file.writeDataInCode(0, off); |
| 80 | off = mem.alignForward(u32, off, @alignOf(u64)); | 82 | // off = mem.alignForward(u32, off, @alignOf(u64)); |
| 81 | off = try macho_file.writeSymtab(off); | 83 | // off = try macho_file.writeSymtab(off); |
| 82 | off = mem.alignForward(u32, off, @alignOf(u64)); | 84 | // off = mem.alignForward(u32, off, @alignOf(u64)); |
| 83 | off = try macho_file.writeStrtab(off); | 85 | // off = try macho_file.writeStrtab(off); |
| 84 | | 86 | |
| 85 | // In order to please Apple ld (and possibly other MachO linkers in the wild), | 87 | // // In order to please Apple ld (and possibly other MachO linkers in the wild), |
| 86 | // we will now sanitize segment names of Zig-specific segments. | 88 | // // we will now sanitize segment names of Zig-specific segments. |
| 87 | sanitizeZigSections(macho_file); | 89 | // sanitizeZigSections(macho_file); |
| 88 | | 90 | |
| 89 | const ncmds, const sizeofcmds = try writeLoadCommands(macho_file); | 91 | // const ncmds, const sizeofcmds = try writeLoadCommands(macho_file); |
| 90 | try writeHeader(macho_file, ncmds, sizeofcmds); | 92 | // try writeHeader(macho_file, ncmds, sizeofcmds); |
| 91 | } | 93 | } |
| 92 | | 94 | |
| 93 | pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void { | 95 | pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void { |