Stage2: wasm-linker - Place stack at the beginning of the linear memory#10572
Merged
andrewrk merged 2 commits intoziglang:masterfrom Jan 12, 2022
Merged
Stage2: wasm-linker - Place stack at the beginning of the linear memory#10572andrewrk merged 2 commits intoziglang:masterfrom
andrewrk merged 2 commits intoziglang:masterfrom
Conversation
By placing the stack at the start of the memory section, we prevent the runtime from silently overwriting the global declarations and instead trap. We do however, allow users to overwrite this behavior by setting the global-base, 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 are sure the stack will not overflow and they want to decrease the binary size as the offsets to the static memory are generally smaller. (Having the stack in front, means that accessing the memory after the stack has a bigger offset when loading/storing from memory).
andrewrk
added a commit
that referenced
this pull request
Jan 12, 2022
Stage2: wasm-linker - Place stack at the beginning of the linear memory
scorphus
pushed a commit
to scorphus/zig
that referenced
this pull request
Jan 15, 2022
Stage2: wasm-linker - Place stack at the beginning of the linear memory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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-baseflag, 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-exeand 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