Stage2: wasm-linker - Place stack at the beginning of the linear memory #10572
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
By placing the stack at the start of the memory section, we prevent the runtime from silently overwriting the static memory and instead trap on a stack overflow.
We do, however, allow users to overwrite this behavior by setting the
global-base
flag, which puts the stack at the end of the memory section and the static data at the base that was specified.The reason a user would want to do this is when they need to put the static data at a specific address. Another benefit of doing so it has a side effect of lower binary size.
(Having the stack in front, means that accessing the memory after the stack has a bigger offset when loading/storing from memory. Bigger offsets mean it takes more bytes to represent the instruction).
Note: While we used to append this flag by default to wasm-ld, we only did this for
build-exe
and had no way to overwrite such behavior.This PR implements it for both the self-hosted linker and the linker frontend for stage1.
Closes #10567