Giter Club home page Giter Club logo

Comments (9)

CryZe avatar CryZe commented on May 16, 2024

It seems like the problem there is that ctx is actually passed after the f64 or something. f64 is in the XMM0 register even though the ABI requires it to be in the XMM1 register if it's the second argument, which is also not the case for Linux, so this would explain this being a Windows only problem again. I think I saw the ctx argument being moved to the first parameter in some PR. Maybe it didn't do that all the way?

Here you can see XMM1 being used:
https://rust.godbolt.org/z/v4BTVw

Here's the jitted code filling the value into XMM0:

https://i.imgur.com/y3zHMDn.png

Alternatively, cranelift may not know about the Windows calling convention and thus just fill the value into XMM0 like it would on Linux (either it isn't being told about it, or it doesn't support it yet).

from wasmer.

CryZe avatar CryZe commented on May 16, 2024

https://i.imgur.com/8Jgwgh9.png

Defining the wrap function to always be of "sysv64" calling convention fixes the bug, but that seems more like a workaround rather than a proper fix, as cranelift should probably just emit the correct calling convention in the first place. I don't know where this is done though. (Update: This fixes some things but breaks others, I'm thinking cranelift actually is going for the windows calling convention but the ctx parameter isn't implemented correctly)

I'd encourage some maintainer to verify if all the calling conventions between the jit'ed code and rust are actually correct (all the trampolines, libcalls, ...).

from wasmer.

lachlansneff avatar lachlansneff commented on May 16, 2024

@CryZe Thanks for the deep dive! I "own" most of the runtime code, so I'll take a look at this on Monday. It's probably the calling convention getting set up wrong somewhere.

from wasmer.

lachlansneff avatar lachlansneff commented on May 16, 2024

@CryZe Sorry this took so long, but I've just had time to investigate and indeed yes, cranelift implements the x64 calling convention incorrectly. I honestly don't blame them, it seems to waste registers.

Here's the spec: https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2017#example-of-argument-passing-3---mixed-ints-and-floats

from wasmer.

syrusakbary avatar syrusakbary commented on May 16, 2024

We created an issue in Cranelift: bytecodealliance/cranelift#691

from wasmer.

syrusakbary avatar syrusakbary commented on May 16, 2024

This issue was fixed in: bytecodealliance/cranelift#701 (related issue in cranelift: bytecodealliance/cranelift#691)

Once we update the Cranelift version the issue should be fixed in our runtime.

Keeping the issue open until then!

from wasmer.

CryZe avatar CryZe commented on May 16, 2024

The implementation was unfortunately incorrect. So they still need to fix that. (Oh wait, they fixed that too).

from wasmer.

hrydgard avatar hrydgard commented on May 16, 2024

I had similar problems with floating point arguments on Windows, but indeed appears to work correctly on master with the the updated cranelift.

Are you guys planning to tag a new release in the near future? Would be convenient :)

from wasmer.

CryZe avatar CryZe commented on May 16, 2024

This seems to be resolved :)

from wasmer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.