authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-12 15:35:01+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-18 09:13:08+02:00
logcba04ff24403ea5d134524eee318424599f068a6
tree661c7a1a8ebe129309e2085f152cb1e16f19c43f
parent2579c55d4903b016e0fb6d1f52fbbfe4a2a71c26

macho: re-enable calculating num of relocs for ZigObject


2 files changed, 18 insertions(+), 12 deletions(-)

src/link/MachO/ZigObject.zig+10
...@@ -433,6 +433,16 @@ pub fn resolveRelocs(self: *ZigObject, macho_file: *MachO) !void {...@@ -433,6 +433,16 @@ pub fn resolveRelocs(self: *ZigObject, macho_file: *MachO) !void {
433 if (has_error) return error.ResolveFailed;433 if (has_error) return error.ResolveFailed;
434}434}
435435
436pub fn calcNumRelocs(self: *ZigObject, macho_file: *MachO) void {
437 for (self.getAtoms()) |atom_index| {
438 const atom = self.getAtom(atom_index) orelse continue;
439 if (!atom.flags.alive) continue;
440 if (!macho_file.isZigSection(atom.out_n_sect) and !macho_file.isDebugSection(atom.out_n_sect)) continue;
441 const header = &macho_file.sections.items(.header)[atom.out_n_sect];
442 header.nreloc += atom.calcNumRelocs(macho_file);
443 }
444}
445
436pub fn calcSymtabSize(self: *ZigObject, macho_file: *MachO) void {446pub fn calcSymtabSize(self: *ZigObject, macho_file: *MachO) void {
437 const tracy = trace(@src());447 const tracy = trace(@src());
438 defer tracy.end();448 defer tracy.end();
src/link/MachO/relocatable.zig+8-12
...@@ -369,6 +369,11 @@ fn calcSectionSizes(macho_file: *MachO) !void {...@@ -369,6 +369,11 @@ fn calcSectionSizes(macho_file: *MachO) !void {
369 calcSectionSize(macho_file, @intCast(i));369 calcSectionSize(macho_file, @intCast(i));
370 }370 }
371371
372 if (macho_file.getZigObject()) |zo| {
373 // TODO this will create a race
374 zo.calcNumRelocs(macho_file);
375 }
376
372 if (macho_file.eh_frame_sect_index) |_| {377 if (macho_file.eh_frame_sect_index) |_| {
373 try calcEhFrameSize(macho_file);378 try calcEhFrameSize(macho_file);
374 }379 }
...@@ -382,19 +387,10 @@ fn calcSectionSizes(macho_file: *MachO) !void {...@@ -382,19 +387,10 @@ fn calcSectionSizes(macho_file: *MachO) !void {
382387
383 try macho_file.data_in_code.updateSize(macho_file);388 try macho_file.data_in_code.updateSize(macho_file);
384389
385 calcCompactUnwindSize(macho_file);390 if (macho_file.unwind_info_sect_index) |_| {
391 calcCompactUnwindSize(macho_file);
392 }
386 calcSymtabSize(macho_file);393 calcSymtabSize(macho_file);
387
388 // TODO
389 // if (macho_file.getZigObject()) |zo| {
390 // for (zo.atoms.items) |atom_index| {
391 // const atom = macho_file.getAtom(atom_index) orelse continue;
392 // if (!atom.flags.alive) continue;
393 // const header = &macho_file.sections.items(.header)[atom.out_n_sect];
394 // if (!macho_file.isZigSection(atom.out_n_sect) and !macho_file.isDebugSection(atom.out_n_sect)) continue;
395 // header.nreloc += atom.calcNumRelocs(macho_file);
396 // }
397 // }
398}394}
399395
400fn calcSectionSize(macho_file: *MachO, sect_id: u8) void {396fn calcSectionSize(macho_file: *MachO, sect_id: u8) void {