authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-08 23:50:31+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-08 23:51:30+01:00
log3bfda3d791c5315712f4c4c2fd0e83c8518d089a
treed686966f7cd90332e2226c5516df1b89f054c074
parent8c0e5435b32bfcd7e8a55cce9fc5b4ba70d1a148

macho: fix alignment of objects in archive


1 files changed, 6 insertions(+), 6 deletions(-)

src/link/MachO/relocatable.zig+6-6
...@@ -193,8 +193,8 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?...@@ -193,8 +193,8 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?
193 // Update file offsets of contributing objects193 // Update file offsets of contributing objects
194 const total_size: usize = blk: {194 const total_size: usize = blk: {
195 var pos: usize = Archive.SARMAG;195 var pos: usize = Archive.SARMAG;
196 pos += @sizeOf(Archive.ar_hdr) + Archive.SYMDEF.len + 1;196 pos += @sizeOf(Archive.ar_hdr);
197 pos = mem.alignForward(usize, pos, ptr_width);197 pos += mem.alignForward(usize, Archive.SYMDEF.len + 1, ptr_width);
198 pos += ar_symtab.size(format);198 pos += ar_symtab.size(format);
199199
200 for (files.items) |index| {200 for (files.items) |index| {
...@@ -209,10 +209,10 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?...@@ -209,10 +209,10 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?
209 .object => |x| x.path,209 .object => |x| x.path,
210 else => unreachable,210 else => unreachable,
211 };211 };
212 pos = mem.alignForward(usize, pos, ptr_width);212 pos = mem.alignForward(usize, pos, 2);
213 state.file_off = pos;213 state.file_off = pos;
214 pos += @sizeOf(Archive.ar_hdr) + path.len + 1;214 pos += @sizeOf(Archive.ar_hdr);
215 pos = mem.alignForward(usize, pos, ptr_width);215 pos += mem.alignForward(usize, path.len + 1, ptr_width);
216 pos += math.cast(usize, state.size) orelse return error.Overflow;216 pos += math.cast(usize, state.size) orelse return error.Overflow;
217 }217 }
218218
...@@ -236,7 +236,7 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?...@@ -236,7 +236,7 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?
236236
237 // Write object files237 // Write object files
238 for (files.items) |index| {238 for (files.items) |index| {
239 const aligned = mem.alignForward(usize, buffer.items.len, ptr_width);239 const aligned = mem.alignForward(usize, buffer.items.len, 2);
240 const padding = aligned - buffer.items.len;240 const padding = aligned - buffer.items.len;
241 if (padding > 0) {241 if (padding > 0) {
242 try writer.writeByteNTimes(0, padding);242 try writer.writeByteNTimes(0, padding);