-
Notifications
You must be signed in to change notification settings - Fork 106
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
Broken optimised wasmd build #536
Comments
Related: babylonchain/babylon#642. |
Thank you for digging into this!
|
Very strange indeed. Smells like a bug in the linker or something like that as the Go compiler alone cannot know if
I think there are two ways out here
|
Thanks for the prompt response! Yes, I think checking an unused parameter doesn't make much sense. And, let's hope that's the only source of these errors. In any case, making that change looks like a safe bet. |
I have created a PR removing the
|
Agreed, this looks like a bug at another level (linker, optimiser, library code). Let's keep an eye on it; perhaps this will appear in a different form. We can re-enable optimisations on our side, to try and see if this triggers with the new version by the way. |
When compiling
wasmd
with optimisation (viaCGO_CFLAGS="-O" go build
) the resulting binary crashes with a panic when iterating over a range of map entries from a smart contract.This is part of the stack trace:
A SEGV when iterating over and calling the "next" method. Only happens on Linux machines AFAIK.
The offending line turns out to be https://github.com/CosmWasm/wasmvm/blob/v1.5.2/internal/api/callbacks.go#L291
where accessing a uninitialised / invalid
errOut
vector causes the crash.Funnily, removing the check over
errOut
fixes / prevents the bug from triggering, as this is the only instance the variable is being used in that code path.This seems to be caused by optimisations removing some initialisation. Perhaps because the variable is not really being used, except for the check. Perhaps because of an optimiser bug under Linux.
Needless to say, there may be other places this issue may be present as well.
Oddly, compiling
wasmd
with optimisation level 2 (CGO_CFLAGS="-O2"
) doesn't trigger the bug; which may point to an optimiser bug or similar.Reporting this so that it is known, and can perhaps be fixed.
For reproducing, it's enough to build
wasmd
withCGO_CFLAGS="-O"
, deploy a smart contract that iterates over a range, and call that code, either through a query or execute call.In https://github.com/maurolacy/iterator-contract there's A PoC contract to help with reproducing / triggering this under Linux.
Tested with wasmd v0.50.0 and wasmvm v1.5.2.
The text was updated successfully, but these errors were encountered: