Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix global initialization in WASI #253

Merged
merged 2 commits into from
Oct 10, 2024
Merged

Fix global initialization in WASI #253

merged 2 commits into from
Oct 10, 2024

Conversation

DutChen18
Copy link
Member

#include <iostream>

int main() {
        std::cout << "Hello, World!" << std::endl;
        return 0;
}
$ /opt/cheerp/bin/clang++ test.cpp -o test.wasm -target cheerp-wasm-wasi
$ wasmtime test.wasm
Error: failed to run main module `test.wasm`

Caused by:
    0: failed to instantiate "test.wasm"
    1: unknown import: `i::_GLOBAL__I_000101` has not been defined

The above error occurs because of two issues:

  1. There is a genericjs Exception::allocator global present in the wasm libs, the initialization of which was done by pre-executor before, but now fails because the pre-executor does not handle a threading intrinsic.
  2. Even if the wasm libs only contain wasm globals, the entry point for global initialization was being put in genericjs.

Because of these issues, any WASI program with globals that could not be pre-executed would fail with the above error. This PR fixes both issues. Note that no changes are made to pre-executor, it will still fail to initialize some gloals due to unhandled intrinsics. But this will no longer be a problem as, with these fixes, they can now be initialized at runtime in WASI.

This makes it so the global is not present in wasm libs, which is needed
for wasi to work.
@DutChen18 DutChen18 requested a review from yuri91 October 7, 2024 13:10
@yuri91 yuri91 merged commit 6dfb6ea into master Oct 10, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants