-
Notifications
You must be signed in to change notification settings - Fork 259
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
Adds _initiialize for c-shared wasm with go #2305
Conversation
Signed-off-by: Julien Salleyron <[email protected]>
@@ -689,7 +689,7 @@ type moduleConfig struct { | |||
// NewModuleConfig returns a ModuleConfig that can be used for configuring module instantiation. | |||
func NewModuleConfig() ModuleConfig { | |||
return &moduleConfig{ | |||
startFunctions: []string{"_start"}, | |||
startFunctions: []string{"_start", "_initialize"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If both are present, would it be more correct to run _initialize first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say so, yes. Or make it an error, but that's probably harder (and harder to explain).
Go implementing this is interesting, but this has been possible with (e.g.) I support adding |
will this be a part of Go spec? |
AFAIK I'm not sure what follows after wasip1. Like, should our wasip1 package handle this, rather than by default? If so, |
Just for some context, Node has two entry points corresponding to each of them. I found it to be sort of tedious But one reason for it was that initialize functions can't return an error code. It seems simplest for users still to just handle either transparently. |
OTOH supporting one and not the other seems weird. OTOH maybe even including |
yep that's exactly my thinking - I would rather remove _start in the first place |
Yeah, that's a breaking change though. |
a breaking change not in API, so I don't think that's something we promise to keep, and i think that's much clearer! |
I get the point, but that'd be still a change in behavior, though |
I would prefer we don't introduce breaking changes in the behavior. A lot of users have indirect dependencies on wazero that they might not even know about. If they happen to upgrade wazero somewhat unintentionally and suddenly their software doesn't work anymore because _start isn't called automatically, they're in for going down a rabbit whole of understanding the root cause. I want to care for my fellow developers out there who are already dealing with tons of crap day to day, let us be on the side of making their lives easier. That being said, since we already support automatically calling _start and I don't think we should drop it, I would still be in favor of automatically calling _initialize because otherwise we introduce an inconsistent experience where some modules will load "out of the box" with default configuration, and some others won't (c-shared & reactor). The cost is really low on Wazero here, if we can avoid answering GitHub issues and having to produce extra documentation to explain subtle implementation differences, it feels like we're doing the right thing? I hope these perspectives are useful ✌️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to fix the doc accordingly?
// WithStartFunctions configures the functions to call after the module is
// instantiated. Defaults to "_start".// Instantiate instantiates a module from the WebAssembly binary (%.wasm)
// with default configuration, which notably calls the "_start" function,
// if it exists.
on second though, this also means a breaking change right? before people manually call .ExportFunction("_initialize"), and this results in calling it twice |
i am inclined to avoid adding anything like _initialize at all |
You're right that it could result in _initialize being called twice, which might result in similar kinds of terrible bugs. Considering what we discussed, I would agree that the best option at this time is probably to hold on making any changes and learn more about what problems users will face once they start using c-shared modules more. |
yep, agreed! |
I would've thought before people would've called Almost every change is a potential breaking change. Dropping I'd definitely vote for adding |
@ncruces my intuition is also that adding _initialize would be the right trade off, but taking our time to build confidence doesn't hurt here. c-shared for WASM will be in Go 1.24 which is set to release on February next year, so let's use that time to reflect on it and gather more evidence? |
https://github.com/search?q=ExportedFunction%28%22_initialize%22%29+language%3AGo+&type=code people actually are doing ExportedFunction("_initialize") |
so my take here is having _start in the wazero core was totally mistake and garbage in my opinion, and people are relying on it is unfortunate (sysfs etc is also mistake to be honest). I agree that only having _start is inconsistent and desire to add _initialize to the list for consistency but that feels like adding additional garbage, so I would pretty much rather removing _start in the first place because this in anyway breaks somebody. So i am closing, and i really wish we hadn't added _start in the first place. Just forcing user to add one single line of WithStartFunction("_initialize") doesn't hurt at all in my opinion. |
@achille-roussel Is it possible for the go compiler to register IIRC wasi-sdk does that for start but not reactor programs, but that's because no one actually cares about reactor mode (c-shared) since no money in it. |
It's an interesting idea, probably worth bringing up to Go in the form of either a discussion on #webassmebly in Slack, or a Github issue. For full context, this was the original proposal golang/go#65199 |
In the recently merged proposal for wasm export with the go compiler golang/go#65199, when you compile with wasm export and the build mode to
c-shared
there is no_start
function exported but a_initialize
function.As the startFunctions is verified before being called, it should not impact any body if the _initialize is not defined.