From cba04ff24403ea5d134524eee318424599f068a6 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 12 Jul 2024 15:35:01 +0200 Subject: [PATCH] macho: re-enable calculating num of relocs for ZigObject --- src/link/MachO/ZigObject.zig | 10 ++++++++++ src/link/MachO/relocatable.zig | 20 ++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index 8e65feb264..bddd5379f4 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -433,6 +433,16 @@ pub fn resolveRelocs(self: *ZigObject, macho_file: *MachO) !void { if (has_error) return error.ResolveFailed; } +pub fn calcNumRelocs(self: *ZigObject, macho_file: *MachO) void { + for (self.getAtoms()) |atom_index| { + const atom = self.getAtom(atom_index) orelse continue; + if (!atom.flags.alive) continue; + if (!macho_file.isZigSection(atom.out_n_sect) and !macho_file.isDebugSection(atom.out_n_sect)) continue; + const header = &macho_file.sections.items(.header)[atom.out_n_sect]; + header.nreloc += atom.calcNumRelocs(macho_file); + } +} + pub fn calcSymtabSize(self: *ZigObject, macho_file: *MachO) void { const tracy = trace(@src()); defer tracy.end(); diff --git a/src/link/MachO/relocatable.zig b/src/link/MachO/relocatable.zig index 0095118c86..c3d15c2241 100644 --- a/src/link/MachO/relocatable.zig +++ b/src/link/MachO/relocatable.zig @@ -369,6 +369,11 @@ fn calcSectionSizes(macho_file: *MachO) !void { calcSectionSize(macho_file, @intCast(i)); } + if (macho_file.getZigObject()) |zo| { + // TODO this will create a race + zo.calcNumRelocs(macho_file); + } + if (macho_file.eh_frame_sect_index) |_| { try calcEhFrameSize(macho_file); } @@ -382,19 +387,10 @@ fn calcSectionSizes(macho_file: *MachO) !void { try macho_file.data_in_code.updateSize(macho_file); - calcCompactUnwindSize(macho_file); + if (macho_file.unwind_info_sect_index) |_| { + calcCompactUnwindSize(macho_file); + } calcSymtabSize(macho_file); - - // TODO - // if (macho_file.getZigObject()) |zo| { - // for (zo.atoms.items) |atom_index| { - // const atom = macho_file.getAtom(atom_index) orelse continue; - // if (!atom.flags.alive) continue; - // const header = &macho_file.sections.items(.header)[atom.out_n_sect]; - // if (!macho_file.isZigSection(atom.out_n_sect) and !macho_file.isDebugSection(atom.out_n_sect)) continue; - // header.nreloc += atom.calcNumRelocs(macho_file); - // } - // } } fn calcSectionSize(macho_file: *MachO, sect_id: u8) void {