Wasm: remove implicit __heap_base/__data_end exports#156174
Open
daxpedda wants to merge 1 commit intorust-lang:mainfrom
Open
Wasm: remove implicit __heap_base/__data_end exports#156174daxpedda wants to merge 1 commit intorust-lang:mainfrom
__heap_base/__data_end exports#156174daxpedda wants to merge 1 commit intorust-lang:mainfrom
Conversation
Member
|
This change likely would fix #155173 |
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.
This is kind of a follow-up to #147225. Currently
__heap_base/__data_endglobals are implicitly exported onwasm*-unknown-unknownandwasm32v1-none, even though they were only used for Wasm multi-threading, requiring the atomics target feature and shared memory.Instead users should explicitly opt-in to these features, in which case toolchains, like
wasm-bindgen, would require some linker flags. After this PR the following would be required for multi-threading support inwasm-bindgen:You will notice that the only new addition is
--export=__heap_base, apparentlywasm-bindgendoesn't need__data_endanymore (I didn't dig into the original motivation).For context why
wasm-bindgenneeded access to__heap_base:There is currently no mechanism in the Wasm tool conventions that automatically allocates the stack for every thread (e.g. via the
startfunction). Sowasm-bindgenhas to explicitly callmallocto allocate the stack on the new thread.However, calling
mallocitself requires a stack to be present! With the help of__heap_basewasm-bindgenconstructs a temporary stack to make this work. This is obviously quite hacky. A newer implementation could go a different route: e.g. allocate the threads stack in the main thread and passing the right information on, not requiring access to__heap_baseat all (and avoiding this really messy workaround).I should also note here that e.g.
js-bindgen, the successor currently being worked on, doesn't need any of these exports because it doesn't rely on post-processing. In which case all of these variables can be accessed by name at link-time, instead of requiring the linker to export each variable for post-processing to find them by name. That is to say: all these workaround are toolchain-specific and not universal to the Wasm targets.r? @alexcrichton