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) {...@@ -2101,9 +2101,10 @@ static void construct_linker_job_wasm(LinkJob *lj) {
21012101
2102 lj->args.append("-error-limit=0");2102 lj->args.append("-error-limit=0");
2103 // Increase the default stack size to a more reasonable value of 1MB instead of2103 // 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;
2105 lj->args.append("-z");2106 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
2108 if (g->out_type != OutTypeExe) {2109 if (g->out_type != OutTypeExe) {
2109 lj->args.append("--no-entry"); // So lld doesn't look for _start.2110 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) {...@@ -126,6 +126,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
126 " -l[lib] alias for --library\n"126 " -l[lib] alias for --library\n"
127 " -rdynamic add all symbols to the dynamic symbol table\n"127 " -rdynamic add all symbols to the dynamic symbol table\n"
128 " -rpath [path] add directory to the runtime library search path\n"128 " -rpath [path] add directory to the runtime library search path\n"
129 " --stack [size] (linux, windows, Wasm) override default stack size\n"
129 " --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"130 " --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"
130 " -F[dir] (darwin) add search path for frameworks\n"131 " -F[dir] (darwin) add search path for frameworks\n"
131 " -framework [name] (darwin) link against framework\n"132 " -framework [name] (darwin) link against framework\n"
...@@ -1231,6 +1232,8 @@ static int main0(int argc, char **argv) {...@@ -1231,6 +1232,8 @@ static int main0(int argc, char **argv) {
1231 ver_patch = atoi(argv[i]);1232 ver_patch = atoi(argv[i]);
1232 } else if (strcmp(arg, "--test-cmd") == 0) {1233 } else if (strcmp(arg, "--test-cmd") == 0) {
1233 test_exec_args.append(argv[i]);1234 test_exec_args.append(argv[i]);
1235 } else if (strcmp(arg, "--stack") == 0) {
1236 stack_size_override = atoi(argv[i]);
1234 } else if (strcmp(arg, "--subsystem") == 0) {1237 } else if (strcmp(arg, "--subsystem") == 0) {
1235 if (strcmp(argv[i], "console") == 0) {1238 if (strcmp(argv[i], "console") == 0) {
1236 subsystem = TargetSubsystemConsole;1239 subsystem = TargetSubsystemConsole;