Skip to content
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

Using CXX in multiple DLLs always results in undefined behavior? #1363

Open
camio opened this issue Jul 18, 2024 · 0 comments
Open

Using CXX in multiple DLLs always results in undefined behavior? #1363

camio opened this issue Jul 18, 2024 · 0 comments

Comments

@camio
Copy link

camio commented Jul 18, 2024

We're investigating using CXX to create multiple DLLs for incorporation into a large C++ project.

Non-inline functions with multiple definitions living in separate DLLs are okay when they aren't exposed directly or indirectly (e.g. via. exceptions) over the DLLs' public interfaces. Consequently, cbindgen, in exposing only functions particular to the crate, effectively insulates Rust runtimes within the DLLs.

CXX when used in multiple DLLs, on the other hand, will expose non-inline functions with multiple definitions, such as rust::String's destructor. This is fine as long as these functions's implementations do not access an object with multiple definitions (namely, global state in the DLL's data section). The implementation of rust::String::~String calls ManuallyDrop::drop which then calls drop_in_place. Do we have any guarantees that drop_in_place will not access global state?

If the answer is "no" it seems like linking a single executable to multiple DLLs that use CXX results in undefined behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant