-
Notifications
You must be signed in to change notification settings - Fork 727
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
Possibly unsupported static constructor (C++) #1509
Comments
Hmm, this is probably an ABI mismatch somewhere. If you could create a reduced test-case I'd be happy to take a look. |
Oh, actually, that's a bit more surprising, it's crashing on the C++ side... Do layout tests pass for EncryptionParameters? |
All layout tests are passing. What would a satisfactory reduced test case look like? I just want to make sure that whatever I provide will actually help you (or anyone else) approach the issue. |
A standalone repo / gist that reproduces the issue with as little C++ / Rust code as possible would be great. |
Or maybe even a patch to this repo's bindgen-integration tests, which already have all the build setup. |
It's not minimal yet (I think) but I trimmed a lot of fat. See: https://github.com/Belval/seal-bindgen-test-case You can get the error simply by running |
Ah, I can repro that, thanks! So the issue is an ABI issue, and it's a bit self-inflicted unfortunately :(. So the function prototype bindgen generates returns |
Ok, so I took a look at it, I got the STL to not complain (#1513), and then used the diff --git a/Cargo.toml b/Cargo.toml
index b766ef1..bd60449 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,7 @@ build = "build.rs"
[build-dependencies]
git2 = "0.8"
-bindgen = "0.42.2"
+bindgen = { path = "/home/emilio/src/moz/rust-bindgen" }
cc = "1.0"
[dependencies]
diff --git a/build.rs b/build.rs
index 7606151..8f23d2b 100644
--- a/build.rs
+++ b/build.rs
@@ -32,12 +32,11 @@ fn main() {
let bindings = bindgen::Builder::default()
.generate_inline_functions(true)
.derive_default(true)
- .header("./seal/src/seal/seal.h")
+ .header("src/bindings.h")
.clang_arg("-I./seal/src/")
.clang_arg("-std=c++17")
.clang_arg("-x")
.clang_arg("c++")
- .opaque_type("std::.*")
.whitelist_type("seal::.*")
.whitelist_function("seal::.*")
.generate()
diff --git a/src/bindings.h b/src/bindings.h
new file mode 100644
index 0000000..1ce8790
--- /dev/null
+++ b/src/bindings.h
@@ -0,0 +1,12 @@
+#include <seal/seal.h>
+
+/// <div rustbindgen replaces="std::shared_ptr"></div>
+template<typename T>
+class simple_shared_ptr {
+ public:
+ T* ptr;
+ void* count;
+};
+
+static_assert(sizeof(simple_shared_ptr<int>) == sizeof(std::shared_ptr<int>), "");
+static_assert(alignof(simple_shared_ptr<int>) == alignof(std::shared_ptr<int>), ""); (You could use the same for the Anyhow, with that the issue persists. I could confirm there's an ABI issue. From Rust:
So I think this is basically a dupe of #778 / rust-lang/rust#38258, and the workaround is creating an |
Apologies if I misunderstand, but there is already an
but it doesn't work either because of the I guess my question is, what do you mean by creating an Thank you for taking the time to investigate the issue. |
The issue is that, when returning the shared ptr, the itanium C++ ABI says that it is non-trivial for the purpose of calls (since it has a destructor). Then, returning a https://itanium-cxx-abi.github.io/cxx-abi/abi.html#value-parameter Point 1, that is:
Regardless of whether it's a struct or a class, rust won't let us do that, and will always use registers for small structs. What I mean is that you can write a C function that doesn't return the complex type, for example:
And you could call that function, and it'll work. Another alternative would be something like:
|
Oh ok it is clearer now. Thank you! |
I did what I thought was you described here but it does not seem to work. I create a
Then I edited my
Setting my header file as "bindings.h" with it having an include for "seal.h". The generated bindings seems to be right and include Yet when I run it I get this error message:
Which is unclear to me because it seems to imply that |
I'm unsure you can define an inline extern "C" function, you probably need a new cpp file or something. Also, you're returning a freed pointer, that's no good. |
Possibly problematic C++ code
Bindgen Invocation
then
I tried all combinations that i could find in the bindings, there doesn't seem to be a right way to do it.
Actual Results
I used
rust-gdb
to see what was causing it, and it seems to be during the assignation? of the MemoryPool from the EncryptionParameters.Expected Results
I expect it to run without segmentation fault. If static constructor are supported.
The text was updated successfully, but these errors were encountered: