Stream: general

Topic: ✔ Table Func index do not match the one from exports


view this post on Zulip Wilson Wang (Jan 15 2023 at 04:53):

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?

view this post on Zulip bjorn3 (Jan 15 2023 at 10:07):

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().

view this post on Zulip Wilson Wang (Jan 15 2023 at 18:26):

bjorn3 said:

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().

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

view this post on Zulip Wilson Wang (Jan 15 2023 at 19:17):

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.

view this post on Zulip Wilson Wang (Jan 15 2023 at 19:32):

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?

view this post on Zulip bjorn3 (Jan 15 2023 at 21:06):

Not clue how to get the function name.

view this post on Zulip Wilson Wang (Jan 15 2023 at 21:41):

thanks for the info anyway. I'll see if others can provider some clue.

view this post on Zulip Alex Crichton (Jan 17 2023 at 02:01):

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.

view this post on Zulip Wilson Wang (Jan 17 2023 at 03:31):

Alex Crichton said:

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.

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?

view this post on Zulip Alex Crichton (Jan 17 2023 at 03:33):

There is no way to do that right now, but we could provide apis to access the debug info or name section perhaps

view this post on Zulip Wilson Wang (Jan 17 2023 at 03:35):

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.

view this post on Zulip Notification Bot (Jan 17 2023 at 03:36):

Wilson Wang has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC