-
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
Fix MSVC MT/MD incompatibility in PYBIND11_BUILD_ABI #4953
Changes from 18 commits
607812a
71b0e9e
d1695f1
4c6c344
543b08f
e7a559d
12a6478
10dd08a
72b6d2a
9ce2def
1d2f952
0131c55
c3415a9
a5b5c3b
a3944f3
b9b54a7
713b427
79a3770
ef6c3f0
fa75ca0
823a77b
4819606
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -310,15 +310,25 @@ struct type_info { | |
# endif | ||
#endif | ||
|
||
/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility. | ||
/// On MSVC, changes in _MSC_VER may indicate ABI incompatibility (#2898). | ||
#ifndef PYBIND11_BUILD_ABI | ||
# if defined(__GXX_ABI_VERSION) | ||
# if defined(__GXX_ABI_VERSION) // Linux/OSX. | ||
# define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION) | ||
# elif defined(_MSC_VER) | ||
# define PYBIND11_BUILD_ABI "_mscver" PYBIND11_TOSTRING(_MSC_VER) | ||
# elif defined(_MSC_VER) // See PR #4953. | ||
# if defined(_MT) && defined(_DLL) // Corresponding to CL command line options /MD or /MDd. | ||
# if (_MSC_VER) / 100 == 19 | ||
# define PYBIND11_BUILD_ABI "_md_mscver19" | ||
# else | ||
# error "Unknown major version for MSC_VER: PLEASE REVISE THIS CODE." | ||
# endif | ||
# elif defined(_MT) // Corresponding to CL command line options /MT or /MTd. | ||
# define PYBIND11_BUILD_ABI "_mt_mscver" PYBIND11_TOSTRING(_MSC_VER) | ||
# else | ||
# error "Unknown combination of MSVC preprocessor macros: PLEASE REVISE THIS CODE." | ||
rwgk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# endif | ||
# elif defined(__NVCOMPILER) // NVHPC (PGI-based). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For nvhpc you would check |
||
# define PYBIND11_BUILD_ABI "" // TODO: What should be here, to prevent UB? | ||
# else | ||
# define PYBIND11_BUILD_ABI "" | ||
# error "Unknown platform or compiler: PLEASE REVISE THIS CODE." | ||
# endif | ||
#endif | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this PR is for msvc but this isn't the correct way to check for linux.
Background:
This macro value is the same across all version of clang ( always 1002 ) but changes anytime the gcc internal compiler ABI changes, which generally has no impact. You can find more details on the gcc abi changes here: https://gcc.gnu.org/onlinedocs/gcc/C_002b_002b-Dialect-Options.html
Generally you can safely pass types across anything
1002
or newer as long as the_GLIBCXX_USE_CXX11_ABI
( https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html ) is the same.So if you build two libraries with differing values of
_GLIBCXX_USE_CXX11_ABI
they can't have the same abi:But that isn't captured in your ABI checks at all and is significantly more important compared to
__GXX_ABI_VERSION