[lld][WebAssembly] Add an --initial-heap option (#75594)

It is beneficial to preallocate a certain number of pages in the linear
memory (i. e. use the "minimum" field of WASM memories) so that fewer
"memory.grow"s are needed at startup.

So far, the way to do that has been to pass the "--initial-memory"
option to the linker. It works, but has the very significant downside of
requiring the user to know the size of static data beforehand, as it
must not exceed the number of bytes passed-in as "--initial-memory".

The new "--initial-heap" option avoids this downside by simply appending
the specified number of pages to static data (and stack), regardless of
how large they already are.

Ref: https://github.com/emscripten-core/emscripten/issues/20888.
This commit is contained in:
SingleAccretion
2023-12-15 21:16:38 +03:00
committed by GitHub
parent 1709e8c656
commit b2cdf3cc4c
6 changed files with 49 additions and 3 deletions

View File

@@ -502,9 +502,10 @@ static void readConfigs(opt::InputArgList &args) {
errorHandler().verbose = args.hasArg(OPT_verbose);
LLVM_DEBUG(errorHandler().verbose = true);
config->initialMemory = args::getInteger(args, OPT_initial_memory, 0);
config->globalBase = args::getInteger(args, OPT_global_base, 0);
config->tableBase = args::getInteger(args, OPT_table_base, 0);
config->globalBase = args::getInteger(args, OPT_global_base, 0);
config->initialHeap = args::getInteger(args, OPT_initial_heap, 0);
config->initialMemory = args::getInteger(args, OPT_initial_memory, 0);
config->maxMemory = args::getInteger(args, OPT_max_memory, 0);
config->zStackSize =
args::getZOptionValue(args, OPT_z, "stack-size", WasmPageSize);