-
Notifications
You must be signed in to change notification settings - Fork 67
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
which memory dynamic-linking libraries should use for host functions? #232
Comments
The memory for a given program must be defined in exactly one module, from which it is exported. All the other modules then import that memory. Currently the way this works is the main module always defines and exports the memory and all other modules (i.e. all shared libraries import the memory). In this case libc.so should be importing its memory. |
do you mean b. is correct? well, i agree that the memory exported by the main module and the memory imported by libc.so are normally same. |
I suppose it could/should validate that there is exactly one export called A while back we tried to rename |
https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md was written before WASI had any concept of dynamic linking, so easy program is just one module. I will likely need to be updated if/when we want to support dynamic linking. |
even with dynamic-linking, the main module still should export |
At yes, that does look odd. In emscripten for some reason we defined the table on the JS side and import it, but your are correct, the main module should really be exporting it. |
I took another look at emscripten and even attempted to convert it to using main-module-exported memory: emscripten-core/emscripten#22332. However, don't think this can work today, at least as long as the main module is being built as In theory it could work if we pass The solution here I think is to avoid building the main module with PIC (emscripten-core/emscripten#12682).. since then the linker knowns exactly how big to make the initial table and memory. |
I do think we could remove the restriction in https://github.com/llvm/llvm-project/blob/04e7eaf91f3e9b6830feb2e08bb5b0ddb14c3174/lld/wasm/Driver.cpp#L632 but that still leaves the problem of what value to use for |
i'm not familiar enough with emscripten to grasp the diff quickly. what's wrong with making it both imported and exported? (as we did for wasi-threads) |
isn't it more consistent to make shared libraries export the imported memory as well? |
Nothing stops you from doing this but it seems redundant. As the embedder, if I am providing the memory and table as imports on the wasm file, why would I then want them to be re-expoted? I also have them, right? Its just add unnecessary exports. At least for emscripten, I can't see a reason to both import and export. |
It seems like a reasonable solution here would be to say "A module must either import or export something called For PIE/dynamic linking its up the embedder to create the memory before loading the module, and to set |
"avoid being different from statically linked modules" is a good enough reason, IMO. |
eg. otherwise |
I'm not sure I agree. Adding a little complexity to the host seem better than ask all modules to redundantly export something to the host (if nothing else this add some unnecessary size to every single module). |
This is my attempt to capture the discussion in WebAssembly#232
https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md says:
i guess it's the convention used by many of host functions, not only WASI.
however, wasi-libc's libc.so doesn't export "memory".
actually, wasm-ld rejects -shared -export-memory.
https://github.com/llvm/llvm-project/blob/06a808c4f4014edfeb2517bddd0bcb63eb4a260b/lld/wasm/Driver.cpp#L658
am i missing something?
a. wasm-ld should be fixed.
b. application-abi.md doesn't apply to a module which is a shared library.
the memory exported from the "main" module should always be used.
i feel this a bit strange because the module calling wasi (eg. libc.so) doesn't know about the "main" module.
The text was updated successfully, but these errors were encountered: