Open RechieKho opened 1 year ago
Nice progress!
It's tricky to go dig into user projects so reproducers that don't require doing that will always be useful in getting assistance. It also helps to isolate issues in the IREE codebase from issues in user codebases. There are definitely bugs in IREE but it's harder for us to evaluate in-situ :)
In this case I suspect your issue is in your code: you are not (AFAICT) retaining your file data - line 45 of iree_module.cpp is getting the data from somewhere, passing in a reference to it to iree_vm_bytecode_module_create, but not retaining it and setting up the release (instead of iree_allocator_null) such that whatever decides to unload the file can do it whenever it wants. You're probably dropping the data (indirectly or directly) before the unload(), which still needs that data, hence the explosion when trying to access it.
Sorry, forgot to put my response from the discord thread: What is keeping your bytecode_data alive? That looks like a temporary and it needs to be kept valid for the life of the module. The use after free is happening on context destroy when it tries to find the module's destructor export -- which requires access to the bytecode which was only on the stack at load time.
We don't make a copy of the bytecode. It can be actually large and (for production uses is often backed by an mmap) so the caller must arrange to keep it live.
https://discord.com/channels/689900678990135345/1097386769143562284/1097541566194798733
I wonder if we could name the parameter to hint this better? caller_owned_archive_contents
? Signals that it is special without studying the docs.
What happened?
Hi. I am currently writing an GDExtension to embed iree runtime into Godot game engine. Here is the project source code. On this f36fc7e, I found out that whenever I frequently reload / unload bytecode (aka. release
iree_vm_module_t
andiree_vm_context_t
), the program crashes. I also create an issue on that repo as well.As @stellaraccident (a very cool person!) suggest me to use asan, I manage to finally get some cool debug information.
Here is the asan output:
Steps to reproduce your issue
What component(s) does this issue relate to?
Runtime
Version information
For the iree-dist tools: candidate-20230415.490 For the runtime: It is a custom fork to fix cmake linker error.
Additional context
No response