-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
FFI to C on MacOS causes segmentation fault (works on Ubuntu) #59202
Comments
This is almost certainly a problem with the library, and you happen to get lucky on Ubuntu. |
Minimising to something that is a small, self-contained reproducer would help a lot. |
@nagisa sounds good - let me work on that. @sfackler I don't have a tonne of experience with C libraries and ffi. I can say for certain that when I run the C function independently (gcc/cc compiled) on both Linux and Mac, and run the same function repeatedly, I cannot reproduce the error. What would you need from me in order to convince you that this is an FFI issue? (in addition to a smaller reproducible program). |
I'd want to see some specific evidence that the compiler did a specific thing wrong. |
That's fair. I'm not entirely sure how to go about that but will continue debugging and do my best to get you something credible and useful. |
you should try to use automatic tool like https://github.com/rust-lang/rust-bindgen instead of doing the binding yourself. Also, try to run your program with tools such as |
Will close this until I have more information. |
@sfackler i just hit this as well... you can check out a fork of a c library I am trying to build a wrapper for. and this error is strange, because i commented out all of my C calls that pass the CString as an arg, so i'm not even sending it anywhere, and can get it to segfault repeatedly.
a few things are interesting though, notice these two lines: If i comment out line 131, and only call the what makes this EVEN more strange, is if in that same function, i comment out 78 and 111, so that only 74/75 (CString) is live, no segfault. if i do the opposite, and comment out 74/75, but leave 78/111 live, no segfault. it is only when the two, seemingly unrelated calls are in the same function, that things go crazy. my environment: Apple LLVM version 10.0.1 (clang-1001.0.46.4) |
The following crate illustrates the issue I'm running into.
https://github.com/exsidius/rust_libpg_query
Running
cargo test
on Ubuntu causes no errors but on Mac will (inconsistently cause Seg. Faults).The errors codes are as follows -
error: process didn't exit successfully: `/Users/ExSidius/Dropbox/actual-code/rust_libpg_query/target/debug/deps/pg_query-ebb8d6e50e159947` (signal: 11, SIGSEGV: invalid memory reference)
Occasionally, I will also run into a Utf8Error (may or may not be part of the same bug) -
I believe I'm using CStrings appropriately (and the fact that it works on one operating system and not another seems suspicious.
Meta
Ubuntu -
macOS -
Let me know if there's anything I can do to help debug.
The text was updated successfully, but these errors were encountered: