authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-10-07 11:00:40+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-10-07 17:18:37+02:00
log07c33dfc951af5e7bf1c29c94142d49e3acf08b0
tree1681539cdd41885d381881f9fcf2272f1056f3f8
parent53dee08af99dd334b0d227afb5ce2a0f92c35a5d

Remove obsolete addPadding fn and callsites from MachO linker

This is no longer needed due to the way writing to the output file is structured. Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>

1 files changed, 0 insertions(+), 21 deletions(-)

src/link/MachO.zig-21
...@@ -287,9 +287,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -287,9 +287,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
287 }287 }
288 const cmd = &self.load_commands.items[self.dylinker_cmd_index.?].Dylinker;288 const cmd = &self.load_commands.items[self.dylinker_cmd_index.?].Dylinker;
289 off += cmd.name;289 off += cmd.name;
290 const padding = cmd.cmdsize - @sizeOf(macho.dylinker_command);
291 log.debug("writing LC_LOAD_DYLINKER padding of size {} at 0x{x}\n", .{ padding, off });
292 try self.addPadding(padding, off);
293 log.debug("writing LC_LOAD_DYLINKER path to dyld at 0x{x}\n", .{off});290 log.debug("writing LC_LOAD_DYLINKER path to dyld at 0x{x}\n", .{off});
294 try self.base.file.?.pwriteAll(mem.spanZ(DEFAULT_DYLD_PATH), off);291 try self.base.file.?.pwriteAll(mem.spanZ(DEFAULT_DYLD_PATH), off);
295 }292 }
...@@ -302,9 +299,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {...@@ -302,9 +299,6 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
302 }299 }
303 const cmd = &self.load_commands.items[self.libsystem_cmd_index.?].Dylib;300 const cmd = &self.load_commands.items[self.libsystem_cmd_index.?].Dylib;
304 off += cmd.dylib.name;301 off += cmd.dylib.name;
305 const padding = cmd.cmdsize - @sizeOf(macho.dylib_command);
306 log.debug("writing LC_LOAD_DYLIB padding of size {} at 0x{x}\n", .{ padding, off });
307 try self.addPadding(padding, off);
308 log.debug("writing LC_LOAD_DYLIB path to libSystem at 0x{x}\n", .{off});302 log.debug("writing LC_LOAD_DYLIB path to libSystem at 0x{x}\n", .{off});
309 try self.base.file.?.pwriteAll(mem.spanZ(LIB_SYSTEM_PATH), off);303 try self.base.file.?.pwriteAll(mem.spanZ(LIB_SYSTEM_PATH), off);
310 }304 }
...@@ -1264,21 +1258,6 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 {...@@ -1264,21 +1258,6 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 {
1264 return self.makeString(new_name);1258 return self.makeString(new_name);
1265}1259}
12661260
1267/// TODO This should not heap allocate, instead it should utilize a fixed size, statically allocated
1268/// global const array. You could even use pwritev to write the same buffer multiple times with only
1269/// 1 syscall if you needed to, for example, write 8192 bytes using a buffer of only 4096 bytes.
1270/// This size parameter should probably be a usize not u64.
1271fn addPadding(self: *MachO, size: u64, file_offset: u64) !void {
1272 if (size == 0) return;
1273
1274 const buf = try self.base.allocator.alloc(u8, @intCast(usize, size));
1275 defer self.base.allocator.free(buf);
1276
1277 mem.set(u8, buf[0..], 0);
1278
1279 try self.base.file.?.pwriteAll(buf, file_offset);
1280}
1281
1282fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 {1261fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 {
1283 const hdr_size: u64 = @sizeOf(macho.mach_header_64);1262 const hdr_size: u64 = @sizeOf(macho.mach_header_64);
1284 if (start < hdr_size) return hdr_size;1263 if (start < hdr_size) return hdr_size;