authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-12 15:17:21+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-05-12 19:25:26+02:00
log7b7724628974067f1a66069699fd1433d32da50d
tree287632cb97c3f7e90bba6a10631d4c8a9c93fb62
parentfb8527b289db438494e3b86c65d5ade585a77b41

macho: allow overriding stack size in binary


2 files changed, 15 insertions(+), 2 deletions(-)

src/link/MachO.zig+4-1
......@@ -442,6 +442,7 @@ pub fn flushModule(self: *MachO, comp: *Compilation) !void {
442442 const text_segment = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
443443 const main_cmd = &self.load_commands.items[self.main_cmd_index.?].Main;
444444 main_cmd.entryoff = addr - text_segment.inner.vmaddr;
445 main_cmd.stacksize = self.base.options.stack_size_override orelse 0;
445446 self.load_commands_dirty = true;
446447 }
447448 try self.writeRebaseInfoTable();
......@@ -695,7 +696,9 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
695696 Compilation.dump_argv(argv.items);
696697 }
697698
698 try zld.link(input_files.items, full_out_path);
699 try zld.link(input_files.items, full_out_path, .{
700 .stack_size = self.base.options.stack_size_override,
701 });
699702
700703 break :outer;
701704 }
src/link/MachO/Zld.zig+11-1
......@@ -29,6 +29,10 @@ page_size: ?u16 = null,
2929file: ?fs.File = null,
3030out_path: ?[]const u8 = null,
3131
32// TODO these args will become obselete once Zld is coalesced with incremental
33// linker.
34stack_size: u64 = 0,
35
3236objects: std.ArrayListUnmanaged(*Object) = .{},
3337archives: std.ArrayListUnmanaged(*Archive) = .{},
3438
......@@ -172,7 +176,11 @@ pub fn closeFiles(self: Zld) void {
172176 if (self.file) |f| f.close();
173177}
174178
175pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8) !void {
179const LinkArgs = struct {
180 stack_size: ?u64 = null,
181};
182
183pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8, args: LinkArgs) !void {
176184 if (files.len == 0) return error.NoInputFiles;
177185 if (out_path.len == 0) return error.EmptyOutputPath;
178186
......@@ -206,6 +214,7 @@ pub fn link(self: *Zld, files: []const []const u8, out_path: []const u8) !void {
206214 .read = true,
207215 .mode = if (std.Target.current.os.tag == .windows) 0 else 0o777,
208216 });
217 self.stack_size = args.stack_size orelse 0;
209218
210219 try self.populateMetadata();
211220 try self.parseInputFiles(files);
......@@ -2204,6 +2213,7 @@ fn setEntryPoint(self: *Zld) !void {
22042213 const entry_sym = sym.cast(Symbol.Regular) orelse unreachable;
22052214 const ec = &self.load_commands.items[self.main_cmd_index.?].Main;
22062215 ec.entryoff = @intCast(u32, entry_sym.address - seg.inner.vmaddr);
2216 ec.stacksize = self.stack_size;
22072217}
22082218
22092219fn writeRebaseInfoTable(self: *Zld) !void {