My goal is, in wasm, sending a function as a ref and call it from the host. I use --export-all to export it as a funcref in __indirect_function_table. However, later when I get it from the table, I found that its index does not match the one I get through instance.get(). I assume the store_id and index of the function that I found in __indirect_function_table and instance.get() would be the same. Am I using wasmtime correctly?
You have to directly get the function from the __indirect_function_table table if you got a function pointer on the wasm side you passed to the host. The function pointer is an index into __indirect_function_table. This is almost always different from the export index you pass to instance.get().
bjorn3 said:
You have to directly get the function from the
__indirect_function_tabletable if you got a function pointer on the wasm side you passed to the host. The function pointer is an index into__indirect_function_table. This is almost always different from the export index you pass toinstance.get().
Thanks for the answer. I am using wasmtime-cpp. I am actually getting the Func class from the __indirect_function_table and use its store_id & index to compare with another Func that I get by look it up in the instance.export(). Although through Func.call I can invoke the same function. But these two Func classes have different index field. I am not very clear what is the best way if I want to compare two Func classes and check if they are the same class in wasmtime-cpp. I will also at Alex since he is working on wasmtime-cpp. cc: @Alex Crichton
The interesting thing is that, if i use wasmtime_func_to_raw() and print the raw values of these Func classes. The values are different even if they are running the same function.
So here my observation is: if a wasm function is both exported and in the __indirect_function_table, the underlying anyfunc are different even though they are the same actual wasm function. Am I correct? If this is true, how do I get the exported name of a wasm function that I found inside __indirect_function_table?
Not clue how to get the function name.
thanks for the info anyway. I'll see if others can provider some clue.
Note that store_id and index are meant to be internal and are not suitable for function equality. There's no way in Wasmtime to equate two functions together at this time.
Alex Crichton said:
Note that
store_idandindexare meant to be internal and are not suitable for function equality. There's no way in Wasmtime to equate two functions together at this time.
thanks for the answer, @Alex Crichton . Btw, if I got a funcref in __indirect_function_table, how do i find the function name if it is also exported?
There is no way to do that right now, but we could provide apis to access the debug info or name section perhaps
Alex Crichton said:
There is no way to do that right now, but we could provide apis to access the debug info or name section perhaps
thanks, got that. maybe later i will fill a bug and try to work on this. So far it is not a blocker issue for me.
Wilson Wang has marked this topic as resolved.
Last updated: Dec 06 2025 at 05:03 UTC