-
Notifications
You must be signed in to change notification settings - Fork 2
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
Why "C" calling convention? #5
Comments
Just fyi, it appears rust checks for duplicate symbols on its side, but not from the C side, not that this matters much. |
I worked around these |
I see maybe! There are functions here that pass and return secret data by value, so the calling convention used must avoid placing them on the stack, as data on the stack cannot reliably be erased. Are these |
Two reasons: Rust/LLVM play it really fast and loose with the ABI. If they can avoid passing args they will (hard coded branches). If they can inline args (hard coded branches) they will. Also the LLVM will happily create multiple versions of the same functions for different call sites, and different ABI's it uses in multiple places. Effectively. If you write normal code on top of the library you can accidentally opt-in an LLVM pass that may destroy some of the package's guarantees. So I'm attempting to opt-out of that behavior. When I was reading the dis-assembly the C ABI helped me know which args were being introduced where. I think long term the only way to fully avoid it is to compile the crate and re-expose it via the FFI. Which may avoid 99% of the issues as then that crate can be compiled at a lower optimization levels avoiding the need to write ASM for all the functions. |
I donno if I completely understand, as I have not looked much at compiler output myself. I suppose however the C ABI dictates that We should be careful about my changes on lines 255 and 360 in https://github.com/valarauca/consistenttime/pull/6/files I made those changes to increase test coverage, but they make your C ABI |
What does making all the functions
extern "C"
achieve? I suspect the code would be slightly simpler if one could usetrait
s everywhere, but presumably you avoided doing that for good reason?The text was updated successfully, but these errors were encountered: