From 84189f9d56f207e92d0a9d1f5145079cc46f8db0 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sat, 13 Jul 2024 10:00:38 +0200 Subject: [PATCH] macho: skip resizing incremental Zig sections in r mode --- src/link/MachO/relocatable.zig | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/link/MachO/relocatable.zig b/src/link/MachO/relocatable.zig index 1039b6557c..6b2594c493 100644 --- a/src/link/MachO/relocatable.zig +++ b/src/link/MachO/relocatable.zig @@ -637,11 +637,13 @@ fn writeSections(macho_file: *MachO) !void { const gpa = macho_file.base.comp.gpa; const cpu_arch = macho_file.getTarget().cpu.arch; const slice = macho_file.sections.slice(); - for (slice.items(.header), slice.items(.out), slice.items(.relocs)) |header, *out, *relocs| { + for (slice.items(.header), slice.items(.out), slice.items(.relocs), 0..) |header, *out, *relocs, n_sect| { if (header.isZerofill()) continue; - try out.resize(gpa, header.size); - const padding_byte: u8 = if (header.isCode() and cpu_arch == .x86_64) 0xcc else 0; - @memset(out.items, padding_byte); + if (!macho_file.isZigSection(@intCast(n_sect))) { // TODO this is wrong; what about debug sections? + try out.resize(gpa, header.size); + const padding_byte: u8 = if (header.isCode() and cpu_arch == .x86_64) 0xcc else 0; + @memset(out.items, padding_byte); + } try relocs.resize(gpa, header.nreloc); }