aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/Object.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-08-01 12:28:58 +0200
committerJakub Konka <kubkon@jakubkonka.com>2022-08-03 21:19:41 +0200
commitbb532584bc569edb563b757c658fd743731837ec (patch)
treeaa0c1356909f0be2431e5420b0e84ca5ae89e5ad /src/link/MachO/Object.zig
parentf26d5ee7ea97c8fd6e5b2655f845be7e4293930e (diff)
downloadzig-bb532584bc569edb563b757c658fd743731837ec.tar.gz
zig-bb532584bc569edb563b757c658fd743731837ec.zip
macho: update how we insert output sections
Instead of generating sections upfront, allow generation by scanning the object files for input -> output sections mapping. Next, always strive to keep output sections in the final container sorted as they appear in the final binary. This makes the linker less messy wrt handling of output sections sort order for dyld/macOS not to complain. There's still more work to be done for incremental context though to make this work but looks promising already.
Diffstat (limited to 'src/link/MachO/Object.zig')
-rw-r--r--src/link/MachO/Object.zig23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig
index 2e2f3dad84..996a85ed4b 100644
--- a/src/link/MachO/Object.zig
+++ b/src/link/MachO/Object.zig
@@ -214,6 +214,23 @@ fn filterRelocs(
return relocs[start..end];
}
+pub fn scanInputSections(self: Object, macho_file: *MachO) !void {
+ for (self.sections.items) |sect| {
+ const match = (try macho_file.getOutputSection(sect)) orelse {
+ log.debug(" unhandled section", .{});
+ continue;
+ };
+ const output = macho_file.sections.items(.header)[match];
+ log.debug("mapping '{s},{s}' into output sect({d}, '{s},{s}')", .{
+ sect.segName(),
+ sect.sectName(),
+ match + 1,
+ output.segName(),
+ output.sectName(),
+ });
+ }
+}
+
/// Splits object into atoms assuming one-shot linking mode.
pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) !void {
assert(macho_file.mode == .one_shot);
@@ -280,13 +297,9 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32)
});
const cpu_arch = macho_file.base.options.target.cpu.arch;
- const is_zerofill = blk: {
- const section_type = sect.type_();
- break :blk section_type == macho.S_ZEROFILL or section_type == macho.S_THREAD_LOCAL_ZEROFILL;
- };
// Read section's code
- const code: ?[]const u8 = if (!is_zerofill) try self.getSectionContents(sect) else null;
+ const code: ?[]const u8 = if (!sect.isZerofill()) try self.getSectionContents(sect) else null;
// Read section's list of relocations
const relocs = @ptrCast(