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

How to determine module name? #261

Closed
posutsai opened this issue Aug 8, 2019 · 4 comments
Closed

How to determine module name? #261

posutsai opened this issue Aug 8, 2019 · 4 comments

Comments

@posutsai
Copy link

posutsai commented Aug 8, 2019

I try to use preload option to load a function out of the main module and it keeps showing this error message.

error while processing main module my_main_module.wasm: Instantiation error: Link error:env/foo: no provided import function

How to know runtime the exported wasm file's module name?

@posutsai
Copy link
Author

posutsai commented Aug 8, 2019

Looks like wasmtime doesn't distinguish each module as different names. In handle_module function it passes None to instantiate_module no matter what the preloaded file name is. I think it would be better if wasmtime could name each module to satisfy this kind of need.
Anyway, my target function seems to be linkable through symbol after I manually name my preloaded function. However, I wonder does wasmtime support decode an exported function? It keeps throwing out an error message.

!!! no export named __wasi_memory, or the export isn't a mem: None

@sunfishcode
Copy link
Member

There are some open design questions concerning the naming of modules, such as this.

The "!!! no export named __wasi_memory, or the export isn't a mem: None" error message is admittedly confusing. It would say "memory" instead of "__wasi_memory". I've now opened #264 to fix that. That said, what this error message means is that if you're using WASI, you're currently required to have a memory export named "memory", because many WASI functions expect to be able to access it. That's independent of any other exports you have.

@posutsai
Copy link
Author

posutsai commented Aug 9, 2019

I have read the discussion in the proposal. Looks like this feature haven't been standardized yet. Is there anything that still calls for participation? It would be wonderful if I can contribute even a little thing.

I would like to know if you have any helpful suggestion to help me find out any alternative way to achieve my goal. Here's what I plan to do.

Briefly, I want to implement a tool to do the interposition-like job on Linux dynamic linking for either debugging or profiling. Let's say I have a foo function in foo.wasm and it is called in the main function. I want to replace the callee of call instruction with other function and direct the runtime to execute the code defined in other modules.

In my opinion, the only left option is to do it in the linking stage. Using -c flag, compiler describes how linker interprets the separate object files in customized "linking" section. My tool should parse those object files and modify the "linking" section and pass compiled substituted other object file to the wasm-ld together. In this way, if I do it correctly, wasm-ld would output only one wasm file and behave what I want it to do in the runtime.

@alexcrichton
Copy link
Member

I believe the concerns here should be addressed by the wasmtime API crate at this time in terms of being able to preprocess imports, and if there's still an issue regarding WASI mind opening a new issue?

grishasobol pushed a commit to grishasobol/wasmtime that referenced this issue Nov 29, 2021
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

No branches or pull requests

3 participants