-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[BUG] - crash on c++ exception when importing 2 pybind submodules built from different MSVC versions #2898
Comments
Maybe this is related: #1562 ? |
Anything new regarding it? I currently solve it by adding -DPYBIND11_COMPILER_TYPE="<unique_abi_string>" to every module I add. |
Also got hit by this bug. The involved pybind11 modules were TensorRT, which NVidia built with MSVC 2017, and other modules built via GitHub Actions, currently on MSVC 2022. All modules end up accessing the same global state with This is really bad, and should be fixed ASAP or we'll keep running into ABI mismatch induced memory corruptions and crashes for the foreseeable future. Is there a good reason why pybind11 is doing state sharing by default? I could imagine someone designing a multi-module-project with some common types, but state sharing might as well be an opt-in-feature for this specific case, not a default that is prone to all sorts of ABI pitfalls. What about @Nir-Az's request of adding |
This is a very hard bug IMO. |
That would be great. I'm guessing this is a really messy problem to get right. It needs understanding MSVC ABI compatibilities. Another problem is that it is very difficult to test. Do you know if MSVC has something similar to |
It's been 2.5 years since my comment :) |
To the best of my incomplete understanding (please correct me if I'm wrong):
The current implementation is unlikely to get changed unless someone brave wants to throw themselves into that most likely thankless battle, that will most likely drag out for years until everybody is either happy or adapted themselves enough. |
When talking about ABI compatibility at the DLL-boundary, not really. C++ binary compatibility between Visual Studio versions mentions that it is possible to mix outputs from different compilers at pre-linker-stage, but strict version matching down to the minor number is required at the post-linker-stage. So But also, even with a matching toolchain the C++ ABI may break for other reasons as well, e.g. compiler flags. So when mixing build products from multiple, unknown sources, the only real solution AFAIK is to not use C++ across ABI boundaries at all (which Msft also states in Portability at ABI boundaries). That being said, empirically, people compiling against pre-built DLLs often seem to get away with matching just the MSVC-year (first three
They do have a concept of ABI versions, namely C-ABI & CPython version & architecture, which is luckily a solved problem in PyPI & CPython nowadays. What we as module authors are doing behind the CPython-interface is of no concern to PyPI & CPython. PyPI can't help us with issues stemming from private implementation details like C++-ABI, Rust-ABI, CUDA version, device-driver-ABIs, etc. PyPI is not a C++ package manager like Conan or Vcpkg. And even those will often do full library rebuilds rather than using pre-built binaries for slight changes in toolchain or flags.
Well, we know that 100% of use cases have been knowingly exposed to memory corruption and crashes. So yes, not having done that by default clearly would have been the better option.
Sure, I guess we understand that what's done is done and that |
Thanks a lot Peter for the very careful explanation! Eye opening for me (I'm not very familiar with the MSVC specifics): I thought we're only a little bit our of the safe zone, but now I'm thinking we're out by a lot. I'm actually surprised now that there weren't more complains.
Agreed! That sounds like a good change to include in pybind11 v2.12. |
@pwuertz Looking at this again, I realize I didn't say directly: Could you please send a PR? (I believe realistically that's the only way something will change here: someone with a vested interest & relevant expertise taking action.) |
Thanks a lot! Just to point out, the internals key is also shown in the pybind11 pytest output, e.g. (from a #4779 GHA log):
|
…ith _MSC_VER (pybind#2898) (pybind#4779)" This reverts commit 76b8858.
Issue description
Update: After diving deep in the pybind11 comments inside the code (Thanks God for it!) I am rephrasing the issue.
It looks like different MSVC versions that build modules with pybind11 interfere with each other (due to use of common resources between python modules).
The PYBIND11_INTERNALS_ID string is not constructed from a _MSC_VER and when I miss match modules build with MSVC 14.0
and MSVC >= 14.2 the ID is the same and I get a crash
Here is the crash stack
The "registered_exception_translators" list is not empty, but once you try to access the translator you get access violation.
I saw the "PYBIND11_COMPILER_TYPE" definition can be override,
I guess what I see here is that mismatch between MSVC versions also cause problems and perhaps should be considered as a different ABI.
Question:
What are the benefits of using the same "Internals" between modules? is it memory consumption?
It seems like if I force override the ABI version it works (add_definitions(-DPYBIND11_COMPILER_TYPE="_testing")
This is my workaround for now, I can suggest a PR that integrate MSC version as part of the ABI_ID..
Thanks
Thanks
Nir
The text was updated successfully, but these errors were encountered: