diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-07-11 13:46:54 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-07-18 09:13:08 +0200 |
| commit | b4e6b3c53c0fd54b43f648d9a207e8ff592dd0ff (patch) | |
| tree | 80aecf7a8b554ce6179cf57b3d30a6770a29373f | |
| parent | 05a790d784e4f1258d550e31178cf1e163750b6b (diff) | |
| download | zig-b4e6b3c53c0fd54b43f648d9a207e8ff592dd0ff.tar.gz zig-b4e6b3c53c0fd54b43f648d9a207e8ff592dd0ff.zip | |
macho: bring back parts of r mode
| -rw-r--r-- | src/link/MachO.zig | 2 | ||||
| -rw-r--r-- | src/link/MachO/relocatable.zig | 116 |
2 files changed, 60 insertions, 58 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig index ebe280ca76..98c1eb2339 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -357,7 +357,7 @@ pub fn flushModule(self: *MachO, arena: Allocator, tid: Zcu.PerThread.Id, prog_n if (self.getZigObject()) |zo| try zo.flushModule(self, tid); if (self.base.isStaticLib()) return relocatable.flushStaticLib(self, comp, module_obj_path); - // if (self.base.isObject()) return relocatable.flushObject(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); defer positionals.deinit(); diff --git a/src/link/MachO/relocatable.zig b/src/link/MachO/relocatable.zig index 516b9a1c46..9dcd7a64ff 100644 --- a/src/link/MachO/relocatable.zig +++ b/src/link/MachO/relocatable.zig @@ -26,68 +26,70 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]c return; } - for (positionals.items) |obj| { - macho_file.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { - error.MalformedObject, - error.MalformedArchive, - error.InvalidCpuArch, - error.InvalidTarget, - => continue, // already reported - error.UnknownFileType => try macho_file.reportParseError(obj.path, "unknown file type for an object file", .{}), - else => |e| try macho_file.reportParseError( - obj.path, - "unexpected error: parsing input file failed with error {s}", - .{@errorName(e)}, - ), - }; - } - - if (comp.link_errors.items.len > 0) return error.FlushFailure; - - try macho_file.addUndefinedGlobals(); - try macho_file.resolveSymbols(); - try macho_file.parseDebugInfo(); - try macho_file.dedupLiterals(); - markExports(macho_file); - claimUnresolved(macho_file); - try initOutputSections(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); + @panic("TODO -r mode"); + + // for (positionals.items) |obj| { + // macho_file.parsePositional(obj.path, obj.must_link) catch |err| switch (err) { + // error.MalformedObject, + // error.MalformedArchive, + // error.InvalidCpuArch, + // error.InvalidTarget, + // => continue, // already reported + // error.UnknownFileType => try macho_file.reportParseError(obj.path, "unknown file type for an object file", .{}), + // else => |e| try macho_file.reportParseError( + // obj.path, + // "unexpected error: parsing input file failed with error {s}", + // .{@errorName(e)}, + // ), + // }; + // } - if (build_options.enable_logging) { - state_log.debug("{}", .{macho_file.dumpState()}); - } + // if (comp.link_errors.items.len > 0) return error.FlushFailure; + + // try macho_file.addUndefinedGlobals(); + // try macho_file.resolveSymbols(); + // try macho_file.parseDebugInfo(); + // try macho_file.dedupLiterals(); + // markExports(macho_file); + // claimUnresolved(macho_file); + // try initOutputSections(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); + + // if (build_options.enable_logging) { + // state_log.debug("{}", .{macho_file.dumpState()}); + // } - try macho_file.calcSymtabSize(); - try writeAtoms(macho_file); - try writeCompactUnwind(macho_file); - try writeEhFrame(macho_file); + // try macho_file.calcSymtabSize(); + // try writeAtoms(macho_file); + // try writeCompactUnwind(macho_file); + // try writeEhFrame(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); } pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?[]const u8) link.File.FlushError!void { |
