authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2020-06-05 22:21:33+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-06-08 17:44:06-04:00
log0ff5d7b24e2017199566d1bab75254fa5ef68611
tree0c44d8f84b155eedef9e7cbfba47c0834d700a84
parentcde7c756767348e4c96770327b490f824f2a8e60

Add option for overriding the stack size

This commit adds a `--stack [size]` link-time option to zig compiler allowing the user to override the default stack size set for the specified executable/library format. This is currently limited to ELF, COFF and Wasm however (i.e., Mach-O is excluded).

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

src/link.cpp+3-2
......@@ -2101,9 +2101,10 @@ static void construct_linker_job_wasm(LinkJob *lj) {
21012101
21022102 lj->args.append("-error-limit=0");
21032103 // Increase the default stack size to a more reasonable value of 1MB instead of
2104 // the default of 1 Wasm page being 64KB.
2104 // the default of 1 Wasm page being 64KB, unless overriden by the user.
2105 size_t stack_size = (g->stack_size_override == 0) ? 1048576 : g->stack_size_override;
21052106 lj->args.append("-z");
2106 lj->args.append("stack-size=1048576");
2107 lj->args.append(buf_ptr(buf_sprintf("stack-size=%" ZIG_PRI_usize, stack_size)));
21072108
21082109 if (g->out_type != OutTypeExe) {
21092110 lj->args.append("--no-entry"); // So lld doesn't look for _start.
src/main.cpp+3
......@@ -126,6 +126,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
126126 " -l[lib] alias for --library\n"
127127 " -rdynamic add all symbols to the dynamic symbol table\n"
128128 " -rpath [path] add directory to the runtime library search path\n"
129 " --stack [size] (linux, windows, Wasm) override default stack size\n"
129130 " --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"
130131 " -F[dir] (darwin) add search path for frameworks\n"
131132 " -framework [name] (darwin) link against framework\n"
......@@ -1231,6 +1232,8 @@ static int main0(int argc, char **argv) {
12311232 ver_patch = atoi(argv[i]);
12321233 } else if (strcmp(arg, "--test-cmd") == 0) {
12331234 test_exec_args.append(argv[i]);
1235 } else if (strcmp(arg, "--stack") == 0) {
1236 stack_size_override = atoi(argv[i]);
12341237 } else if (strcmp(arg, "--subsystem") == 0) {
12351238 if (strcmp(argv[i], "console") == 0) {
12361239 subsystem = TargetSubsystemConsole;