| author | |
| committer | |
| log | 0ff5d7b24e2017199566d1bab75254fa5ef68611 |
| tree | 0c44d8f84b155eedef9e7cbfba47c0834d700a84 |
| parent | cde7c756767348e4c96770327b490f824f2a8e60 |
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 | 2101 | |
| 2102 | 2102 | lj->args.append("-error-limit=0"); |
| 2103 | 2103 | // 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 | 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))); | |
| 2107 | 2108 | |
| 2108 | 2109 | if (g->out_type != OutTypeExe) { |
| 2109 | 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 | 126 | " -l[lib] alias for --library\n" |
| 127 | 127 | " -rdynamic add all symbols to the dynamic symbol table\n" |
| 128 | 128 | " -rpath [path] add directory to the runtime library search path\n" |
| 129 | " --stack [size] (linux, windows, Wasm) override default stack size\n" | |
| 129 | 130 | " --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n" |
| 130 | 131 | " -F[dir] (darwin) add search path for frameworks\n" |
| 131 | 132 | " -framework [name] (darwin) link against framework\n" |
| ... | ... | @@ -1231,6 +1232,8 @@ static int main0(int argc, char **argv) { |
| 1231 | 1232 | ver_patch = atoi(argv[i]); |
| 1232 | 1233 | } else if (strcmp(arg, "--test-cmd") == 0) { |
| 1233 | 1234 | test_exec_args.append(argv[i]); |
| 1235 | } else if (strcmp(arg, "--stack") == 0) { | |
| 1236 | stack_size_override = atoi(argv[i]); | |
| 1234 | 1237 | } else if (strcmp(arg, "--subsystem") == 0) { |
| 1235 | 1238 | if (strcmp(argv[i], "console") == 0) { |
| 1236 | 1239 | subsystem = TargetSubsystemConsole; |