RemoveUnusedModuleElements: add option to remove nop exported functions#8532
RemoveUnusedModuleElements: add option to remove nop exported functions#8532BilelGho wants to merge 1 commit intoWebAssembly:mainfrom
Conversation
Add pass argument `remove-unused-module-elements-ignore-nop-exports` that strips exports (and their functions, if otherwise unreferenced) whose body is a single `nop`. Some runtimes check for export existence to decide behavior, so a nop export misleads them into thinking a lifecycle hook is implemented. Fixes WebAssembly#6506.
What is the exact behavior that is a problem in those runtimes? (I'm not necessarily opposed to this functionality, but I'd like to understand the actual problem) |
This is actually a bit of a misquote to this comment in this old issue by @orsinium I haven't checked myself tbh. Could be a good idea to check whether this is helpful first. I just found it as an open issue for new contributors. I wouldn't know if such runtimes wrote their workarounds or could still benefit of such option. Feel free to dismiss if it looks unnecessary. |
|
Thanks for the info, I'd forgotten that old discussion. I'd like to hear more from the runtimes that would benefit, if this is still important for them, before moving forward with a change. |
|
Thank you! I also forgot about the discussion, it's nice to see things moving forward :) I can't speak much for other runtimes beyond my old comment but for my runtime (Firefly Zero) that would be surely beneficial. For example, here if the |
Fixes #6506.
Summary
remove-unused-module-elements-ignore-nop-exportsto theRemoveUnusedModuleElementspass.nophave their export entries removed before the normal DCE graph walk. If nothing else references the function, the function itself is also removed by the existing DCE logic.Usage
Motivation
Some runtimes (e.g. wasm-4, custom Rust runtimes) check whether a named export exists to decide behavior. A nop export misleads them into thinking a lifecycle hook is implemented, causing unexpected behavior. This option lets toolchains strip such stub exports produced by compilers that always emit lifecycle functions even when the user provides no implementation.
Test plan
test/lit/passes/remove-unused-module-elements-ignore-nop-exports.wast