-
Notifications
You must be signed in to change notification settings - Fork 13k
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
tuple structs cause FFI segfaults on 32-bit Linux #39394
Comments
Bluss has kindly pointed out rust-lang/rfcs#1758 . |
Your code is wrong.
is not the same as
ABI wise. One is a structure and the other is a scalar. They may be handled differently if ABI specifies so. In this case 32-bit SysV ABI specifies that
is actually
under the covers, whereas
is
Now its easy to see that |
The I think this behaviour should be documented in the nomicon. |
Yeah, bindgen's issue is not caused by bindgen per se, but by clang-sys. In any case, as I commented in the rust-bindgen issue linked above, I've found this several times in different FFI-related libraries. I believe this kind of usage is going to be hard to exterminate from the ecosystem, and if specializing newtypes in the compiler so they interact with the ABI in the same way as its underlying type is not possible, this is going to require a fair amount of docs. |
Oh, or repr(transparent), of course. |
So the correct way to call would be:
(this works fine for me locally using i686-unknown-linux-gnu & |
I don't want to leave an issue that doesn't have a clear next step. Should I close this in favour of the RFC? Is this a docs issue that I should leave open? |
I’m not sure there’s anything to be documented here. The ABI between caller and callee was violated and that’s it. I’m not sure what the expectations in this case were, but the assumptions which caused this bug seem trivially wrong to me. Tuple structs are also documented in the reference. |
Given the following Rust code, compiled as a staticlib:
And the following C program to call it:
Running the compiled program on 32-bit linux isn't passing the int correctly:
64-bit linux works fine.
I have a full example repo here: https://github.com/Wilfred/rust_struct_test
I'm not sure if this is a bug with Rust itself, or in my code.
The text was updated successfully, but these errors were encountered: