Fall back to cabi_realloc in the main module - #2606
Open
alexcrichton wants to merge 2 commits into
Open
Conversation
This commit updates the `__wasm_task_hook` intrinsic, added in bytecodealliance#2603, to additionally get called for the `realloc` function, typically exported as `cabi_realloc` today. The goal of this commit is to uniformly use this hook for wasip3 task initialization/configuration as opposed to the current state of affairs in wasi-libc where `cabi_realloc` is special. The implementation here is more involved than bytecodealliance#2603 `realloc` options are required to create the fixup module and thus come from the original instance raw. When using task hooks, however, the desired state is that the lowerings created use the hooked version of `realloc`. As with all problems in computer science, this is solved with another layer of indirection. Specifically the shim module may not contain shims for `realloc` options if used for lowerings. These are then hooked up through the fixup module so it's instantiated with both lowered functions and the "real" implementation so everything can get wired up at the same time. While implementing this I went ahead an implemented a minor optimization where for modules that import linear memory they no longer need an shim-per-import-using-realloc and instead just have a single shim for realloc. This means that when importing memory generated components generally have even fewer shims than before. This commit then attempts to add a variety of tests for various shapes of this new hook and various other options. This was developed in tandem with changes to wasi-libc and additionally verified against those.
This commit updates the behavior of `wasm-tools component link` to search for the `cabi_realloc` function in the main module, if present. This behavior fixes an issue when linking shared libraries where each shared library was required to export its own `cabi_realloc` which otherwise doesn't happen by default when using wasi-sdk for example. By falling back to the main module that preserves the originally intended semantics, one definition of `cabi_realloc`, and these situations should work by default now.
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 commit updates the behavior of
wasm-tools component linktosearch for the
cabi_reallocfunction in the main module, if present.This behavior fixes an issue when linking shared libraries where each
shared library was required to export its own
cabi_reallocwhichotherwise doesn't happen by default when using wasi-sdk for example. By
falling back to the main module that preserves the originally intended
semantics, one definition of
cabi_realloc, and these situations shouldwork by default now.